AryaWu/sqlite
0
1# 2023-11-152#3# The author disclaims copyright to this source code. In place of4# 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 JSONB12#13 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16 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 } $res44 do_execsql_test jsonb01-1.2.$id.2 {45 SELECT json_remove(x,$path) FROM t1;46 } $res47}48 49do_catchsql_test jsonb01-2.0 {50 SELECT x'8ce6ffffffff171333' -> '$';51} {1 {malformed JSON}}52 53finish_test54 