3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements tests for JSON SQL functions extension to the
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
23 do_execsql_test json101-1.1.00 {
24 SELECT json_array(1,2.5,null,'hello');
25 } {[1,2.5,null,"hello"]}
26 do_execsql_test json101-1.1.01 {
27 SELECT json_array(1,'{"abc":2.5,"def":null,"ghi":hello}',99);
28 -- the second term goes in as a string:
29 } {[1,"{\\"abc\\":2.5,\\"def\\":null,\\"ghi\\":hello}",99]}
30 do_execsql_test json101-1.1.02 {
31 SELECT json_array(1,json('{"abc":2.5,"def":null,"ghi":"hello"}'),99);
32 -- the second term goes in as JSON
33 } {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]}
34 do_execsql_test json101-1.1.03 {
35 SELECT json_array(1,json_object('abc',2.5,'def',null,'ghi','hello'),99);
36 -- the second term goes in as JSON
37 } {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]}
38 do_execsql_test json101-1.2 {
39 SELECT hex(json_array('String "\ Test'));
40 } {5B22537472696E67205C225C5C2054657374225D}
41 do_catchsql_test json101-1.3 {
42 SELECT json_array(1,printf('%.1000c','x'),x'abcd',3);
43 } {1 {JSON cannot hold BLOB values}}
44 do_execsql_test json101-1.4 {
45 SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1,
46 0.0, 1.0, -1.0, -1e99, +2e100,
48 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
49 19, NULL, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
50 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
51 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
52 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
54 } {[-9223372036854775808,9223372036854775807,0,1,-1,0.0,1.0,-1.0,-1.0e+99,2.0e+100,"one","two","three",4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,null,21,22,23,24,25,26,27,28,29,30,31,"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ",99]}
56 do_execsql_test json101-2.1 {
57 SELECT json_object('a',1,'b',2.5,'c',null,'d','String Test');
58 } {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}}
59 do_catchsql_test json101-2.2 {
60 SELECT json_object('a',printf('%.1000c','x'),2,2.5);
61 } {1 {json_object() labels must be TEXT}}
62 do_catchsql_test json101-2.3 {
63 SELECT json_object('a',1,'b');
64 } {1 {json_object() requires an even number of arguments}}
65 do_catchsql_test json101-2.4 {
66 SELECT json_object('a',printf('%.1000c','x'),'b',x'abcd');
67 } {1 {JSON cannot hold BLOB values}}
69 do_execsql_test json101-3.1 {
70 SELECT json_replace('{"a":1,"b":2}','$.a','[3,4,5]');
71 } {{{"a":"[3,4,5]","b":2}}}
72 do_execsql_test json101-3.2 {
73 SELECT json_replace('{"a":1,"b":2}','$.a',json('[3,4,5]'));
74 } {{{"a":[3,4,5],"b":2}}}
75 do_execsql_test json101-3.3 {
76 SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
78 do_execsql_test json101-3.4 {
79 SELECT json_type(json_set('{"a":1,"b":2}','$.b',json('{"x":3,"y":4}')),'$.b');
82 do_execsql_test json101-3.5 {
83 SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456));
84 } {{$} {} | {$.x} 456 |}
87 # Per rfc7159, any JSON value is allowed at the top level, and whitespace
88 # is permitting before and/or after that value.
90 do_execsql_test json101-4.1 {
93 VALUES('true'),('false'),('null'),('123'),('-234'),('34.5e+6'),
94 ('""'),('"\""'),('"\\"'),('"abcdefghijlmnopqrstuvwxyz"'),
95 ('[]'),('{}'),('[true,false,null,123,-234,34.5e+6,{},[]]'),
96 ('{"a":true,"b":{"c":false}}');
97 SELECT * FROM j1 WHERE NOT json_valid(x);
99 do_execsql_test json101-4.2 {
100 SELECT * FROM j1 WHERE NOT json_valid(char(0x20,0x09,0x0a,0x0d)||x);
102 do_execsql_test json101-4.3 {
103 SELECT * FROM j1 WHERE NOT json_valid(x||char(0x20,0x09,0x0a,0x0d));
106 # But an empty string, or a string of pure whitespace is not valid JSON.
108 do_execsql_test json101-4.4 {
109 SELECT json_valid(''), json_valid(char(0x20,0x09,0x0a,0x0d));
112 # json_remove() and similar functions with no edit operations return their
115 do_execsql_test json101-4.5 {
116 SELECT x FROM j1 WHERE json_remove(x)<>x;
118 do_execsql_test json101-4.6 {
119 SELECT x FROM j1 WHERE json_replace(x)<>x;
121 do_execsql_test json101-4.7 {
122 SELECT x FROM j1 WHERE json_set(x)<>x;
124 do_execsql_test json101-4.8 {
125 SELECT x FROM j1 WHERE json_insert(x)<>x;
128 # json_extract(JSON,'$') will return objects and arrays without change.
130 do_execsql_test json-4.10 {
131 SELECT count(*) FROM j1 WHERE json_type(x) IN ('object','array');
133 WHERE json_extract(x,'$')<>x
134 AND json_type(x) IN ('object','array');
137 do_execsql_test json-5.1 {
138 CREATE TABLE j2(id INTEGER PRIMARY KEY, json, src);
139 INSERT INTO j2(id,json,src)
146 "streetAddress": "21 2nd Street",
149 "postalCode": "10021-3100"
154 "number": "212 555-1234"
158 "number": "646 555-4567"
163 }','https://en.wikipedia.org/wiki/JSON');
164 INSERT INTO j2(id,json,src)
174 { "id": "1001", "type": "Regular" },
175 { "id": "1002", "type": "Chocolate" },
176 { "id": "1003", "type": "Blueberry" },
177 { "id": "1004", "type": "Devil''s Food" }
182 { "id": "5001", "type": "None" },
183 { "id": "5002", "type": "Glazed" },
184 { "id": "5005", "type": "Sugar" },
185 { "id": "5007", "type": "Powdered Sugar" },
186 { "id": "5006", "type": "Chocolate with Sprinkles" },
187 { "id": "5003", "type": "Chocolate" },
188 { "id": "5004", "type": "Maple" }
190 }','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html');
191 INSERT INTO j2(id,json,src)
202 { "id": "1001", "type": "Regular" },
203 { "id": "1002", "type": "Chocolate" },
204 { "id": "1003", "type": "Blueberry" },
205 { "id": "1004", "type": "Devil''s Food" }
210 { "id": "5001", "type": "None" },
211 { "id": "5002", "type": "Glazed" },
212 { "id": "5005", "type": "Sugar" },
213 { "id": "5007", "type": "Powdered Sugar" },
214 { "id": "5006", "type": "Chocolate with Sprinkles" },
215 { "id": "5003", "type": "Chocolate" },
216 { "id": "5004", "type": "Maple" }
228 { "id": "1001", "type": "Regular" }
233 { "id": "5001", "type": "None" },
234 { "id": "5002", "type": "Glazed" },
235 { "id": "5005", "type": "Sugar" },
236 { "id": "5003", "type": "Chocolate" },
237 { "id": "5004", "type": "Maple" }
243 "name": "Old Fashioned",
249 { "id": "1001", "type": "Regular" },
250 { "id": "1002", "type": "Chocolate" }
255 { "id": "5001", "type": "None" },
256 { "id": "5002", "type": "Glazed" },
257 { "id": "5003", "type": "Chocolate" },
258 { "id": "5004", "type": "Maple" }
261 ]','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html');
262 SELECT count(*) FROM j2;
265 do_execsql_test json-5.2 {
266 SELECT id, json_valid(json), json_type(json), '|' FROM j2 ORDER BY id;
267 } {1 1 object | 2 1 object | 3 1 array |}
274 # fullkey is always the same as path+key (with appropriate formatting)
276 do_execsql_test json-5.3 {
277 SELECT j2.rowid, jx.rowid, fullkey, path, key
278 FROM j2, json_tree(j2.json) AS jx
279 WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
282 do_execsql_test json-5.4 {
283 SELECT j2.rowid, jx.rowid, fullkey, path, key
284 FROM j2, json_each(j2.json) AS jx
285 WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
290 # Verify that the json_each.json and json_tree.json output is always the
293 do_execsql_test json-5.5 {
294 SELECT j2.rowid, jx.rowid, fullkey, path, key
295 FROM j2, json_each(j2.json) AS jx
296 WHERE jx.json<>j2.json;
298 do_execsql_test json-5.6 {
299 SELECT j2.rowid, jx.rowid, fullkey, path, key
300 FROM j2, json_tree(j2.json) AS jx
301 WHERE jx.json<>j2.json;
303 do_execsql_test json-5.7 {
304 SELECT j2.rowid, jx.rowid, fullkey, path, key
305 FROM j2, json_each(j2.json) AS jx
306 WHERE jx.value<>jx.atom AND type NOT IN ('array','object');
308 do_execsql_test json-5.8 {
309 SELECT j2.rowid, jx.rowid, fullkey, path, key
310 FROM j2, json_tree(j2.json) AS jx
311 WHERE jx.value<>jx.atom AND type NOT IN ('array','object');
314 do_execsql_test json-6.1 {
315 SELECT json_valid('{"a":55,"b":72,}');
317 do_execsql_test json-6.2 {
318 SELECT json_valid('{"a":55,"b":72}');
320 do_execsql_test json-6.3 {
321 SELECT json_valid('["a",55,"b",72,]');
323 do_execsql_test json-6.4 {
324 SELECT json_valid('["a",55,"b",72]');
327 # White-space tests. Note that form-feed is not white-space in JSON.
328 # ticket [57eec374ae1d0a1d4a23077a95f4e173fe269113]
330 foreach {tn isvalid ws} {
336 7.6 1 char(0x20,0x09,0x0a,0x0d,0x20)
337 7.7 0 char(0x20,0x09,0x0a,0x0c,0x0d,0x20)
339 do_execsql_test json-$tn.1 \
340 "SELECT json_valid(printf('%s{%s\"x\"%s:%s9%s}%s',
341 $::ws,$::ws,$::ws,$::ws,$::ws,$::ws));" \
345 # Ticket https://www.sqlite.org/src/info/ad2559db380abf8e
346 # Control characters must be escaped in JSON strings.
348 do_execsql_test json-8.1 {
349 DROP TABLE IF EXISTS t8;
350 CREATE TABLE t8(a,b);
351 INSERT INTO t8(a) VALUES('abc' || char(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) || 'xyz');
352 UPDATE t8 SET b=json_array(a);
354 } {{["abc\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#xyz"]}}
355 do_execsql_test json-8.2 {
356 SELECT a=json_extract(b,'$[0]') FROM t8;
359 # 2017-04-12. Regression reported on the mailing list by Rolf Ade
361 do_execsql_test json-8.3 {
362 SELECT json_valid(char(0x22,0xe4,0x22));
364 do_execsql_test json-8.4 {
365 SELECT unicode(json_extract(char(0x22,228,0x22),'$'));
368 # The json_quote() function transforms an SQL value into a JSON value.
369 # String values are quoted and interior quotes are escaped. NULL values
370 # are rendered as the unquoted string "null".
372 do_execsql_test json-9.1 {
373 SELECT json_quote('abc"xyz');
375 do_execsql_test json-9.2 {
376 SELECT json_quote(3.14159);
378 do_execsql_test json-9.3 {
379 SELECT json_quote(12345);
381 do_execsql_test json-9.4 {
382 SELECT json_quote(null);
384 do_catchsql_test json-9.5 {
385 SELECT json_quote(x'30313233');
386 } {1 {JSON cannot hold BLOB values}}
387 do_catchsql_test json-9.6 {
388 SELECT json_quote(123,456)
389 } {1 {wrong number of arguments to function json_quote()}}
390 do_catchsql_test json-9.7 {
392 } {1 {wrong number of arguments to function json_quote()}}
394 # Make sure only valid backslash-escapes are accepted.
396 do_execsql_test json-10.1 {
397 SELECT json_valid('" \ "');
399 do_execsql_test json-10.2 {
400 SELECT json_valid('" \! "');
402 do_execsql_test json-10.3 {
403 SELECT json_valid('" \" "');
405 do_execsql_test json-10.4 {
406 SELECT json_valid('" \# "');
408 do_execsql_test json-10.5 {
409 SELECT json_valid('" \$ "');
411 do_execsql_test json-10.6 {
412 SELECT json_valid('" \% "');
414 do_execsql_test json-10.7 {
415 SELECT json_valid('" \& "');
417 do_execsql_test json-10.8 {
418 SELECT json_valid('" \'' "');
420 do_execsql_test json-10.9 {
421 SELECT json_valid('" \( "');
423 do_execsql_test json-10.10 {
424 SELECT json_valid('" \) "');
426 do_execsql_test json-10.11 {
427 SELECT json_valid('" \* "');
429 do_execsql_test json-10.12 {
430 SELECT json_valid('" \+ "');
432 do_execsql_test json-10.13 {
433 SELECT json_valid('" \, "');
435 do_execsql_test json-10.14 {
436 SELECT json_valid('" \- "');
438 do_execsql_test json-10.15 {
439 SELECT json_valid('" \. "');
441 do_execsql_test json-10.16 {
442 SELECT json_valid('" \/ "');
444 do_execsql_test json-10.17 {
445 SELECT json_valid('" \0 "');
447 do_execsql_test json-10.18 {
448 SELECT json_valid('" \1 "');
450 do_execsql_test json-10.19 {
451 SELECT json_valid('" \2 "');
453 do_execsql_test json-10.20 {
454 SELECT json_valid('" \3 "');
456 do_execsql_test json-10.21 {
457 SELECT json_valid('" \4 "');
459 do_execsql_test json-10.22 {
460 SELECT json_valid('" \5 "');
462 do_execsql_test json-10.23 {
463 SELECT json_valid('" \6 "');
465 do_execsql_test json-10.24 {
466 SELECT json_valid('" \7 "');
468 do_execsql_test json-10.25 {
469 SELECT json_valid('" \8 "');
471 do_execsql_test json-10.26 {
472 SELECT json_valid('" \9 "');
474 do_execsql_test json-10.27 {
475 SELECT json_valid('" \: "');
477 do_execsql_test json-10.28 {
478 SELECT json_valid('" \; "');
480 do_execsql_test json-10.29 {
481 SELECT json_valid('" \< "');
483 do_execsql_test json-10.30 {
484 SELECT json_valid('" \= "');
486 do_execsql_test json-10.31 {
487 SELECT json_valid('" \> "');
489 do_execsql_test json-10.32 {
490 SELECT json_valid('" \? "');
492 do_execsql_test json-10.33 {
493 SELECT json_valid('" \@ "');
495 do_execsql_test json-10.34 {
496 SELECT json_valid('" \A "');
498 do_execsql_test json-10.35 {
499 SELECT json_valid('" \B "');
501 do_execsql_test json-10.36 {
502 SELECT json_valid('" \C "');
504 do_execsql_test json-10.37 {
505 SELECT json_valid('" \D "');
507 do_execsql_test json-10.38 {
508 SELECT json_valid('" \E "');
510 do_execsql_test json-10.39 {
511 SELECT json_valid('" \F "');
513 do_execsql_test json-10.40 {
514 SELECT json_valid('" \G "');
516 do_execsql_test json-10.41 {
517 SELECT json_valid('" \H "');
519 do_execsql_test json-10.42 {
520 SELECT json_valid('" \I "');
522 do_execsql_test json-10.43 {
523 SELECT json_valid('" \J "');
525 do_execsql_test json-10.44 {
526 SELECT json_valid('" \K "');
528 do_execsql_test json-10.45 {
529 SELECT json_valid('" \L "');
531 do_execsql_test json-10.46 {
532 SELECT json_valid('" \M "');
534 do_execsql_test json-10.47 {
535 SELECT json_valid('" \N "');
537 do_execsql_test json-10.48 {
538 SELECT json_valid('" \O "');
540 do_execsql_test json-10.49 {
541 SELECT json_valid('" \P "');
543 do_execsql_test json-10.50 {
544 SELECT json_valid('" \Q "');
546 do_execsql_test json-10.51 {
547 SELECT json_valid('" \R "');
549 do_execsql_test json-10.52 {
550 SELECT json_valid('" \S "');
552 do_execsql_test json-10.53 {
553 SELECT json_valid('" \T "');
555 do_execsql_test json-10.54 {
556 SELECT json_valid('" \U "');
558 do_execsql_test json-10.55 {
559 SELECT json_valid('" \V "');
561 do_execsql_test json-10.56 {
562 SELECT json_valid('" \W "');
564 do_execsql_test json-10.57 {
565 SELECT json_valid('" \X "');
567 do_execsql_test json-10.58 {
568 SELECT json_valid('" \Y "');
570 do_execsql_test json-10.59 {
571 SELECT json_valid('" \Z "');
573 do_execsql_test json-10.60 {
574 SELECT json_valid('" \[ "');
576 do_execsql_test json-10.61 {
577 SELECT json_valid('" \\ "');
579 do_execsql_test json-10.62 {
580 SELECT json_valid('" \] "');
582 do_execsql_test json-10.63 {
583 SELECT json_valid('" \^ "');
585 do_execsql_test json-10.64 {
586 SELECT json_valid('" \_ "');
588 do_execsql_test json-10.65 {
589 SELECT json_valid('" \` "');
591 do_execsql_test json-10.66 {
592 SELECT json_valid('" \a "');
594 do_execsql_test json-10.67 {
595 SELECT json_valid('" \b "');
597 do_execsql_test json-10.68 {
598 SELECT json_valid('" \c "');
600 do_execsql_test json-10.69 {
601 SELECT json_valid('" \d "');
603 do_execsql_test json-10.70 {
604 SELECT json_valid('" \e "');
606 do_execsql_test json-10.71 {
607 SELECT json_valid('" \f "');
609 do_execsql_test json-10.72 {
610 SELECT json_valid('" \g "');
612 do_execsql_test json-10.73 {
613 SELECT json_valid('" \h "');
615 do_execsql_test json-10.74 {
616 SELECT json_valid('" \i "');
618 do_execsql_test json-10.75 {
619 SELECT json_valid('" \j "');
621 do_execsql_test json-10.76 {
622 SELECT json_valid('" \k "');
624 do_execsql_test json-10.77 {
625 SELECT json_valid('" \l "');
627 do_execsql_test json-10.78 {
628 SELECT json_valid('" \m "');
630 do_execsql_test json-10.79 {
631 SELECT json_valid('" \n "');
633 do_execsql_test json-10.80 {
634 SELECT json_valid('" \o "');
636 do_execsql_test json-10.81 {
637 SELECT json_valid('" \p "');
639 do_execsql_test json-10.82 {
640 SELECT json_valid('" \q "');
642 do_execsql_test json-10.83 {
643 SELECT json_valid('" \r "');
645 do_execsql_test json-10.84 {
646 SELECT json_valid('" \s "');
648 do_execsql_test json-10.85 {
649 SELECT json_valid('" \t "');
651 do_execsql_test json-10.86.0 {
652 SELECT json_valid('" \u "');
654 do_execsql_test json-10.86.1 {
655 SELECT json_valid('" \ua "');
657 do_execsql_test json-10.86.2 {
658 SELECT json_valid('" \uab "');
660 do_execsql_test json-10.86.3 {
661 SELECT json_valid('" \uabc "');
663 do_execsql_test json-10.86.4 {
664 SELECT json_valid('" \uabcd "');
666 do_execsql_test json-10.86.5 {
667 SELECT json_valid('" \uFEDC "');
669 do_execsql_test json-10.86.6 {
670 SELECT json_valid('" \u1234 "');
672 do_execsql_test json-10.87 {
673 SELECT json_valid('" \v "');
675 do_execsql_test json-10.88 {
676 SELECT json_valid('" \w "');
678 do_execsql_test json-10.89 {
679 SELECT json_valid('" \x "');
681 do_execsql_test json-10.90 {
682 SELECT json_valid('" \y "');
684 do_execsql_test json-10.91 {
685 SELECT json_valid('" \z "');
687 do_execsql_test json-10.92 {
688 SELECT json_valid('" \{ "');
690 do_execsql_test json-10.93 {
691 SELECT json_valid('" \| "');
693 do_execsql_test json-10.94 {
694 SELECT json_valid('" \} "');
696 do_execsql_test json-10.95 {
697 SELECT json_valid('" \~ "');
700 #--------------------------------------------------------------------------
701 # 2017-04-11. https://www.sqlite.org/src/info/981329adeef51011
702 # Stack overflow on deeply nested JSON.
704 # The following tests confirm that deeply nested JSON is considered invalid.
706 do_execsql_test json-11.0 {
707 /* Shallow enough to be parsed */
708 SELECT json_valid(printf('%.2000c0%.2000c','[',']'));
710 do_execsql_test json-11.1 {
711 /* Too deep by one */
712 SELECT json_valid(printf('%.2001c0%.2001c','[',']'));
714 do_execsql_test json-11.2 {
715 /* Shallow enough to be parsed { */
716 SELECT json_valid(replace(printf('%.2000c0%.2000c','[','}'),'[','{"a":'));
719 do_execsql_test json-11.3 {
720 /* Too deep by one { */
721 SELECT json_valid(replace(printf('%.2001c0%.2001c','[','}'),'[','{"a":'));
725 # 2017-10-27. Demonstrate the ability to access an element from
726 # a json structure even though the element name constains a "."
727 # character, by quoting the element name in the path.
729 do_execsql_test json-12.100 {
731 INSERT INTO t12(x) VALUES(
735 {"forceDisplay":true,
736 "transliterate":true,
738 "summary.report":true},
740 {"forceDisplay":true,
741 "transliterate":false,
742 "add.footnote":false,
743 "summary.report":true},
745 {"forceDisplay":true,
746 "transliterate":false,
747 "add.footnote":false,
748 "summary.report":false}
753 do_execsql_test json-12.110 {
754 SELECT json_remove(x, '$.settings.layer2."dis.legomenon".forceDisplay')
756 } {{{"settings":{"layer2":{"hapax.legomenon":{"forceDisplay":true,"transliterate":true,"add.footnote":true,"summary.report":true},"dis.legomenon":{"transliterate":false,"add.footnote":false,"summary.report":true},"tris.legomenon":{"forceDisplay":true,"transliterate":false,"add.footnote":false,"summary.report":false}}}}}}
757 do_execsql_test json-12.120 {
758 SELECT json_extract(x, '$.settings.layer2."tris.legomenon"."summary.report"')
763 # ticket https://www.sqlite.org/src/tktview/80177f0c226ff54f6ddd41
764 # Make sure the query planner knows about the arguments to table-valued functions.
766 do_execsql_test json-13.100 {
767 DROP TABLE IF EXISTS t1;
768 DROP TABLE IF EXISTS t2;
769 CREATE TABLE t1(id, json);
770 INSERT INTO t1(id,json) VALUES(1,'{"items":[3,5]}');
771 CREATE TABLE t2(id, json);
772 INSERT INTO t2(id,json) VALUES(2,'{"value":2}');
773 INSERT INTO t2(id,json) VALUES(3,'{"value":3}');
774 INSERT INTO t2(id,json) VALUES(4,'{"value":4}');
775 INSERT INTO t2(id,json) VALUES(5,'{"value":5}');
776 INSERT INTO t2(id,json) VALUES(6,'{"value":6}');
777 SELECT * FROM t1 CROSS JOIN t2
778 WHERE EXISTS(SELECT 1 FROM json_each(t1.json,'$.items') AS Z
779 WHERE Z.value==t2.id);
780 } {1 {{"items":[3,5]}} 3 {{"value":3}} 1 {{"items":[3,5]}} 5 {{"value":5}}}
781 do_execsql_test json-13.110 {
782 SELECT * FROM t2 CROSS JOIN t1
783 WHERE EXISTS(SELECT 1 FROM json_each(t1.json,'$.items') AS Z
784 WHERE Z.value==t2.id);
785 } {3 {{"value":3}} 1 {{"items":[3,5]}} 5 {{"value":5}} 1 {{"items":[3,5]}}}
788 # Incorrect fullkey output from json_each()
789 # when the input JSON is not an array or object.
791 do_execsql_test json-14.100 {
792 SELECT fullkey FROM json_each('123');
794 do_execsql_test json-14.110 {
795 SELECT fullkey FROM json_each('123.56');
797 do_execsql_test json-14.120 {
798 SELECT fullkey FROM json_each('"hello"');
800 do_execsql_test json-14.130 {
801 SELECT fullkey FROM json_each('null');
803 do_execsql_test json-14.140 {
804 SELECT fullkey FROM json_tree('123');
806 do_execsql_test json-14.150 {
807 SELECT fullkey FROM json_tree('123.56');
809 do_execsql_test json-14.160 {
810 SELECT fullkey FROM json_tree('"hello"');
812 do_execsql_test json-14.170 {
813 SELECT fullkey FROM json_tree('null');
817 # Make sure the table-valued functions contained within parentheses
820 # Bug reported via private email. See TH3 for more information.
822 do_execsql_test json-15.100 {
823 SELECT * FROM JSON_EACH('{"a":1, "b":2}');
824 } {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}}
825 do_execsql_test json-15.110 {
826 SELECT xyz.* FROM JSON_EACH('{"a":1, "b":2}') AS xyz;
827 } {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}}
828 do_execsql_test json-15.120 {
829 SELECT * FROM (JSON_EACH('{"a":1, "b":2}'));
830 } {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}}
831 do_execsql_test json-15.130 {
832 SELECT xyz.* FROM (JSON_EACH('{"a":1, "b":2}')) AS xyz;
833 } {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}}
836 # Mailing list bug report on the handling of surrogate pairs
839 do_execsql_test json-16.10 {
840 SELECT length(json_extract('"abc\uD834\uDD1Exyz"','$'));
842 do_execsql_test json-16.20 {
843 SELECT length(json_extract('"\uD834\uDD1E"','$'));
845 do_execsql_test json-16.30 {
846 SELECT unicode(json_extract('"\uD834\uDD1E"','$'));