mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
New test cases for JSONB.
FossilOrigin-Name: d624c31e5c49e1ce63b4b72caa42a61c5167866f47d842fbcfe4e826fd079d7c
This commit is contained in:
@ -111,13 +111,22 @@ do_execsql_test json101-3.2b {
|
||||
do_execsql_test json101-3.3 {
|
||||
SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
|
||||
} {text}
|
||||
do_execsql_test json101-3.3b {
|
||||
SELECT json_type(jsonb_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
|
||||
} {text}
|
||||
do_execsql_test json101-3.4 {
|
||||
SELECT json_type(json_set('{"a":1,"b":2}','$.b',json('{"x":3,"y":4}')),'$.b');
|
||||
} {object}
|
||||
do_execsql_test json101-3.4b {
|
||||
SELECT json_type(jsonb_set('{"a":1,"b":2}','$.b',jsonb('{"x":3,"y":4}')),'$.b');
|
||||
} {object}
|
||||
ifcapable vtab {
|
||||
do_execsql_test json101-3.5 {
|
||||
SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456));
|
||||
} {{$} {} | {$.x} 456 |}
|
||||
do_execsql_test json101-3.5 {
|
||||
SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456));
|
||||
} {{$} {} | {$.x} 456 |}
|
||||
do_execsql_test json101-3.5b {
|
||||
SELECT fullkey, atom, '|' FROM json_tree(jsonb_set('{}','$.x',123,'$.x',456));
|
||||
} {{$} {} | {$.x} 456 |}
|
||||
}
|
||||
|
||||
# Per rfc7159, any JSON value is allowed at the top level, and whitespace
|
||||
@ -169,6 +178,13 @@ do_execsql_test json101-4.10 {
|
||||
WHERE json_extract(x,'$')<>x
|
||||
AND json_type(x) IN ('object','array');
|
||||
} {4}
|
||||
do_execsql_test json101-4.10b {
|
||||
CREATE TABLE j1b AS SELECT jsonb(x) AS "x" FROM j1;
|
||||
SELECT count(*) FROM j1b WHERE json_type(x) IN ('object','array');
|
||||
SELECT json(x) FROM j1b
|
||||
WHERE json_extract(x,'$')<>json(x)
|
||||
AND json_type(x) IN ('object','array');
|
||||
} {4}
|
||||
|
||||
do_execsql_test json101-5.1 {
|
||||
CREATE TABLE j2(id INTEGER PRIMARY KEY, json, src);
|
||||
@ -296,11 +312,17 @@ do_execsql_test json101-5.1 {
|
||||
}
|
||||
]','https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html');
|
||||
SELECT count(*) FROM j2;
|
||||
} {3}
|
||||
CREATE TABLE j2b(id INTEGER PRIMARY KEY, json, src);
|
||||
INSERT INTO J2b(id,json,src) SELECT id, jsonb(json), src FROM j2;
|
||||
SELECT count(*) FROM j2b;
|
||||
} {3 3}
|
||||
|
||||
do_execsql_test json101-5.2 {
|
||||
SELECT id, json_valid(json), json_type(json), '|' FROM j2 ORDER BY id;
|
||||
} {1 1 object | 2 1 object | 3 1 array |}
|
||||
do_execsql_test json101-5.2b {
|
||||
SELECT id, json_valid(json), json_type(json), '|' FROM j2b ORDER BY id;
|
||||
} {1 1 object | 2 1 object | 3 1 array |}
|
||||
|
||||
ifcapable !vtab {
|
||||
finish_test
|
||||
@ -315,6 +337,12 @@ do_execsql_test json101-5.3 {
|
||||
WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
|
||||
ELSE '.'||key END);
|
||||
} {}
|
||||
do_execsql_test json101-5.3b {
|
||||
SELECT j2b.rowid, jx.rowid, fullkey, path, key
|
||||
FROM j2b, json_tree(j2b.json) AS jx
|
||||
WHERE fullkey!=(path || CASE WHEN typeof(key)=='integer' THEN '['||key||']'
|
||||
ELSE '.'||key END);
|
||||
} {}
|
||||
do_execsql_test json101-5.4 {
|
||||
SELECT j2.rowid, jx.rowid, fullkey, path, key
|
||||
FROM j2, json_each(j2.json) AS jx
|
||||
@ -409,6 +437,13 @@ do_execsql_test json101-8.1 {
|
||||
UPDATE t8 SET b=json_array(a);
|
||||
SELECT b FROM t8;
|
||||
} {{["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"]}}
|
||||
do_execsql_test json101-8.1b {
|
||||
DROP TABLE IF EXISTS t8;
|
||||
CREATE TABLE t8(a,b);
|
||||
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');
|
||||
UPDATE t8 SET b=jsonb_array(a);
|
||||
SELECT json(b) FROM t8;
|
||||
} {{["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"]}}
|
||||
do_execsql_test json101-8.2 {
|
||||
SELECT a=json_extract(b,'$[0]') FROM t8;
|
||||
} {1}
|
||||
@ -807,14 +842,23 @@ do_execsql_test json101-12.100 {
|
||||
}
|
||||
}');
|
||||
} {}
|
||||
|
||||
do_execsql_test json101-12.110 {
|
||||
SELECT json_remove(x, '$.settings.layer2."dis.legomenon".forceDisplay')
|
||||
FROM t12;
|
||||
} {{{"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}}}}}}
|
||||
do_execsql_test json101-12.110b {
|
||||
SELECT json_remove(jsonb(x), '$.settings.layer2."dis.legomenon".forceDisplay')
|
||||
FROM t12;
|
||||
} {{{"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}}}}}}
|
||||
do_execsql_test json101-12.120 {
|
||||
SELECT json_extract(x, '$.settings.layer2."tris.legomenon"."summary.report"')
|
||||
FROM t12;
|
||||
} {0}
|
||||
do_execsql_test json101-12.120b {
|
||||
SELECT json_extract(jsonb(x), '$.settings.layer2."tris.legomenon"."summary.report"')
|
||||
FROM t12;
|
||||
} {0}
|
||||
|
||||
# 2018-01-26
|
||||
# ticket https://www.sqlite.org/src/tktview/80177f0c226ff54f6ddd41
|
||||
@ -1054,8 +1098,4 @@ do_execsql_test json101-21.27 {
|
||||
SELECT json_group_object(x,y) FROM c;
|
||||
} {{{"a":1,"b":2.0,"c":null,:"three","e":"four"}}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user