16fd5c1e0Sdrh# 2015-08-12 26fd5c1e0Sdrh# 36fd5c1e0Sdrh# The author disclaims copyright to this source code. In place of 46fd5c1e0Sdrh# a legal notice, here is a blessing: 56fd5c1e0Sdrh# 66fd5c1e0Sdrh# May you do good and not evil. 76fd5c1e0Sdrh# May you find forgiveness for yourself and forgive others. 86fd5c1e0Sdrh# May you share freely, never taking more than you give. 96fd5c1e0Sdrh# 106fd5c1e0Sdrh#*********************************************************************** 116fd5c1e0Sdrh# This file implements tests for JSON SQL functions extension to the 126fd5c1e0Sdrh# SQLite library. 136fd5c1e0Sdrh# 146fd5c1e0Sdrh 156fd5c1e0Sdrhset testdir [file dirname $argv0] 166fd5c1e0Sdrhsource $testdir/tester.tcl 176fd5c1e0Sdrh 18b7601461Sdrhdo_execsql_test json101-1.1.00 { 196fd5c1e0Sdrh SELECT json_array(1,2.5,null,'hello'); 206fd5c1e0Sdrh} {[1,2.5,null,"hello"]} 21b7601461Sdrhdo_execsql_test json101-1.1.01 { 22f5ddb9c2Sdrh SELECT json_array(1,'{"abc":2.5,"def":null,"ghi":hello}',99); 23f5ddb9c2Sdrh -- the second term goes in as a string: 24f5ddb9c2Sdrh} {[1,"{\\"abc\\":2.5,\\"def\\":null,\\"ghi\\":hello}",99]} 25b7601461Sdrhdo_execsql_test json101-1.1.02 { 26f5ddb9c2Sdrh SELECT json_array(1,json('{"abc":2.5,"def":null,"ghi":"hello"}'),99); 27f5ddb9c2Sdrh -- the second term goes in as JSON 28f5ddb9c2Sdrh} {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]} 29b7601461Sdrhdo_execsql_test json101-1.1.03 { 30f5ddb9c2Sdrh SELECT json_array(1,json_object('abc',2.5,'def',null,'ghi','hello'),99); 31f5ddb9c2Sdrh -- the second term goes in as JSON 32f5ddb9c2Sdrh} {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]} 33b7601461Sdrhdo_execsql_test json101-1.2 { 346fd5c1e0Sdrh SELECT hex(json_array('String "\ Test')); 356fd5c1e0Sdrh} {5B22537472696E67205C225C5C2054657374225D} 36b7601461Sdrhdo_catchsql_test json101-1.3 { 37dc384957Sdrh SELECT json_array(1,printf('%.1000c','x'),x'abcd',3); 386fd5c1e0Sdrh} {1 {JSON cannot hold BLOB values}} 39b7601461Sdrhdo_execsql_test json101-1.4 { 406fd5c1e0Sdrh SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1, 416fd5c1e0Sdrh 0.0, 1.0, -1.0, -1e99, +2e100, 426fd5c1e0Sdrh 'one','two','three', 436fd5c1e0Sdrh 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 446fd5c1e0Sdrh 19, NULL, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 456fd5c1e0Sdrh 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ', 466fd5c1e0Sdrh 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ', 476fd5c1e0Sdrh 'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ', 486fd5c1e0Sdrh 99); 496fd5c1e0Sdrh} {[-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]} 506fd5c1e0Sdrh 51b7601461Sdrhdo_execsql_test json101-2.1 { 526fd5c1e0Sdrh SELECT json_object('a',1,'b',2.5,'c',null,'d','String Test'); 536fd5c1e0Sdrh} {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}} 54b7601461Sdrhdo_catchsql_test json101-2.2 { 55dc384957Sdrh SELECT json_object('a',printf('%.1000c','x'),2,2.5); 566fd5c1e0Sdrh} {1 {json_object() labels must be TEXT}} 57b7601461Sdrhdo_catchsql_test json101-2.3 { 586fd5c1e0Sdrh SELECT json_object('a',1,'b'); 596fd5c1e0Sdrh} {1 {json_object() requires an even number of arguments}} 60b7601461Sdrhdo_catchsql_test json101-2.4 { 61dc384957Sdrh SELECT json_object('a',printf('%.1000c','x'),'b',x'abcd'); 626fd5c1e0Sdrh} {1 {JSON cannot hold BLOB values}} 636fd5c1e0Sdrh 64b7601461Sdrhdo_execsql_test json101-3.1 { 65ecb5fedbSdrh SELECT json_replace('{"a":1,"b":2}','$.a','[3,4,5]'); 66ecb5fedbSdrh} {{{"a":"[3,4,5]","b":2}}} 67b7601461Sdrhdo_execsql_test json101-3.2 { 68f5ddb9c2Sdrh SELECT json_replace('{"a":1,"b":2}','$.a',json('[3,4,5]')); 69ecb5fedbSdrh} {{{"a":[3,4,5],"b":2}}} 70b7601461Sdrhdo_execsql_test json101-3.3 { 71ecb5fedbSdrh SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b'); 72ecb5fedbSdrh} {text} 73b7601461Sdrhdo_execsql_test json101-3.4 { 74f5ddb9c2Sdrh SELECT json_type(json_set('{"a":1,"b":2}','$.b',json('{"x":3,"y":4}')),'$.b'); 75ecb5fedbSdrh} {object} 76b7601461Sdrhifcapable vtab { 77b7601461Sdrhdo_execsql_test json101-3.5 { 788cb0c83cSdrh SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456)); 798cb0c83cSdrh} {{$} {} | {$.x} 456 |} 80b7601461Sdrh} 816fd5c1e0Sdrh 82d1f0068dSdrh# Per rfc7159, any JSON value is allowed at the top level, and whitespace 83d1f0068dSdrh# is permitting before and/or after that value. 84d1f0068dSdrh# 85b7601461Sdrhdo_execsql_test json101-4.1 { 86d1f0068dSdrh CREATE TABLE j1(x); 87d1f0068dSdrh INSERT INTO j1(x) 88d1f0068dSdrh VALUES('true'),('false'),('null'),('123'),('-234'),('34.5e+6'), 89d1f0068dSdrh ('""'),('"\""'),('"\\"'),('"abcdefghijlmnopqrstuvwxyz"'), 90d1f0068dSdrh ('[]'),('{}'),('[true,false,null,123,-234,34.5e+6,{},[]]'), 91d1f0068dSdrh ('{"a":true,"b":{"c":false}}'); 92d1f0068dSdrh SELECT * FROM j1 WHERE NOT json_valid(x); 93d1f0068dSdrh} {} 94b7601461Sdrhdo_execsql_test json101-4.2 { 95d1f0068dSdrh SELECT * FROM j1 WHERE NOT json_valid(char(0x20,0x09,0x0a,0x0d)||x); 96d1f0068dSdrh} {} 97b7601461Sdrhdo_execsql_test json101-4.3 { 98d1f0068dSdrh SELECT * FROM j1 WHERE NOT json_valid(x||char(0x20,0x09,0x0a,0x0d)); 99d1f0068dSdrh} {} 100d1f0068dSdrh 101d1f0068dSdrh# But an empty string, or a string of pure whitespace is not valid JSON. 102d1f0068dSdrh# 103b7601461Sdrhdo_execsql_test json101-4.4 { 104d1f0068dSdrh SELECT json_valid(''), json_valid(char(0x20,0x09,0x0a,0x0d)); 105d1f0068dSdrh} {0 0} 106d1f0068dSdrh 107d1f0068dSdrh# json_remove() and similar functions with no edit operations return their 108d1f0068dSdrh# input unchanged. 109d1f0068dSdrh# 110b7601461Sdrhdo_execsql_test json101-4.5 { 111d1f0068dSdrh SELECT x FROM j1 WHERE json_remove(x)<>x; 112d1f0068dSdrh} {} 113b7601461Sdrhdo_execsql_test json101-4.6 { 114d1f0068dSdrh SELECT x FROM j1 WHERE json_replace(x)<>x; 115d1f0068dSdrh} {} 116b7601461Sdrhdo_execsql_test json101-4.7 { 117d1f0068dSdrh SELECT x FROM j1 WHERE json_set(x)<>x; 118d1f0068dSdrh} {} 119b7601461Sdrhdo_execsql_test json101-4.8 { 120d1f0068dSdrh SELECT x FROM j1 WHERE json_insert(x)<>x; 121d1f0068dSdrh} {} 122d1f0068dSdrh 123d1f0068dSdrh# json_extract(JSON,'$') will return objects and arrays without change. 124d1f0068dSdrh# 125d1f0068dSdrhdo_execsql_test json-4.10 { 126d1f0068dSdrh SELECT count(*) FROM j1 WHERE json_type(x) IN ('object','array'); 127d1f0068dSdrh SELECT x FROM j1 128d1f0068dSdrh WHERE json_extract(x,'$')<>x 129d1f0068dSdrh AND json_type(x) IN ('object','array'); 130d1f0068dSdrh} {4} 131d1f0068dSdrh 13220b3b610Sdrhdo_execsql_test json-5.1 { 13320b3b610Sdrh CREATE TABLE j2(id INTEGER PRIMARY KEY, json, src); 13420b3b610Sdrh INSERT INTO j2(id,json,src) 13520b3b610Sdrh VALUES(1,'{ 13620b3b610Sdrh "firstName": "John", 13720b3b610Sdrh "lastName": "Smith", 13820b3b610Sdrh "isAlive": true, 13920b3b610Sdrh "age": 25, 14020b3b610Sdrh "address": { 14120b3b610Sdrh "streetAddress": "21 2nd Street", 14220b3b610Sdrh "city": "New York", 14320b3b610Sdrh "state": "NY", 14420b3b610Sdrh "postalCode": "10021-3100" 14520b3b610Sdrh }, 14620b3b610Sdrh "phoneNumbers": [ 14720b3b610Sdrh { 14820b3b610Sdrh "type": "home", 14920b3b610Sdrh "number": "212 555-1234" 15020b3b610Sdrh }, 15120b3b610Sdrh { 15220b3b610Sdrh "type": "office", 15320b3b610Sdrh "number": "646 555-4567" 15420b3b610Sdrh } 15520b3b610Sdrh ], 15620b3b610Sdrh "children": [], 15720b3b610Sdrh "spouse": null 15820b3b610Sdrh }','https://en.wikipedia.org/wiki/JSON'); 15920b3b610Sdrh INSERT INTO j2(id,json,src) 16020b3b610Sdrh VALUES(2, '{ 16120b3b610Sdrh "id": "0001", 16220b3b610Sdrh "type": "donut", 16320b3b610Sdrh "name": "Cake", 16420b3b610Sdrh "ppu": 0.55, 16520b3b610Sdrh "batters": 16620b3b610Sdrh { 16720b3b610Sdrh "batter": 16820b3b610Sdrh [ 16920b3b610Sdrh { "id": "1001", "type": "Regular" }, 17020b3b610Sdrh { "id": "1002", "type": "Chocolate" }, 17120b3b610Sdrh { "id": "1003", "type": "Blueberry" }, 17220b3b610Sdrh { "id": "1004", "type": "Devil''s Food" } 17320b3b610Sdrh ] 17420b3b610Sdrh }, 17520b3b610Sdrh "topping": 17620b3b610Sdrh [ 17720b3b610Sdrh { "id": "5001", "type": "None" }, 17820b3b610Sdrh { "id": "5002", "type": "Glazed" }, 17920b3b610Sdrh { "id": "5005", "type": "Sugar" }, 18020b3b610Sdrh { "id": "5007", "type": "Powdered Sugar" }, 18120b3b610Sdrh { "id": "5006", "type": "Chocolate with Sprinkles" }, 18220b3b610Sdrh { "id": "5003", "type": "Chocolate" }, 18320b3b610Sdrh { "id": "5004", "type": "Maple" } 18420b3b610Sdrh ] 18520b3b610Sdrh }','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html'); 18620b3b610Sdrh INSERT INTO j2(id,json,src) 18720b3b610Sdrh VALUES(3,'[ 18820b3b610Sdrh { 18920b3b610Sdrh "id": "0001", 19020b3b610Sdrh "type": "donut", 19120b3b610Sdrh "name": "Cake", 19220b3b610Sdrh "ppu": 0.55, 19320b3b610Sdrh "batters": 19420b3b610Sdrh { 19520b3b610Sdrh "batter": 19620b3b610Sdrh [ 19720b3b610Sdrh { "id": "1001", "type": "Regular" }, 19820b3b610Sdrh { "id": "1002", "type": "Chocolate" }, 19920b3b610Sdrh { "id": "1003", "type": "Blueberry" }, 20020b3b610Sdrh { "id": "1004", "type": "Devil''s Food" } 20120b3b610Sdrh ] 20220b3b610Sdrh }, 20320b3b610Sdrh "topping": 20420b3b610Sdrh [ 20520b3b610Sdrh { "id": "5001", "type": "None" }, 20620b3b610Sdrh { "id": "5002", "type": "Glazed" }, 20720b3b610Sdrh { "id": "5005", "type": "Sugar" }, 20820b3b610Sdrh { "id": "5007", "type": "Powdered Sugar" }, 20920b3b610Sdrh { "id": "5006", "type": "Chocolate with Sprinkles" }, 21020b3b610Sdrh { "id": "5003", "type": "Chocolate" }, 21120b3b610Sdrh { "id": "5004", "type": "Maple" } 21220b3b610Sdrh ] 21320b3b610Sdrh }, 21420b3b610Sdrh { 21520b3b610Sdrh "id": "0002", 21620b3b610Sdrh "type": "donut", 21720b3b610Sdrh "name": "Raised", 21820b3b610Sdrh "ppu": 0.55, 21920b3b610Sdrh "batters": 22020b3b610Sdrh { 22120b3b610Sdrh "batter": 22220b3b610Sdrh [ 22320b3b610Sdrh { "id": "1001", "type": "Regular" } 22420b3b610Sdrh ] 22520b3b610Sdrh }, 22620b3b610Sdrh "topping": 22720b3b610Sdrh [ 22820b3b610Sdrh { "id": "5001", "type": "None" }, 22920b3b610Sdrh { "id": "5002", "type": "Glazed" }, 23020b3b610Sdrh { "id": "5005", "type": "Sugar" }, 23120b3b610Sdrh { "id": "5003", "type": "Chocolate" }, 23220b3b610Sdrh { "id": "5004", "type": "Maple" } 23320b3b610Sdrh ] 23420b3b610Sdrh }, 23520b3b610Sdrh { 23620b3b610Sdrh "id": "0003", 23720b3b610Sdrh "type": "donut", 23820b3b610Sdrh "name": "Old Fashioned", 23920b3b610Sdrh "ppu": 0.55, 24020b3b610Sdrh "batters": 24120b3b610Sdrh { 24220b3b610Sdrh "batter": 24320b3b610Sdrh [ 24420b3b610Sdrh { "id": "1001", "type": "Regular" }, 24520b3b610Sdrh { "id": "1002", "type": "Chocolate" } 24620b3b610Sdrh ] 24720b3b610Sdrh }, 24820b3b610Sdrh "topping": 24920b3b610Sdrh [ 25020b3b610Sdrh { "id": "5001", "type": "None" }, 25120b3b610Sdrh { "id": "5002", "type": "Glazed" }, 25220b3b610Sdrh { "id": "5003", "type": "Chocolate" }, 25320b3b610Sdrh { "id": "5004", "type": "Maple" } 25420b3b610Sdrh ] 25520b3b610Sdrh } 25620b3b610Sdrh ]','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html'); 25720b3b610Sdrh SELECT count(*) FROM j2; 25820b3b610Sdrh} {3} 25920b3b610Sdrh 26020b3b610Sdrhdo_execsql_test json-5.2 { 26120b3b610Sdrh SELECT id, json_valid(json), json_type(json), '|' FROM j2 ORDER BY id; 26220b3b610Sdrh} {1 1 object | 2 1 object | 3 1 array |} 26320b3b610Sdrh 26420b3b610Sdrhifcapable !vtab { 26520b3b610Sdrh finish_test 26620b3b610Sdrh return 26720b3b610Sdrh} 26820b3b610Sdrh 26920b3b610Sdrh# fullkey is always the same as path+key (with appropriate formatting) 27020b3b610Sdrh# 27120b3b610Sdrhdo_execsql_test json-5.3 { 27220b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 27320b3b610Sdrh FROM j2, json_tree(j2.json) AS jx 27420b3b610Sdrh WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']' 27520b3b610Sdrh ELSE '.'||key END); 27620b3b610Sdrh} {} 27720b3b610Sdrhdo_execsql_test json-5.4 { 27820b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 27920b3b610Sdrh FROM j2, json_each(j2.json) AS jx 28020b3b610Sdrh WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']' 28120b3b610Sdrh ELSE '.'||key END); 28220b3b610Sdrh} {} 28320b3b610Sdrh 28420b3b610Sdrh 28520b3b610Sdrh# Verify that the json_each.json and json_tree.json output is always the 28620b3b610Sdrh# same as input. 28720b3b610Sdrh# 28820b3b610Sdrhdo_execsql_test json-5.5 { 28920b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 29020b3b610Sdrh FROM j2, json_each(j2.json) AS jx 29120b3b610Sdrh WHERE jx.json<>j2.json; 29220b3b610Sdrh} {} 29320b3b610Sdrhdo_execsql_test json-5.6 { 29420b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 29520b3b610Sdrh FROM j2, json_tree(j2.json) AS jx 29620b3b610Sdrh WHERE jx.json<>j2.json; 29720b3b610Sdrh} {} 29820b3b610Sdrhdo_execsql_test json-5.7 { 29920b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 30020b3b610Sdrh FROM j2, json_each(j2.json) AS jx 30120b3b610Sdrh WHERE jx.value<>jx.atom AND type NOT IN ('array','object'); 30220b3b610Sdrh} {} 30320b3b610Sdrhdo_execsql_test json-5.8 { 30420b3b610Sdrh SELECT j2.rowid, jx.rowid, fullkey, path, key 30520b3b610Sdrh FROM j2, json_tree(j2.json) AS jx 30620b3b610Sdrh WHERE jx.value<>jx.atom AND type NOT IN ('array','object'); 30720b3b610Sdrh} {} 30820b3b610Sdrh 309f27cd1f3Sdrhdo_execsql_test json-6.1 { 310f27cd1f3Sdrh SELECT json_valid('{"a":55,"b":72,}'); 311f27cd1f3Sdrh} {0} 312f27cd1f3Sdrhdo_execsql_test json-6.2 { 313f27cd1f3Sdrh SELECT json_valid('{"a":55,"b":72}'); 314f27cd1f3Sdrh} {1} 315f27cd1f3Sdrhdo_execsql_test json-6.3 { 316f27cd1f3Sdrh SELECT json_valid('["a",55,"b",72,]'); 317f27cd1f3Sdrh} {0} 318f27cd1f3Sdrhdo_execsql_test json-6.4 { 319f27cd1f3Sdrh SELECT json_valid('["a",55,"b",72]'); 320f27cd1f3Sdrh} {1} 32120b3b610Sdrh 322b9e8f59bSdrh# White-space tests. Note that form-feed is not white-space in JSON. 323b9e8f59bSdrh# ticket [57eec374ae1d0a1d4a23077a95f4e173fe269113] 324b9e8f59bSdrh# 325b9e8f59bSdrhforeach {tn isvalid ws} { 326b9e8f59bSdrh 7.1 1 char(0x20) 327b9e8f59bSdrh 7.2 1 char(0x09) 328b9e8f59bSdrh 7.3 1 char(0x0A) 329b9e8f59bSdrh 7.4 1 char(0x0D) 330b9e8f59bSdrh 7.5 0 char(0x0C) 331b9e8f59bSdrh 7.6 1 char(0x20,0x09,0x0a,0x0d,0x20) 332b9e8f59bSdrh 7.7 0 char(0x20,0x09,0x0a,0x0c,0x0d,0x20) 333b9e8f59bSdrh} { 334b9e8f59bSdrh do_execsql_test json-$tn.1 \ 335b9e8f59bSdrh "SELECT json_valid(printf('%s{%s\"x\"%s:%s9%s}%s', 336b9e8f59bSdrh $::ws,$::ws,$::ws,$::ws,$::ws,$::ws));" \ 337b9e8f59bSdrh $isvalid 338b9e8f59bSdrh} 33920b3b610Sdrh 3403b7f9a68Sdrh# Ticket https://www.sqlite.org/src/info/ad2559db380abf8e 3413b7f9a68Sdrh# Control characters must be escaped in JSON strings. 3423b7f9a68Sdrh# 3433b7f9a68Sdrhdo_execsql_test json-8.1 { 3443b7f9a68Sdrh DROP TABLE IF EXISTS t8; 3453b7f9a68Sdrh CREATE TABLE t8(a,b); 3463b7f9a68Sdrh 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'); 3473b7f9a68Sdrh UPDATE t8 SET b=json_array(a); 3483b7f9a68Sdrh SELECT b FROM t8; 3493b7f9a68Sdrh} {{["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"]}} 3503b7f9a68Sdrhdo_execsql_test json-8.2 { 3513b7f9a68Sdrh SELECT a=json_extract(b,'$[0]') FROM t8; 3523b7f9a68Sdrh} {1} 3533b7f9a68Sdrh 3548671538cSdrh# 2017-04-12. Regression reported on the mailing list by Rolf Ade 3558671538cSdrh# 3568671538cSdrhdo_execsql_test json-8.3 { 3578671538cSdrh SELECT json_valid(char(0x22,0xe4,0x22)); 3588671538cSdrh} {1} 3598671538cSdrhdo_execsql_test json-8.4 { 3608671538cSdrh SELECT unicode(json_extract(char(0x22,228,0x22),'$')); 3618671538cSdrh} {228} 3628671538cSdrh 3632ad96f58Sdrh# The json_quote() function transforms an SQL value into a JSON value. 3642ad96f58Sdrh# String values are quoted and interior quotes are escaped. NULL values 3652ad96f58Sdrh# are rendered as the unquoted string "null". 3662ad96f58Sdrh# 3672ad96f58Sdrhdo_execsql_test json-9.1 { 3682ad96f58Sdrh SELECT json_quote('abc"xyz'); 3692ad96f58Sdrh} {{"abc\"xyz"}} 3702ad96f58Sdrhdo_execsql_test json-9.2 { 3712ad96f58Sdrh SELECT json_quote(3.14159); 3722ad96f58Sdrh} {3.14159} 3732ad96f58Sdrhdo_execsql_test json-9.3 { 3742ad96f58Sdrh SELECT json_quote(12345); 3752ad96f58Sdrh} {12345} 3762ad96f58Sdrhdo_execsql_test json-9.4 { 3772ad96f58Sdrh SELECT json_quote(null); 3782ad96f58Sdrh} {"null"} 3792ad96f58Sdrhdo_catchsql_test json-9.5 { 3802ad96f58Sdrh SELECT json_quote(x'30313233'); 3812ad96f58Sdrh} {1 {JSON cannot hold BLOB values}} 3822ad96f58Sdrhdo_catchsql_test json-9.6 { 3832ad96f58Sdrh SELECT json_quote(123,456) 3842ad96f58Sdrh} {1 {wrong number of arguments to function json_quote()}} 3852ad96f58Sdrhdo_catchsql_test json-9.7 { 3862ad96f58Sdrh SELECT json_quote() 3872ad96f58Sdrh} {1 {wrong number of arguments to function json_quote()}} 3882ad96f58Sdrh 389ad875e74Sdrh# Make sure only valid backslash-escapes are accepted. 390ad875e74Sdrh# 391ad875e74Sdrhdo_execsql_test json-10.1 { 392ad875e74Sdrh SELECT json_valid('" \ "'); 393ad875e74Sdrh} {0} 394ad875e74Sdrhdo_execsql_test json-10.2 { 395ad875e74Sdrh SELECT json_valid('" \! "'); 396ad875e74Sdrh} {0} 397ad875e74Sdrhdo_execsql_test json-10.3 { 398ad875e74Sdrh SELECT json_valid('" \" "'); 399ad875e74Sdrh} {1} 400ad875e74Sdrhdo_execsql_test json-10.4 { 401ad875e74Sdrh SELECT json_valid('" \# "'); 402ad875e74Sdrh} {0} 403ad875e74Sdrhdo_execsql_test json-10.5 { 404ad875e74Sdrh SELECT json_valid('" \$ "'); 405ad875e74Sdrh} {0} 406ad875e74Sdrhdo_execsql_test json-10.6 { 407ad875e74Sdrh SELECT json_valid('" \% "'); 408ad875e74Sdrh} {0} 409ad875e74Sdrhdo_execsql_test json-10.7 { 410ad875e74Sdrh SELECT json_valid('" \& "'); 411ad875e74Sdrh} {0} 412ad875e74Sdrhdo_execsql_test json-10.8 { 413ad875e74Sdrh SELECT json_valid('" \'' "'); 414ad875e74Sdrh} {0} 415ad875e74Sdrhdo_execsql_test json-10.9 { 416ad875e74Sdrh SELECT json_valid('" \( "'); 417ad875e74Sdrh} {0} 418ad875e74Sdrhdo_execsql_test json-10.10 { 419ad875e74Sdrh SELECT json_valid('" \) "'); 420ad875e74Sdrh} {0} 421ad875e74Sdrhdo_execsql_test json-10.11 { 422ad875e74Sdrh SELECT json_valid('" \* "'); 423ad875e74Sdrh} {0} 424ad875e74Sdrhdo_execsql_test json-10.12 { 425ad875e74Sdrh SELECT json_valid('" \+ "'); 426ad875e74Sdrh} {0} 427ad875e74Sdrhdo_execsql_test json-10.13 { 428ad875e74Sdrh SELECT json_valid('" \, "'); 429ad875e74Sdrh} {0} 430ad875e74Sdrhdo_execsql_test json-10.14 { 431ad875e74Sdrh SELECT json_valid('" \- "'); 432ad875e74Sdrh} {0} 433ad875e74Sdrhdo_execsql_test json-10.15 { 434ad875e74Sdrh SELECT json_valid('" \. "'); 435ad875e74Sdrh} {0} 436ad875e74Sdrhdo_execsql_test json-10.16 { 437ad875e74Sdrh SELECT json_valid('" \/ "'); 438ad875e74Sdrh} {1} 439ad875e74Sdrhdo_execsql_test json-10.17 { 440ad875e74Sdrh SELECT json_valid('" \0 "'); 441ad875e74Sdrh} {0} 442ad875e74Sdrhdo_execsql_test json-10.18 { 443ad875e74Sdrh SELECT json_valid('" \1 "'); 444ad875e74Sdrh} {0} 445ad875e74Sdrhdo_execsql_test json-10.19 { 446ad875e74Sdrh SELECT json_valid('" \2 "'); 447ad875e74Sdrh} {0} 448ad875e74Sdrhdo_execsql_test json-10.20 { 449ad875e74Sdrh SELECT json_valid('" \3 "'); 450ad875e74Sdrh} {0} 451ad875e74Sdrhdo_execsql_test json-10.21 { 452ad875e74Sdrh SELECT json_valid('" \4 "'); 453ad875e74Sdrh} {0} 454ad875e74Sdrhdo_execsql_test json-10.22 { 455ad875e74Sdrh SELECT json_valid('" \5 "'); 456ad875e74Sdrh} {0} 457ad875e74Sdrhdo_execsql_test json-10.23 { 458ad875e74Sdrh SELECT json_valid('" \6 "'); 459ad875e74Sdrh} {0} 460ad875e74Sdrhdo_execsql_test json-10.24 { 461ad875e74Sdrh SELECT json_valid('" \7 "'); 462ad875e74Sdrh} {0} 463ad875e74Sdrhdo_execsql_test json-10.25 { 464ad875e74Sdrh SELECT json_valid('" \8 "'); 465ad875e74Sdrh} {0} 466ad875e74Sdrhdo_execsql_test json-10.26 { 467ad875e74Sdrh SELECT json_valid('" \9 "'); 468ad875e74Sdrh} {0} 469ad875e74Sdrhdo_execsql_test json-10.27 { 470ad875e74Sdrh SELECT json_valid('" \: "'); 471ad875e74Sdrh} {0} 472ad875e74Sdrhdo_execsql_test json-10.28 { 473ad875e74Sdrh SELECT json_valid('" \; "'); 474ad875e74Sdrh} {0} 475ad875e74Sdrhdo_execsql_test json-10.29 { 476ad875e74Sdrh SELECT json_valid('" \< "'); 477ad875e74Sdrh} {0} 478ad875e74Sdrhdo_execsql_test json-10.30 { 479ad875e74Sdrh SELECT json_valid('" \= "'); 480ad875e74Sdrh} {0} 481ad875e74Sdrhdo_execsql_test json-10.31 { 482ad875e74Sdrh SELECT json_valid('" \> "'); 483ad875e74Sdrh} {0} 484ad875e74Sdrhdo_execsql_test json-10.32 { 485ad875e74Sdrh SELECT json_valid('" \? "'); 486ad875e74Sdrh} {0} 487ad875e74Sdrhdo_execsql_test json-10.33 { 488ad875e74Sdrh SELECT json_valid('" \@ "'); 489ad875e74Sdrh} {0} 490ad875e74Sdrhdo_execsql_test json-10.34 { 491ad875e74Sdrh SELECT json_valid('" \A "'); 492ad875e74Sdrh} {0} 493ad875e74Sdrhdo_execsql_test json-10.35 { 494ad875e74Sdrh SELECT json_valid('" \B "'); 495ad875e74Sdrh} {0} 496ad875e74Sdrhdo_execsql_test json-10.36 { 497ad875e74Sdrh SELECT json_valid('" \C "'); 498ad875e74Sdrh} {0} 499ad875e74Sdrhdo_execsql_test json-10.37 { 500ad875e74Sdrh SELECT json_valid('" \D "'); 501ad875e74Sdrh} {0} 502ad875e74Sdrhdo_execsql_test json-10.38 { 503ad875e74Sdrh SELECT json_valid('" \E "'); 504ad875e74Sdrh} {0} 505ad875e74Sdrhdo_execsql_test json-10.39 { 506ad875e74Sdrh SELECT json_valid('" \F "'); 507ad875e74Sdrh} {0} 508ad875e74Sdrhdo_execsql_test json-10.40 { 509ad875e74Sdrh SELECT json_valid('" \G "'); 510ad875e74Sdrh} {0} 511ad875e74Sdrhdo_execsql_test json-10.41 { 512ad875e74Sdrh SELECT json_valid('" \H "'); 513ad875e74Sdrh} {0} 514ad875e74Sdrhdo_execsql_test json-10.42 { 515ad875e74Sdrh SELECT json_valid('" \I "'); 516ad875e74Sdrh} {0} 517ad875e74Sdrhdo_execsql_test json-10.43 { 518ad875e74Sdrh SELECT json_valid('" \J "'); 519ad875e74Sdrh} {0} 520ad875e74Sdrhdo_execsql_test json-10.44 { 521ad875e74Sdrh SELECT json_valid('" \K "'); 522ad875e74Sdrh} {0} 523ad875e74Sdrhdo_execsql_test json-10.45 { 524ad875e74Sdrh SELECT json_valid('" \L "'); 525ad875e74Sdrh} {0} 526ad875e74Sdrhdo_execsql_test json-10.46 { 527ad875e74Sdrh SELECT json_valid('" \M "'); 528ad875e74Sdrh} {0} 529ad875e74Sdrhdo_execsql_test json-10.47 { 530ad875e74Sdrh SELECT json_valid('" \N "'); 531ad875e74Sdrh} {0} 532ad875e74Sdrhdo_execsql_test json-10.48 { 533ad875e74Sdrh SELECT json_valid('" \O "'); 534ad875e74Sdrh} {0} 535ad875e74Sdrhdo_execsql_test json-10.49 { 536ad875e74Sdrh SELECT json_valid('" \P "'); 537ad875e74Sdrh} {0} 538ad875e74Sdrhdo_execsql_test json-10.50 { 539ad875e74Sdrh SELECT json_valid('" \Q "'); 540ad875e74Sdrh} {0} 541ad875e74Sdrhdo_execsql_test json-10.51 { 542ad875e74Sdrh SELECT json_valid('" \R "'); 543ad875e74Sdrh} {0} 544ad875e74Sdrhdo_execsql_test json-10.52 { 545ad875e74Sdrh SELECT json_valid('" \S "'); 546ad875e74Sdrh} {0} 547ad875e74Sdrhdo_execsql_test json-10.53 { 548ad875e74Sdrh SELECT json_valid('" \T "'); 549ad875e74Sdrh} {0} 550ad875e74Sdrhdo_execsql_test json-10.54 { 551ad875e74Sdrh SELECT json_valid('" \U "'); 552ad875e74Sdrh} {0} 553ad875e74Sdrhdo_execsql_test json-10.55 { 554ad875e74Sdrh SELECT json_valid('" \V "'); 555ad875e74Sdrh} {0} 556ad875e74Sdrhdo_execsql_test json-10.56 { 557ad875e74Sdrh SELECT json_valid('" \W "'); 558ad875e74Sdrh} {0} 559ad875e74Sdrhdo_execsql_test json-10.57 { 560ad875e74Sdrh SELECT json_valid('" \X "'); 561ad875e74Sdrh} {0} 562ad875e74Sdrhdo_execsql_test json-10.58 { 563ad875e74Sdrh SELECT json_valid('" \Y "'); 564ad875e74Sdrh} {0} 565ad875e74Sdrhdo_execsql_test json-10.59 { 566ad875e74Sdrh SELECT json_valid('" \Z "'); 567ad875e74Sdrh} {0} 568ad875e74Sdrhdo_execsql_test json-10.60 { 569ad875e74Sdrh SELECT json_valid('" \[ "'); 570ad875e74Sdrh} {0} 571ad875e74Sdrhdo_execsql_test json-10.61 { 572ad875e74Sdrh SELECT json_valid('" \\ "'); 573ad875e74Sdrh} {1} 574ad875e74Sdrhdo_execsql_test json-10.62 { 575ad875e74Sdrh SELECT json_valid('" \] "'); 576ad875e74Sdrh} {0} 577ad875e74Sdrhdo_execsql_test json-10.63 { 578ad875e74Sdrh SELECT json_valid('" \^ "'); 579ad875e74Sdrh} {0} 580ad875e74Sdrhdo_execsql_test json-10.64 { 581ad875e74Sdrh SELECT json_valid('" \_ "'); 582ad875e74Sdrh} {0} 583ad875e74Sdrhdo_execsql_test json-10.65 { 584ad875e74Sdrh SELECT json_valid('" \` "'); 585ad875e74Sdrh} {0} 586ad875e74Sdrhdo_execsql_test json-10.66 { 587ad875e74Sdrh SELECT json_valid('" \a "'); 588ad875e74Sdrh} {0} 589ad875e74Sdrhdo_execsql_test json-10.67 { 590ad875e74Sdrh SELECT json_valid('" \b "'); 591ad875e74Sdrh} {1} 592ad875e74Sdrhdo_execsql_test json-10.68 { 593ad875e74Sdrh SELECT json_valid('" \c "'); 594ad875e74Sdrh} {0} 595ad875e74Sdrhdo_execsql_test json-10.69 { 596ad875e74Sdrh SELECT json_valid('" \d "'); 597ad875e74Sdrh} {0} 598ad875e74Sdrhdo_execsql_test json-10.70 { 599ad875e74Sdrh SELECT json_valid('" \e "'); 600ad875e74Sdrh} {0} 601ad875e74Sdrhdo_execsql_test json-10.71 { 602ad875e74Sdrh SELECT json_valid('" \f "'); 603ad875e74Sdrh} {1} 604ad875e74Sdrhdo_execsql_test json-10.72 { 605ad875e74Sdrh SELECT json_valid('" \g "'); 606ad875e74Sdrh} {0} 607ad875e74Sdrhdo_execsql_test json-10.73 { 608ad875e74Sdrh SELECT json_valid('" \h "'); 609ad875e74Sdrh} {0} 610ad875e74Sdrhdo_execsql_test json-10.74 { 611ad875e74Sdrh SELECT json_valid('" \i "'); 612ad875e74Sdrh} {0} 613ad875e74Sdrhdo_execsql_test json-10.75 { 614ad875e74Sdrh SELECT json_valid('" \j "'); 615ad875e74Sdrh} {0} 616ad875e74Sdrhdo_execsql_test json-10.76 { 617ad875e74Sdrh SELECT json_valid('" \k "'); 618ad875e74Sdrh} {0} 619ad875e74Sdrhdo_execsql_test json-10.77 { 620ad875e74Sdrh SELECT json_valid('" \l "'); 621ad875e74Sdrh} {0} 622ad875e74Sdrhdo_execsql_test json-10.78 { 623ad875e74Sdrh SELECT json_valid('" \m "'); 624ad875e74Sdrh} {0} 625ad875e74Sdrhdo_execsql_test json-10.79 { 626ad875e74Sdrh SELECT json_valid('" \n "'); 627ad875e74Sdrh} {1} 628ad875e74Sdrhdo_execsql_test json-10.80 { 629ad875e74Sdrh SELECT json_valid('" \o "'); 630ad875e74Sdrh} {0} 631ad875e74Sdrhdo_execsql_test json-10.81 { 632ad875e74Sdrh SELECT json_valid('" \p "'); 633ad875e74Sdrh} {0} 634ad875e74Sdrhdo_execsql_test json-10.82 { 635ad875e74Sdrh SELECT json_valid('" \q "'); 636ad875e74Sdrh} {0} 637ad875e74Sdrhdo_execsql_test json-10.83 { 638ad875e74Sdrh SELECT json_valid('" \r "'); 639ad875e74Sdrh} {1} 640ad875e74Sdrhdo_execsql_test json-10.84 { 641ad875e74Sdrh SELECT json_valid('" \s "'); 642ad875e74Sdrh} {0} 643ad875e74Sdrhdo_execsql_test json-10.85 { 644ad875e74Sdrh SELECT json_valid('" \t "'); 645ad875e74Sdrh} {1} 646ad875e74Sdrhdo_execsql_test json-10.86.0 { 647ad875e74Sdrh SELECT json_valid('" \u "'); 648ad875e74Sdrh} {0} 649ad875e74Sdrhdo_execsql_test json-10.86.1 { 650ad875e74Sdrh SELECT json_valid('" \ua "'); 651ad875e74Sdrh} {0} 652ad875e74Sdrhdo_execsql_test json-10.86.2 { 653ad875e74Sdrh SELECT json_valid('" \uab "'); 654ad875e74Sdrh} {0} 655ad875e74Sdrhdo_execsql_test json-10.86.3 { 656ad875e74Sdrh SELECT json_valid('" \uabc "'); 657ad875e74Sdrh} {0} 658ad875e74Sdrhdo_execsql_test json-10.86.4 { 659ad875e74Sdrh SELECT json_valid('" \uabcd "'); 660ad875e74Sdrh} {1} 661ad875e74Sdrhdo_execsql_test json-10.86.5 { 662ad875e74Sdrh SELECT json_valid('" \uFEDC "'); 663ad875e74Sdrh} {1} 664ad875e74Sdrhdo_execsql_test json-10.86.6 { 665ad875e74Sdrh SELECT json_valid('" \u1234 "'); 666ad875e74Sdrh} {1} 667ad875e74Sdrhdo_execsql_test json-10.87 { 668ad875e74Sdrh SELECT json_valid('" \v "'); 669ad875e74Sdrh} {0} 670ad875e74Sdrhdo_execsql_test json-10.88 { 671ad875e74Sdrh SELECT json_valid('" \w "'); 672ad875e74Sdrh} {0} 673ad875e74Sdrhdo_execsql_test json-10.89 { 674ad875e74Sdrh SELECT json_valid('" \x "'); 675ad875e74Sdrh} {0} 676ad875e74Sdrhdo_execsql_test json-10.90 { 677ad875e74Sdrh SELECT json_valid('" \y "'); 678ad875e74Sdrh} {0} 679ad875e74Sdrhdo_execsql_test json-10.91 { 680ad875e74Sdrh SELECT json_valid('" \z "'); 681ad875e74Sdrh} {0} 682ad875e74Sdrhdo_execsql_test json-10.92 { 683ad875e74Sdrh SELECT json_valid('" \{ "'); 684ad875e74Sdrh} {0} 685ad875e74Sdrhdo_execsql_test json-10.93 { 686ad875e74Sdrh SELECT json_valid('" \| "'); 687ad875e74Sdrh} {0} 688ad875e74Sdrhdo_execsql_test json-10.94 { 689ad875e74Sdrh SELECT json_valid('" \} "'); 690ad875e74Sdrh} {0} 691ad875e74Sdrhdo_execsql_test json-10.95 { 692ad875e74Sdrh SELECT json_valid('" \~ "'); 693ad875e74Sdrh} {0} 6942ad96f58Sdrh 695ff6d50e9Sdrh#-------------------------------------------------------------------------- 696ff6d50e9Sdrh# 2017-04-11. https://www.sqlite.org/src/info/981329adeef51011 697ff6d50e9Sdrh# Stack overflow on deeply nested JSON. 698ff6d50e9Sdrh# 699ff6d50e9Sdrh# The following tests confirm that deeply nested JSON is considered invalid. 700ff6d50e9Sdrh# 701ff6d50e9Sdrhdo_execsql_test json-11.0 { 702ff6d50e9Sdrh /* Shallow enough to be parsed */ 703ff6d50e9Sdrh SELECT json_valid(printf('%.2000c0%.2000c','[',']')); 704ff6d50e9Sdrh} {1} 705ff6d50e9Sdrhdo_execsql_test json-11.1 { 706ff6d50e9Sdrh /* Too deep by one */ 707ff6d50e9Sdrh SELECT json_valid(printf('%.2001c0%.2001c','[',']')); 708ff6d50e9Sdrh} {0} 709ff6d50e9Sdrhdo_execsql_test json-11.2 { 710ff6d50e9Sdrh /* Shallow enough to be parsed { */ 711ff6d50e9Sdrh SELECT json_valid(replace(printf('%.2000c0%.2000c','[','}'),'[','{"a":')); 712ff6d50e9Sdrh /* } */ 713ff6d50e9Sdrh} {1} 714ff6d50e9Sdrhdo_execsql_test json-11.3 { 715ff6d50e9Sdrh /* Too deep by one { */ 716ff6d50e9Sdrh SELECT json_valid(replace(printf('%.2001c0%.2001c','[','}'),'[','{"a":')); 717ff6d50e9Sdrh /* } */ 718ff6d50e9Sdrh} {0} 7193b7f9a68Sdrh 7206e61c5f8Sdrh# 2017-10-27. Demonstrate the ability to access an element from 7216e61c5f8Sdrh# a json structure even though the element name constains a "." 7226e61c5f8Sdrh# character, by quoting the element name in the path. 7236e61c5f8Sdrh# 7246e61c5f8Sdrhdo_execsql_test json-12.100 { 7256e61c5f8Sdrh CREATE TABLE t12(x); 7266e61c5f8Sdrh INSERT INTO t12(x) VALUES( 7276e61c5f8Sdrh '{"settings": 7286e61c5f8Sdrh {"layer2": 7296e61c5f8Sdrh {"hapax.legomenon": 7306e61c5f8Sdrh {"forceDisplay":true, 7316e61c5f8Sdrh "transliterate":true, 7326e61c5f8Sdrh "add.footnote":true, 7336e61c5f8Sdrh "summary.report":true}, 7346e61c5f8Sdrh "dis.legomenon": 7356e61c5f8Sdrh {"forceDisplay":true, 7366e61c5f8Sdrh "transliterate":false, 7376e61c5f8Sdrh "add.footnote":false, 7386e61c5f8Sdrh "summary.report":true}, 7396e61c5f8Sdrh "tris.legomenon": 7406e61c5f8Sdrh {"forceDisplay":true, 7416e61c5f8Sdrh "transliterate":false, 7426e61c5f8Sdrh "add.footnote":false, 7436e61c5f8Sdrh "summary.report":false} 7446e61c5f8Sdrh } 7456e61c5f8Sdrh } 7466e61c5f8Sdrh }'); 7476e61c5f8Sdrh} {} 7486e61c5f8Sdrhdo_execsql_test json-12.110 { 7496e61c5f8Sdrh SELECT json_remove(x, '$.settings.layer2."dis.legomenon".forceDisplay') 7506e61c5f8Sdrh FROM t12; 7516e61c5f8Sdrh} {{{"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}}}}}} 7526e61c5f8Sdrhdo_execsql_test json-12.120 { 7536e61c5f8Sdrh SELECT json_extract(x, '$.settings.layer2."tris.legomenon"."summary.report"') 7546e61c5f8Sdrh FROM t12; 7556e61c5f8Sdrh} {0} 7566e61c5f8Sdrh 75733f763d1Sdrh# 2018-01-26 75833f763d1Sdrh# ticket https://www.sqlite.org/src/tktview/80177f0c226ff54f6ddd41 75933f763d1Sdrh# Make sure the query planner knows about the arguments to table-valued functions. 76033f763d1Sdrh# 76133f763d1Sdrhdo_execsql_test json-13.100 { 76233f763d1Sdrh DROP TABLE IF EXISTS t1; 76333f763d1Sdrh DROP TABLE IF EXISTS t2; 76433f763d1Sdrh CREATE TABLE t1(id, json); 76533f763d1Sdrh INSERT INTO t1(id,json) VALUES(1,'{"items":[3,5]}'); 76633f763d1Sdrh CREATE TABLE t2(id, json); 76733f763d1Sdrh INSERT INTO t2(id,json) VALUES(2,'{"value":2}'); 76833f763d1Sdrh INSERT INTO t2(id,json) VALUES(3,'{"value":3}'); 76933f763d1Sdrh INSERT INTO t2(id,json) VALUES(4,'{"value":4}'); 77033f763d1Sdrh INSERT INTO t2(id,json) VALUES(5,'{"value":5}'); 77133f763d1Sdrh INSERT INTO t2(id,json) VALUES(6,'{"value":6}'); 77233f763d1Sdrh SELECT * FROM t1 CROSS JOIN t2 77333f763d1Sdrh WHERE EXISTS(SELECT 1 FROM json_each(t1.json,'$.items') AS Z 77433f763d1Sdrh WHERE Z.value==t2.id); 77533f763d1Sdrh} {1 {{"items":[3,5]}} 3 {{"value":3}} 1 {{"items":[3,5]}} 5 {{"value":5}}} 77633f763d1Sdrhdo_execsql_test json-13.110 { 77733f763d1Sdrh SELECT * FROM t2 CROSS JOIN t1 77833f763d1Sdrh WHERE EXISTS(SELECT 1 FROM json_each(t1.json,'$.items') AS Z 77933f763d1Sdrh WHERE Z.value==t2.id); 78033f763d1Sdrh} {3 {{"value":3}} 1 {{"items":[3,5]}} 5 {{"value":5}} 1 {{"items":[3,5]}}} 7816e61c5f8Sdrh 782dd7460f0Sdrh# 2018-05-16 783dd7460f0Sdrh# Incorrect fullkey output from json_each() 784dd7460f0Sdrh# when the input JSON is not an array or object. 785dd7460f0Sdrh# 786dd7460f0Sdrhdo_execsql_test json-14.100 { 787dd7460f0Sdrh SELECT fullkey FROM json_each('123'); 788dd7460f0Sdrh} {$} 789dd7460f0Sdrhdo_execsql_test json-14.110 { 790dd7460f0Sdrh SELECT fullkey FROM json_each('123.56'); 791dd7460f0Sdrh} {$} 792dd7460f0Sdrhdo_execsql_test json-14.120 { 793dd7460f0Sdrh SELECT fullkey FROM json_each('"hello"'); 794dd7460f0Sdrh} {$} 795dd7460f0Sdrhdo_execsql_test json-14.130 { 796dd7460f0Sdrh SELECT fullkey FROM json_each('null'); 797dd7460f0Sdrh} {$} 798dd7460f0Sdrhdo_execsql_test json-14.140 { 799dd7460f0Sdrh SELECT fullkey FROM json_tree('123'); 800dd7460f0Sdrh} {$} 801dd7460f0Sdrhdo_execsql_test json-14.150 { 802dd7460f0Sdrh SELECT fullkey FROM json_tree('123.56'); 803dd7460f0Sdrh} {$} 804dd7460f0Sdrhdo_execsql_test json-14.160 { 805dd7460f0Sdrh SELECT fullkey FROM json_tree('"hello"'); 806dd7460f0Sdrh} {$} 807dd7460f0Sdrhdo_execsql_test json-14.170 { 808dd7460f0Sdrh SELECT fullkey FROM json_tree('null'); 809dd7460f0Sdrh} {$} 810dd7460f0Sdrh 8114a5cff73Sdrh# 2018-12-03 8124a5cff73Sdrh# Make sure the table-valued functions contained within parentheses 8134a5cff73Sdrh# work correctly. 8144a5cff73Sdrh# 8154a5cff73Sdrh# Bug reported via private email. See TH3 for more information. 8164a5cff73Sdrh# 8174a5cff73Sdrhdo_execsql_test json-15.100 { 8184a5cff73Sdrh SELECT * FROM JSON_EACH('{"a":1, "b":2}'); 8194a5cff73Sdrh} {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}} 8204a5cff73Sdrhdo_execsql_test json-15.110 { 8214a5cff73Sdrh SELECT xyz.* FROM JSON_EACH('{"a":1, "b":2}') AS xyz; 8224a5cff73Sdrh} {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}} 8234a5cff73Sdrhdo_execsql_test json-15.120 { 8244a5cff73Sdrh SELECT * FROM (JSON_EACH('{"a":1, "b":2}')); 8254a5cff73Sdrh} {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}} 8264a5cff73Sdrhdo_execsql_test json-15.130 { 8274a5cff73Sdrh SELECT xyz.* FROM (JSON_EACH('{"a":1, "b":2}')) AS xyz; 8284a5cff73Sdrh} {a 1 integer 1 2 {} {$.a} {$} b 2 integer 2 4 {} {$.b} {$}} 8296e61c5f8Sdrh 83048eb03bdSdrh# 2019-11-10 83148eb03bdSdrh# Mailing list bug report on the handling of surrogate pairs 83248eb03bdSdrh# in JSON. 83348eb03bdSdrh# 83448eb03bdSdrhdo_execsql_test json-16.10 { 83548eb03bdSdrh SELECT length(json_extract('"abc\uD834\uDD1Exyz"','$')); 83648eb03bdSdrh} {7} 83748eb03bdSdrhdo_execsql_test json-16.20 { 83848eb03bdSdrh SELECT length(json_extract('"\uD834\uDD1E"','$')); 83948eb03bdSdrh} {1} 84048eb03bdSdrhdo_execsql_test json-16.30 { 84148eb03bdSdrh SELECT unicode(json_extract('"\uD834\uDD1E"','$')); 84248eb03bdSdrh} {119070} 84348eb03bdSdrh 844ddd166a3Sdrh# 2022-01-30 dbsqlfuzz 4678cf825d27f87c9b8343720121e12cf944b71a 845ddd166a3Sdrhdo_execsql_test json-17.1 { 846ddd166a3Sdrh DROP TABLE IF EXISTS t1; 847ddd166a3Sdrh DROP TABLE IF EXISTS t2; 848ddd166a3Sdrh CREATE TABLE t1(a,b,c); 849ddd166a3Sdrh CREATE TABLE t2(d); 850ddd166a3Sdrh SELECT * FROM t1 LEFT JOIN t2 ON (SELECT b FROM json_each ORDER BY 1); 851ddd166a3Sdrh} {} 85248eb03bdSdrh 853b07fb4f1Sdrh# 2022-04-04 forum post https://sqlite.org/forum/forumpost/c082aeab43 854b07fb4f1Sdrhdo_execsql_test json-18.1 { 855b07fb4f1Sdrh SELECT json_valid('{"":5}'); 856b07fb4f1Sdrh} {1} 857b07fb4f1Sdrhdo_execsql_test json-18.2 { 858b07fb4f1Sdrh SELECT json_extract('{"":5}', '$.""'); 859b07fb4f1Sdrh} {5} 860b07fb4f1Sdrhdo_execsql_test json-18.3 { 861b07fb4f1Sdrh SELECT json_extract('[3,{"a":4,"":[5,{"hi":6},7]},8]', '$[1].""[1].hi'); 862b07fb4f1Sdrh} {6} 863b07fb4f1Sdrhdo_execsql_test json-18.4 { 864b07fb4f1Sdrh SELECT json_extract('[3,{"a":4,"":[5,{"hi":6},7]},8]', '$[1].""[1]."hi"'); 865b07fb4f1Sdrh} {6} 866b07fb4f1Sdrhdo_catchsql_test json-18.5 { 867b07fb4f1Sdrh SELECT json_extract('{"":8}', '$.'); 868b07fb4f1Sdrh} {1 {JSON path error near ''}} 869b07fb4f1Sdrh 870*4d288308Sdrh# 2022-08-29 https://sqlite.org/forum/forumpost/9b9e4716c0d7bbd1 871*4d288308Sdrh# This is not a problem specifically with JSON functions. It is 872*4d288308Sdrh# a problem with transaction control. But the json() function makes 873*4d288308Sdrh# the problem more easily accessible, so it is tested here. 874*4d288308Sdrh# 875*4d288308Sdrhdo_execsql_test json-19.1 { 876*4d288308Sdrh DROP TABLE IF EXISTS t1; 877*4d288308Sdrh CREATE TABLE t1(x); 878*4d288308Sdrh} {} 879*4d288308Sdrhdo_catchsql_test json-19.2 { 880*4d288308Sdrh BEGIN; 881*4d288308Sdrh INSERT INTO t1 VALUES(0), (json('not-valid-json')); 882*4d288308Sdrh} {1 {malformed JSON}} 883*4d288308Sdrhdo_execsql_test json-19.3 { 884*4d288308Sdrh COMMIT; 885*4d288308Sdrh SELECT * FROM t1; 886*4d288308Sdrh} {} 887*4d288308Sdrh 8886fd5c1e0Sdrhfinish_test 889