drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 1 | # 2015-08-12 |
| 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 | # This file implements tests for JSON SQL functions extension to the |
| 12 | # SQLite library. |
| 13 | # |
| 14 | # This file contains tests automatically generated from the json1 |
| 15 | # documentation. |
| 16 | # |
| 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
drh | c306e08 | 2015-10-08 23:37:00 +0000 | [diff] [blame] | 21 | ifcapable !json1 { |
| 22 | finish_test |
| 23 | return |
| 24 | } |
| 25 | |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 26 | do_execsql_test json102-100 { |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 27 | SELECT json_object('ex','[52,3.14159]'); |
| 28 | } {{{"ex":"[52,3.14159]"}}} |
| 29 | do_execsql_test json102-110 { |
| 30 | SELECT json_object('ex',json('[52,3.14159]')); |
| 31 | } {{{"ex":[52,3.14159]}}} |
| 32 | do_execsql_test json102-120 { |
| 33 | SELECT json_object('ex',json_array(52,3.14159)); |
| 34 | } {{{"ex":[52,3.14159]}}} |
| 35 | do_execsql_test json102-130 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 36 | SELECT json(' { "this" : "is", "a": [ "test" ] } '); |
| 37 | } {{{"this":"is","a":["test"]}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 38 | do_execsql_test json102-140 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 39 | SELECT json_array(1,2,'3',4); |
| 40 | } {{[1,2,"3",4]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 41 | do_execsql_test json102-150 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 42 | SELECT json_array('[1,2]'); |
| 43 | } {{["[1,2]"]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 44 | do_execsql_test json102-160 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 45 | SELECT json_array(json_array(1,2)); |
| 46 | } {{[[1,2]]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 47 | do_execsql_test json102-170 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 48 | SELECT json_array(1,null,'3','[4,5]','{"six":7.7}'); |
| 49 | } {{[1,null,"3","[4,5]","{\"six\":7.7}"]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 50 | do_execsql_test json102-180 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 51 | SELECT json_array(1,null,'3',json('[4,5]'),json('{"six":7.7}')); |
| 52 | } {{[1,null,"3",[4,5],{"six":7.7}]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 53 | do_execsql_test json102-190 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 54 | SELECT json_array_length('[1,2,3,4]'); |
| 55 | } {{4}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 56 | do_execsql_test json102-200 { |
| 57 | SELECT json_array_length('[1,2,3,4]', '$'); |
| 58 | } {{4}} |
| 59 | do_execsql_test json102-210 { |
| 60 | SELECT json_array_length('[1,2,3,4]', '$[2]'); |
| 61 | } {{0}} |
| 62 | do_execsql_test json102-220 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 63 | SELECT json_array_length('{"one":[1,2,3]}'); |
| 64 | } {{0}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 65 | do_execsql_test json102-230 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 66 | SELECT json_array_length('{"one":[1,2,3]}', '$.one'); |
| 67 | } {{3}} |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 68 | do_execsql_test json102-240 { |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 69 | SELECT json_array_length('{"one":[1,2,3]}', '$.two'); |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 70 | } {{}} |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 71 | do_execsql_test json102-250 { |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 72 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$'); |
| 73 | } {{{"a":2,"c":[4,5,{"f":7}]}}} |
| 74 | do_execsql_test json102-260 { |
| 75 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c'); |
| 76 | } {{[4,5,{"f":7}]}} |
| 77 | do_execsql_test json102-270 { |
| 78 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2]'); |
| 79 | } {{{"f":7}}} |
| 80 | do_execsql_test json102-280 { |
| 81 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2].f'); |
| 82 | } {{7}} |
| 83 | do_execsql_test json102-290 { |
| 84 | SELECT json_extract('{"a":2,"c":[4,5],"f":7}','$.c','$.a'); |
| 85 | } {{[[4,5],2]}} |
| 86 | do_execsql_test json102-300 { |
| 87 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x'); |
| 88 | } {{}} |
| 89 | do_execsql_test json102-310 { |
| 90 | SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x', '$.a'); |
| 91 | } {{[null,2]}} |
| 92 | do_execsql_test json102-320 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 93 | SELECT json_insert('{"a":2,"c":4}', '$.a', 99); |
| 94 | } {{{"a":2,"c":4}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 95 | do_execsql_test json102-330 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 96 | SELECT json_insert('{"a":2,"c":4}', '$.e', 99); |
| 97 | } {{{"a":2,"c":4,"e":99}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 98 | do_execsql_test json102-340 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 99 | SELECT json_replace('{"a":2,"c":4}', '$.a', 99); |
| 100 | } {{{"a":99,"c":4}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 101 | do_execsql_test json102-350 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 102 | SELECT json_replace('{"a":2,"c":4}', '$.e', 99); |
| 103 | } {{{"a":2,"c":4}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 104 | do_execsql_test json102-360 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 105 | SELECT json_set('{"a":2,"c":4}', '$.a', 99); |
| 106 | } {{{"a":99,"c":4}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 107 | do_execsql_test json102-370 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 108 | SELECT json_set('{"a":2,"c":4}', '$.e', 99); |
| 109 | } {{{"a":2,"c":4,"e":99}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 110 | do_execsql_test json102-380 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 111 | SELECT json_set('{"a":2,"c":4}', '$.c', '[97,96]'); |
| 112 | } {{{"a":2,"c":"[97,96]"}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 113 | do_execsql_test json102-390 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 114 | SELECT json_set('{"a":2,"c":4}', '$.c', json('[97,96]')); |
| 115 | } {{{"a":2,"c":[97,96]}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 116 | do_execsql_test json102-400 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 117 | SELECT json_set('{"a":2,"c":4}', '$.c', json_array(97,96)); |
| 118 | } {{{"a":2,"c":[97,96]}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 119 | do_execsql_test json102-410 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 120 | SELECT json_object('a',2,'c',4); |
| 121 | } {{{"a":2,"c":4}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 122 | do_execsql_test json102-420 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 123 | SELECT json_object('a',2,'c','{e:5}'); |
| 124 | } {{{"a":2,"c":"{e:5}"}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 125 | do_execsql_test json102-430 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 126 | SELECT json_object('a',2,'c',json_object('e',5)); |
| 127 | } {{{"a":2,"c":{"e":5}}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 128 | do_execsql_test json102-440 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 129 | SELECT json_remove('[0,1,2,3,4]','$[2]'); |
| 130 | } {{[0,1,3,4]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 131 | do_execsql_test json102-450 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 132 | SELECT json_remove('[0,1,2,3,4]','$[2]','$[0]'); |
| 133 | } {{[1,3,4]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 134 | do_execsql_test json102-460 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 135 | SELECT json_remove('[0,1,2,3,4]','$[0]','$[2]'); |
| 136 | } {{[1,2,4]}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 137 | do_execsql_test json102-470 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 138 | SELECT json_remove('{"x":25,"y":42}'); |
| 139 | } {{{"x":25,"y":42}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 140 | do_execsql_test json102-480 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 141 | SELECT json_remove('{"x":25,"y":42}','$.z'); |
| 142 | } {{{"x":25,"y":42}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 143 | do_execsql_test json102-490 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 144 | SELECT json_remove('{"x":25,"y":42}','$.y'); |
| 145 | } {{{"x":25}}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 146 | do_execsql_test json102-500 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 147 | SELECT json_remove('{"x":25,"y":42}','$'); |
| 148 | } {{}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 149 | do_execsql_test json102-510 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 150 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}'); |
| 151 | } {{object}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 152 | do_execsql_test json102-520 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 153 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$'); |
| 154 | } {{object}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 155 | do_execsql_test json102-530 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 156 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a'); |
| 157 | } {{array}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 158 | do_execsql_test json102-540 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 159 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[0]'); |
| 160 | } {{integer}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 161 | do_execsql_test json102-550 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 162 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[1]'); |
| 163 | } {{real}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 164 | do_execsql_test json102-560 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 165 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[2]'); |
| 166 | } {{true}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 167 | do_execsql_test json102-570 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 168 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[3]'); |
| 169 | } {{false}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 170 | do_execsql_test json102-580 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 171 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[4]'); |
| 172 | } {{null}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 173 | do_execsql_test json102-590 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 174 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[5]'); |
| 175 | } {{text}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 176 | do_execsql_test json102-600 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 177 | SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[6]'); |
| 178 | } {{}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 179 | do_execsql_test json102-610 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 180 | SELECT json_valid(char(123)||'"x":35'||char(125)); |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 181 | } {{1}} |
drh | e98b6fa | 2015-09-11 15:32:33 +0000 | [diff] [blame] | 182 | do_execsql_test json102-620 { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 183 | SELECT json_valid(char(123)||'"x":35'); |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 184 | } {{0}} |
| 185 | |
drh | e6f5278 | 2015-09-10 15:22:35 +0000 | [diff] [blame] | 186 | ifcapable vtab { |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 187 | do_execsql_test json102-1000 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 188 | CREATE TABLE user(name,phone); |
| 189 | INSERT INTO user(name,phone) VALUES |
| 190 | ('Alice','["919-555-2345","804-555-3621"]'), |
| 191 | ('Bob','["201-555-8872"]'), |
| 192 | ('Cindy','["704-555-9983"]'), |
| 193 | ('Dave','["336-555-8421","704-555-4321","803-911-4421"]'); |
| 194 | SELECT DISTINCT user.name |
| 195 | FROM user, json_each(user.phone) |
| 196 | WHERE json_each.value LIKE '704-%' |
| 197 | ORDER BY 1; |
| 198 | } {Cindy Dave} |
| 199 | |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 200 | do_execsql_test json102-1010 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 201 | UPDATE user |
| 202 | SET phone=json_extract(phone,'$[0]') |
| 203 | WHERE json_array_length(phone)<2; |
| 204 | SELECT name, substr(phone,1,5) FROM user ORDER BY name; |
| 205 | } {Alice {["919} Bob 201-5 Cindy 704-5 Dave {["336}} |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 206 | do_execsql_test json102-1011 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 207 | SELECT name FROM user WHERE phone LIKE '704-%' |
| 208 | UNION |
| 209 | SELECT user.name |
| 210 | FROM user, json_each(user.phone) |
| 211 | WHERE json_valid(user.phone) |
| 212 | AND json_each.value LIKE '704-%'; |
| 213 | } {Cindy Dave} |
| 214 | |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 215 | do_execsql_test json102-1100 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 216 | CREATE TABLE big(json JSON); |
| 217 | INSERT INTO big(json) VALUES('{ |
| 218 | "id":123, |
| 219 | "stuff":[1,2,3,4], |
| 220 | "partlist":[ |
| 221 | {"uuid":"bb108722-572e-11e5-9320-7f3b63a4ca74"}, |
| 222 | {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"}, |
| 223 | {"subassembly":[ |
| 224 | {"uuid":"6fa5181e-5721-11e5-a04e-57f3d7b32808"} |
| 225 | ]} |
| 226 | ] |
| 227 | }'); |
| 228 | INSERT INTO big(json) VALUES('{ |
| 229 | "id":456, |
| 230 | "stuff":["hello","world","xyzzy"], |
| 231 | "partlist":[ |
| 232 | {"uuid":false}, |
| 233 | {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"} |
| 234 | ] |
| 235 | }'); |
| 236 | } {} |
| 237 | set correct_answer [list \ |
| 238 | 1 {$.id} 123 \ |
| 239 | 1 {$.stuff[0]} 1 \ |
| 240 | 1 {$.stuff[1]} 2 \ |
| 241 | 1 {$.stuff[2]} 3 \ |
| 242 | 1 {$.stuff[3]} 4 \ |
| 243 | 1 {$.partlist[0].uuid} bb108722-572e-11e5-9320-7f3b63a4ca74 \ |
| 244 | 1 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535 \ |
| 245 | 1 {$.partlist[2].subassembly[0].uuid} 6fa5181e-5721-11e5-a04e-57f3d7b32808 \ |
| 246 | 2 {$.id} 456 \ |
| 247 | 2 {$.stuff[0]} hello \ |
| 248 | 2 {$.stuff[1]} world \ |
| 249 | 2 {$.stuff[2]} xyzzy \ |
| 250 | 2 {$.partlist[0].uuid} 0 \ |
| 251 | 2 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535] |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 252 | do_execsql_test json102-1110 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 253 | SELECT big.rowid, fullkey, value |
| 254 | FROM big, json_tree(big.json) |
| 255 | WHERE json_tree.type NOT IN ('object','array') |
| 256 | ORDER BY +big.rowid, +json_tree.id |
| 257 | } $correct_answer |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 258 | do_execsql_test json102-1120 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 259 | SELECT big.rowid, fullkey, atom |
| 260 | FROM big, json_tree(big.json) |
| 261 | WHERE atom IS NOT NULL |
| 262 | ORDER BY +big.rowid, +json_tree.id |
| 263 | } $correct_answer |
| 264 | |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 265 | do_execsql_test json102-1130 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 266 | SELECT DISTINCT json_extract(big.json,'$.id') |
| 267 | FROM big, json_tree(big.json,'$.partlist') |
| 268 | WHERE json_tree.key='uuid' |
| 269 | AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808'; |
| 270 | } {123} |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 271 | do_execsql_test json102-1131 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 272 | SELECT DISTINCT json_extract(big.json,'$.id') |
| 273 | FROM big, json_tree(big.json,'$') |
| 274 | WHERE json_tree.key='uuid' |
| 275 | AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808'; |
| 276 | } {123} |
drh | 12b3b89 | 2015-09-11 01:22:41 +0000 | [diff] [blame] | 277 | do_execsql_test json102-1132 { |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 278 | SELECT DISTINCT json_extract(big.json,'$.id') |
| 279 | FROM big, json_tree(big.json) |
| 280 | WHERE json_tree.key='uuid' |
| 281 | AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808'; |
| 282 | } {123} |
drh | e6f5278 | 2015-09-10 15:22:35 +0000 | [diff] [blame] | 283 | } ;# end ifcapable vtab |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 284 | |
dan | 2e8f551 | 2015-09-17 17:21:09 +0000 | [diff] [blame] | 285 | #------------------------------------------------------------------------- |
| 286 | # Test that json_valid() correctly identifies non-ascii range |
| 287 | # characters as non-whitespace. |
| 288 | # |
| 289 | do_execsql_test json102-1201 { SELECT json_valid(char(32) || '"xyz"') } 1 |
| 290 | do_execsql_test json102-1202 { SELECT json_valid(char(200) || '"xyz"') } 0 |
| 291 | |
drh | 4977ccf | 2015-09-19 11:57:26 +0000 | [diff] [blame] | 292 | # Off-by-one error in jsonAppendString() |
| 293 | # |
| 294 | for {set i 0} {$i<100} {incr i} { |
| 295 | set str abcdef[string repeat \" [expr {$i+50}]]uvwxyz |
| 296 | do_test json102-[format %d [expr {$i+1300}]] { |
| 297 | db eval {SELECT json_extract(json_array($::str),'$[0]')==$::str} |
| 298 | } {1} |
| 299 | } |
| 300 | |
drh | 9fa866a | 2017-04-08 18:18:22 +0000 | [diff] [blame] | 301 | #------------------------------------------------------------------------- |
| 302 | # 2017-04-08 ticket b93be8729a895a528e2849fca99f7 |
| 303 | # JSON extension accepts invalid numeric values |
| 304 | # |
| 305 | # JSON does not allow leading zeros. But the JSON extension was |
| 306 | # allowing them. The following tests verify that the problem is now |
| 307 | # fixed. |
| 308 | # |
| 309 | do_execsql_test json102-1401 { SELECT json_valid('{"x":01}') } 0 |
| 310 | do_execsql_test json102-1402 { SELECT json_valid('{"x":-01}') } 0 |
| 311 | do_execsql_test json102-1403 { SELECT json_valid('{"x":0}') } 1 |
| 312 | do_execsql_test json102-1404 { SELECT json_valid('{"x":-0}') } 1 |
| 313 | do_execsql_test json102-1405 { SELECT json_valid('{"x":0.1}') } 1 |
| 314 | do_execsql_test json102-1406 { SELECT json_valid('{"x":-0.1}') } 1 |
| 315 | do_execsql_test json102-1407 { SELECT json_valid('{"x":0.0000}') } 1 |
| 316 | do_execsql_test json102-1408 { SELECT json_valid('{"x":-0.0000}') } 1 |
| 317 | do_execsql_test json102-1409 { SELECT json_valid('{"x":01.5}') } 0 |
| 318 | do_execsql_test json102-1410 { SELECT json_valid('{"x":-01.5}') } 0 |
| 319 | do_execsql_test json102-1411 { SELECT json_valid('{"x":00}') } 0 |
| 320 | do_execsql_test json102-1412 { SELECT json_valid('{"x":-00}') } 0 |
| 321 | |
drh | e12e24d | 2017-04-10 12:25:05 +0000 | [diff] [blame] | 322 | #------------------------------------------------------------------------ |
| 323 | # 2017-04-10 ticket 6c9b5514077fed34551f98e64c09a10dc2fc8e16 |
| 324 | # JSON extension accepts strings containing control characters. |
| 325 | # |
| 326 | # The JSON spec requires that all control characters be escaped. |
| 327 | # |
| 328 | do_execsql_test json102-1500 { |
| 329 | WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x20) |
| 330 | SELECT x FROM c WHERE json_valid(printf('{"a":"x%sz"}', char(x))) ORDER BY x; |
| 331 | } {32} |
| 332 | |
drh | 2ac702d | 2017-04-10 12:31:15 +0000 | [diff] [blame] | 333 | # All control characters are escaped |
| 334 | # |
| 335 | do_execsql_test json102-1501 { |
| 336 | WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x1f) |
| 337 | SELECT sum(json_valid(json_quote('a'||char(x)||'z'))) FROM c ORDER BY x; |
| 338 | } {31} |
| 339 | |
drh | 852944e | 2015-09-10 03:29:11 +0000 | [diff] [blame] | 340 | finish_test |