interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / jsonb01.test

64 lines · 2190 bytes Raw Blame History
1# 2023-11-15
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# Test cases for JSONB
12#
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16
17do_execsql_test jsonb01-1.1 {
18 CREATE TABLE t1(x JSON BLOB);
19 INSERT INTO t1 VALUES(jsonb('{a:5,b:{x:10,y:11},c:[1,2,3,4]}'));
20}
21foreach {id path res} {
22 1 {$.a} {{{"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
23 2 {$.b} {{{"a":5,"c":[1,2,3,4]}}}
24 3 {$.c} {{{"a":5,"b":{"x":10,"y":11}}}}
25 4 {$.d} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
26 5 {$.b.x} {{{"a":5,"b":{"y":11},"c":[1,2,3,4]}}}
27 6 {$.b.y} {{{"a":5,"b":{"x":10},"c":[1,2,3,4]}}}
28 7 {$.c[0]} {{{"a":5,"b":{"x":10,"y":11},"c":[2,3,4]}}}
29 8 {$.c[1]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,3,4]}}}
30 9 {$.c[2]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,4]}}}
31 10 {$.c[3]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3]}}}
32 11 {$.c[4]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
33 12 {$.c[#]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
34 13 {$.c[#-1]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3]}}}
35 14 {$.c[#-2]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,4]}}}
36 15 {$.c[#-3]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,3,4]}}}
37 16 {$.c[#-4]} {{{"a":5,"b":{"x":10,"y":11},"c":[2,3,4]}}}
38 17 {$.c[#-5]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
39 18 {$.c[#-6]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
40} {
41 do_execsql_test jsonb01-1.2.$id.1 {
42 SELECT json(jsonb_remove(x,$path)) FROM t1;
43 } $res
44 do_execsql_test jsonb01-1.2.$id.2 {
45 SELECT json_remove(x,$path) FROM t1;
46 } $res
47}
48
49do_catchsql_test jsonb01-2.0 {
50 SELECT x'8ce6ffffffff171333' -> '$';
51} {1 {malformed JSON}}
52
53# Bug 2026-07-04T04:59:19Z
54# Malformed FLOAT5 within a JSONB
55#
56do_catchsql_test jsonb01-3.0 {
57 SELECT json(x'6B37616263162d');
58} {1 {malformed JSON}}
59load_static_extension db strdup
60do_catchsql_test jsonb01-3.1 {
61 SELECT json(strdup(x'6B37616263162d'));
62} {1 {malformed JSON}}
63
64finish_test