@@ -544,3 +544,44 @@ do_execsql_test json_from_json_object {
544
544
# do_execsql_test json_object_duplicated_keys {
545
545
# SELECT json_object('key', 'value', 'key', 'value2');
546
546
# } {{{"key":"value2"}}}
547
+
548
+ # The json_quote() function transforms an SQL value into a JSON value.
549
+ # String values are quoted and interior quotes are escaped. NULL values
550
+ # are rendered as the unquoted string "null".
551
+ #
552
+ do_execsql_test json_quote_string_literal {
553
+ SELECT json_quote('abc" xyz');
554
+ } {{" abc\" xyz" }}
555
+ do_execsql_test json_quote_float {
556
+ SELECT json_quote(3.14159);
557
+ } {3.14159}
558
+ do_execsql_test json_quote_integer {
559
+ SELECT json_quote(12345);
560
+ } {12345}
561
+ do_execsql_test json_quote_null {
562
+ SELECT json_quote(null);
563
+ } {" null" }
564
+ do_execsql_test json_quote_null_caps {
565
+ SELECT json_quote(NULL);
566
+ } null
567
+ do_execsql_test json_quote_json_value {
568
+ SELECT json_quote(json('{a:1, b: " test" }'));
569
+ } {{{" a" :1," b" :" test" }}}
570
+
571
+
572
+ # Escape character tests in sqlite source depend on json_valid
573
+ # See https://github.com/sqlite/sqlite/blob/255548562b125e6c148bb27d49aaa01b2fe61dba/test/json102.test#L690
574
+ # So for now not all control characters escaped are tested
575
+
576
+
577
+ # TODO No catchsql tests function to test these on
578
+ #do_catchsql_test json_quote_blob {
579
+ # SELECT json_quote(x'3031323334');
580
+ #} {1 {JSON cannot hold BLOB values}}
581
+ #do_catchsql_test json_quote_more_than_one_arg {
582
+ # SELECT json_quote(123,456)
583
+ #} {1 {json_quote function called with not exactly 1 arguments}}
584
+ #do_catchsql_test json_quote_no_args {
585
+ # SELECT json_quote()
586
+ #} {1 {json_quote function with no arguments}}
587
+
0 commit comments