OLD | NEW |
1 # 2008 Feb 19 | 1 # 2008 Feb 19 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # The focus of this file is testing the r-tree extension. | 12 # The focus of this file is testing the r-tree extension. |
13 # | 13 # |
14 | 14 |
15 if {![info exists testdir]} { | 15 if {![info exists testdir]} { |
16 set testdir [file join [file dirname [info script]] .. .. test] | 16 set testdir [file join [file dirname [info script]] .. .. test] |
17 } | 17 } |
18 source [file join [file dirname [info script]] rtree_util.tcl] | 18 source [file join [file dirname [info script]] rtree_util.tcl] |
19 source $testdir/tester.tcl | 19 source $testdir/tester.tcl |
| 20 set testprefix rtree1 |
20 | 21 |
21 # Test plan: | 22 # Test plan: |
22 # | 23 # |
23 # rtree-1.*: Creating/destroying r-tree tables. | 24 # rtree-1.*: Creating/destroying r-tree tables. |
24 # rtree-2.*: Test the implicit constraints - unique rowid and | 25 # rtree-2.*: Test the implicit constraints - unique rowid and |
25 # (coord[N]<=coord[N+1]) for even values of N. Also | 26 # (coord[N]<=coord[N+1]) for even values of N. Also |
26 # automatic assigning of rowid values. | 27 # automatic assigning of rowid values. |
27 # rtree-3.*: Linear scans of r-tree data. | 28 # rtree-3.*: Linear scans of r-tree data. |
28 # rtree-4.*: Test INSERT | 29 # rtree-4.*: Test INSERT |
29 # rtree-5.*: Test DELETE | 30 # rtree-5.*: Test DELETE |
30 # rtree-6.*: Test UPDATE | 31 # rtree-6.*: Test UPDATE |
31 # rtree-7.*: Test renaming an r-tree table. | 32 # rtree-7.*: Test renaming an r-tree table. |
32 # rtree-8.*: Test constrained scans of r-tree data. | 33 # rtree-8.*: Test constrained scans of r-tree data. |
33 # | 34 # |
| 35 # rtree-12.*: Test that on-conflict clauses are supported. |
| 36 # rtree-13.*: Test that bug [d2889096e7bdeac6d] has been fixed. |
| 37 # |
34 | 38 |
35 ifcapable !rtree { | 39 ifcapable !rtree { |
36 finish_test | 40 finish_test |
37 return | 41 return |
38 } | 42 } |
39 | 43 |
40 #---------------------------------------------------------------------------- | 44 #---------------------------------------------------------------------------- |
41 # Test cases rtree-1.* test CREATE and DROP table statements. | 45 # Test cases rtree-1.* test CREATE and DROP table statements. |
42 # | 46 # |
43 | 47 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 99 |
96 do_test rtree-1.3.$nCol { | 100 do_test rtree-1.3.$nCol { |
97 catchsql " | 101 catchsql " |
98 CREATE VIRTUAL TABLE t1 USING rtree($columns); | 102 CREATE VIRTUAL TABLE t1 USING rtree($columns); |
99 " | 103 " |
100 } $X | 104 } $X |
101 | 105 |
102 catchsql { DROP TABLE t1 } | 106 catchsql { DROP TABLE t1 } |
103 } | 107 } |
104 | 108 |
| 109 # Like execsql except display output as integer where that can be |
| 110 # done without loss of information. |
| 111 # |
| 112 proc execsql_intout {sql} { |
| 113 set out {} |
| 114 foreach term [execsql $sql] { |
| 115 regsub {\.0$} $term {} term |
| 116 lappend out $term |
| 117 } |
| 118 return $out |
| 119 } |
| 120 |
105 # Test that it is possible to open an existing database that contains | 121 # Test that it is possible to open an existing database that contains |
106 # r-tree tables. | 122 # r-tree tables. |
107 # | 123 # |
108 do_test rtree-1.4.1 { | 124 do_execsql_test rtree-1.4.1a { |
109 execsql { | 125 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2); |
110 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2); | 126 INSERT INTO t1 VALUES(1, 5.0, 10.0); |
111 INSERT INTO t1 VALUES(1, 5.0, 10.0); | 127 SELECT substr(hex(data),1,40) FROM t1_node; |
112 INSERT INTO t1 VALUES(2, 15.0, 20.0); | 128 } {00000001000000000000000140A0000041200000} |
113 } | 129 do_execsql_test rtree-1.4.1b { |
| 130 INSERT INTO t1 VALUES(2, 15.0, 20.0); |
114 } {} | 131 } {} |
115 do_test rtree-1.4.2 { | 132 do_test rtree-1.4.2 { |
116 db close | 133 db close |
117 sqlite3 db test.db | 134 sqlite3 db test.db |
118 execsql { SELECT * FROM t1 ORDER BY ii } | 135 execsql_intout { SELECT * FROM t1 ORDER BY ii } |
119 } {1 5.0 10.0 2 15.0 20.0} | 136 } {1 5 10 2 15 20} |
120 do_test rtree-1.4.3 { | 137 do_test rtree-1.4.3 { |
121 execsql { DROP TABLE t1 } | 138 execsql { DROP TABLE t1 } |
122 } {} | 139 } {} |
123 | 140 |
124 # Test that it is possible to create an r-tree table with ridiculous | 141 # Test that it is possible to create an r-tree table with ridiculous |
125 # column names. | 142 # column names. |
126 # | 143 # |
127 do_test rtree-1.5.1 { | 144 do_test rtree-1.5.1 { |
128 execsql { | 145 execsql_intout { |
129 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); | 146 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); |
130 INSERT INTO t1 VALUES(1, 2, 3); | 147 INSERT INTO t1 VALUES(1, 2, 3); |
131 SELECT "the key", "x dim.", "x2'dim" FROM t1; | 148 SELECT "the key", "x dim.", "x2'dim" FROM t1; |
132 } | 149 } |
133 } {1 2.0 3.0} | 150 } {1 2 3} |
134 do_test rtree-1.5.1 { | 151 do_test rtree-1.5.1 { |
135 execsql { DROP TABLE t1 } | 152 execsql { DROP TABLE t1 } |
136 } {} | 153 } {} |
137 | 154 |
138 # Force the r-tree constructor to fail. | 155 # Force the r-tree constructor to fail. |
139 # | 156 # |
140 do_test rtree-1.6.1 { | 157 do_test rtree-1.6.1 { |
141 execsql { CREATE TABLE t1_rowid(a); } | 158 execsql { CREATE TABLE t1_rowid(a); } |
142 catchsql { | 159 catchsql { |
143 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); | 160 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); |
144 } | 161 } |
145 } {1 {table "t1_rowid" already exists}} | 162 } {1 {table "t1_rowid" already exists}} |
146 do_test rtree-1.6.1 { | 163 do_test rtree-1.6.1 { |
147 execsql { DROP TABLE t1_rowid } | 164 execsql { DROP TABLE t1_rowid } |
148 } {} | 165 } {} |
149 | 166 |
150 #---------------------------------------------------------------------------- | 167 #---------------------------------------------------------------------------- |
151 # Test cases rtree-2.* | 168 # Test cases rtree-2.* |
152 # | 169 # |
153 do_test rtree-2.1.1 { | 170 do_test rtree-2.1.1 { |
154 execsql { | 171 execsql { |
155 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); | 172 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); |
156 SELECT * FROM t1; | 173 SELECT * FROM t1; |
157 } | 174 } |
158 } {} | 175 } {} |
159 | 176 |
160 do_test rtree-2.1.2 { | 177 do_test rtree-2.1.2 { |
161 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | 178 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } |
162 execsql { SELECT * FROM t1 } | 179 execsql_intout { SELECT * FROM t1 } |
163 } {1 1.0 3.0 2.0 4.0} | 180 } {1 1 3 2 4} |
164 do_test rtree-2.1.3 { | 181 do_test rtree-2.1.3 { |
165 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | 182 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } |
166 execsql { SELECT rowid FROM t1 ORDER BY rowid } | 183 execsql { SELECT rowid FROM t1 ORDER BY rowid } |
167 } {1 2} | 184 } {1 2} |
168 do_test rtree-2.1.3 { | 185 do_test rtree-2.1.3 { |
169 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | 186 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } |
170 execsql { SELECT ii FROM t1 ORDER BY ii } | 187 execsql { SELECT ii FROM t1 ORDER BY ii } |
171 } {1 2 3} | 188 } {1 2 3} |
172 | 189 |
173 do_test rtree-2.2.1 { | 190 do_test rtree-2.2.1 { |
(...skipping 18 matching lines...) Expand all Loading... |
192 # this we have to insert some data into an r-tree, but that is not the | 209 # this we have to insert some data into an r-tree, but that is not the |
193 # focus of these tests. | 210 # focus of these tests. |
194 # | 211 # |
195 do_test rtree-3.1.1 { | 212 do_test rtree-3.1.1 { |
196 execsql { | 213 execsql { |
197 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); | 214 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); |
198 SELECT * FROM t1; | 215 SELECT * FROM t1; |
199 } | 216 } |
200 } {} | 217 } {} |
201 do_test rtree-3.1.2 { | 218 do_test rtree-3.1.2 { |
202 execsql { | 219 execsql_intout { |
203 INSERT INTO t1 VALUES(5, 1, 3, 2, 4); | 220 INSERT INTO t1 VALUES(5, 1, 3, 2, 4); |
204 SELECT * FROM t1; | 221 SELECT * FROM t1; |
205 } | 222 } |
206 } {5 1.0 3.0 2.0 4.0} | 223 } {5 1 3 2 4} |
207 do_test rtree-3.1.3 { | 224 do_test rtree-3.1.3 { |
208 execsql { | 225 execsql_intout { |
209 INSERT INTO t1 VALUES(6, 2, 6, 4, 8); | 226 INSERT INTO t1 VALUES(6, 2, 6, 4, 8); |
210 SELECT * FROM t1; | 227 SELECT * FROM t1; |
211 } | 228 } |
212 } {5 1.0 3.0 2.0 4.0 6 2.0 6.0 4.0 8.0} | 229 } {5 1 3 2 4 6 2 6 4 8} |
213 | 230 |
214 # Test the constraint on the coordinates (c[i]<=c[i+1] where (i%2==0)): | 231 # Test the constraint on the coordinates (c[i]<=c[i+1] where (i%2==0)): |
215 do_test rtree-3.2.1 { | 232 do_test rtree-3.2.1 { |
216 catchsql { INSERT INTO t1 VALUES(7, 2, 6, 4, 3) } | 233 catchsql { INSERT INTO t1 VALUES(7, 2, 6, 4, 3) } |
217 } {1 {constraint failed}} | 234 } {1 {constraint failed}} |
218 do_test rtree-3.2.2 { | 235 do_test rtree-3.2.2 { |
219 catchsql { INSERT INTO t1 VALUES(8, 2, 6, 3, 3) } | 236 catchsql { INSERT INTO t1 VALUES(8, 2, 6, 3, 3) } |
220 } {0 {}} | 237 } {0 {}} |
221 | 238 |
222 #---------------------------------------------------------------------------- | 239 #---------------------------------------------------------------------------- |
223 # Test cases rtree-5.* test DELETE operations. | 240 # Test cases rtree-5.* test DELETE operations. |
224 # | 241 # |
225 do_test rtree-5.1.1 { | 242 do_test rtree-5.1.1 { |
226 execsql { CREATE VIRTUAL TABLE t2 USING rtree(ii, x1, x2) } | 243 execsql { CREATE VIRTUAL TABLE t2 USING rtree(ii, x1, x2) } |
227 } {} | 244 } {} |
228 do_test rtree-5.1.2 { | 245 do_test rtree-5.1.2 { |
229 execsql { | 246 execsql_intout { |
230 INSERT INTO t2 VALUES(1, 10, 20); | 247 INSERT INTO t2 VALUES(1, 10, 20); |
231 INSERT INTO t2 VALUES(2, 30, 40); | 248 INSERT INTO t2 VALUES(2, 30, 40); |
232 INSERT INTO t2 VALUES(3, 50, 60); | 249 INSERT INTO t2 VALUES(3, 50, 60); |
233 SELECT * FROM t2 ORDER BY ii; | 250 SELECT * FROM t2 ORDER BY ii; |
234 } | 251 } |
235 } {1 10.0 20.0 2 30.0 40.0 3 50.0 60.0} | 252 } {1 10 20 2 30 40 3 50 60} |
236 do_test rtree-5.1.3 { | 253 do_test rtree-5.1.3 { |
237 execsql { | 254 execsql_intout { |
238 DELETE FROM t2 WHERE ii=2; | 255 DELETE FROM t2 WHERE ii=2; |
239 SELECT * FROM t2 ORDER BY ii; | 256 SELECT * FROM t2 ORDER BY ii; |
240 } | 257 } |
241 } {1 10.0 20.0 3 50.0 60.0} | 258 } {1 10 20 3 50 60} |
242 do_test rtree-5.1.4 { | 259 do_test rtree-5.1.4 { |
243 execsql { | 260 execsql_intout { |
244 DELETE FROM t2 WHERE ii=1; | 261 DELETE FROM t2 WHERE ii=1; |
245 SELECT * FROM t2 ORDER BY ii; | 262 SELECT * FROM t2 ORDER BY ii; |
246 } | 263 } |
247 } {3 50.0 60.0} | 264 } {3 50 60} |
248 do_test rtree-5.1.5 { | 265 do_test rtree-5.1.5 { |
249 execsql { | 266 execsql { |
250 DELETE FROM t2 WHERE ii=3; | 267 DELETE FROM t2 WHERE ii=3; |
251 SELECT * FROM t2 ORDER BY ii; | 268 SELECT * FROM t2 ORDER BY ii; |
252 } | 269 } |
253 } {} | 270 } {} |
254 do_test rtree-5.1.6 { | 271 do_test rtree-5.1.6 { |
255 execsql { SELECT * FROM t2_rowid } | 272 execsql { SELECT * FROM t2_rowid } |
256 } {} | 273 } {} |
257 | 274 |
258 #---------------------------------------------------------------------------- | 275 #---------------------------------------------------------------------------- |
259 # Test cases rtree-5.* test UPDATE operations. | 276 # Test cases rtree-5.* test UPDATE operations. |
260 # | 277 # |
261 do_test rtree-6.1.1 { | 278 do_test rtree-6.1.1 { |
262 execsql { CREATE VIRTUAL TABLE t3 USING rtree(ii, x1, x2, y1, y2) } | 279 execsql { CREATE VIRTUAL TABLE t3 USING rtree(ii, x1, x2, y1, y2) } |
263 } {} | 280 } {} |
264 do_test rtree-6.1.2 { | 281 do_test rtree-6.1.2 { |
265 execsql { | 282 execsql_intout { |
266 INSERT INTO t3 VALUES(1, 2, 3, 4, 5); | 283 INSERT INTO t3 VALUES(1, 2, 3, 4, 5); |
267 UPDATE t3 SET x2=5; | 284 UPDATE t3 SET x2=5; |
268 SELECT * FROM t3; | 285 SELECT * FROM t3; |
269 } | 286 } |
270 } {1 2.0 5.0 4.0 5.0} | 287 } {1 2 5 4 5} |
271 do_test rtree-6.1.3 { | 288 do_test rtree-6.1.3 { |
272 execsql { UPDATE t3 SET ii = 2 } | 289 execsql { UPDATE t3 SET ii = 2 } |
273 execsql { SELECT * FROM t3 } | 290 execsql_intout { SELECT * FROM t3 } |
274 } {2 2.0 5.0 4.0 5.0} | 291 } {2 2 5 4 5} |
275 | 292 |
276 #---------------------------------------------------------------------------- | 293 #---------------------------------------------------------------------------- |
277 # Test cases rtree-7.* test rename operations. | 294 # Test cases rtree-7.* test rename operations. |
278 # | 295 # |
279 do_test rtree-7.1.1 { | 296 do_test rtree-7.1.1 { |
280 execsql { | 297 execsql { |
281 CREATE VIRTUAL TABLE t4 USING rtree(ii, x1, x2, y1, y2, z1, z2); | 298 CREATE VIRTUAL TABLE t4 USING rtree(ii, x1, x2, y1, y2, z1, z2); |
282 INSERT INTO t4 VALUES(1, 2, 3, 4, 5, 6, 7); | 299 INSERT INTO t4 VALUES(1, 2, 3, 4, 5, 6, 7); |
283 } | 300 } |
284 } {} | 301 } {} |
285 do_test rtree-7.1.2 { | 302 do_test rtree-7.1.2 { |
286 execsql { ALTER TABLE t4 RENAME TO t5 } | 303 execsql { ALTER TABLE t4 RENAME TO t5 } |
287 execsql { SELECT * FROM t5 } | 304 execsql_intout { SELECT * FROM t5 } |
288 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 305 } {1 2 3 4 5 6 7} |
289 do_test rtree-7.1.3 { | 306 do_test rtree-7.1.3 { |
290 db close | 307 db close |
291 sqlite3 db test.db | 308 sqlite3 db test.db |
292 execsql { SELECT * FROM t5 } | 309 execsql_intout { SELECT * FROM t5 } |
293 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 310 } {1 2 3 4 5 6 7} |
294 do_test rtree-7.1.4 { | 311 do_test rtree-7.1.4 { |
295 execsql { ALTER TABLE t5 RENAME TO 'raisara "one"'''} | 312 execsql { ALTER TABLE t5 RENAME TO 'raisara "one"'''} |
296 execsql { SELECT * FROM "raisara ""one""'" } | 313 execsql_intout { SELECT * FROM "raisara ""one""'" } |
297 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 314 } {1 2 3 4 5 6 7} |
298 do_test rtree-7.1.5 { | 315 do_test rtree-7.1.5 { |
299 execsql { SELECT * FROM 'raisara "one"''' } | 316 execsql_intout { SELECT * FROM 'raisara "one"''' } |
300 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 317 } {1 2 3 4 5 6 7} |
301 do_test rtree-7.1.6 { | 318 do_test rtree-7.1.6 { |
302 execsql { ALTER TABLE "raisara ""one""'" RENAME TO "abc 123" } | 319 execsql { ALTER TABLE "raisara ""one""'" RENAME TO "abc 123" } |
303 execsql { SELECT * FROM "abc 123" } | 320 execsql_intout { SELECT * FROM "abc 123" } |
304 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 321 } {1 2 3 4 5 6 7} |
305 do_test rtree-7.1.7 { | 322 do_test rtree-7.1.7 { |
306 db close | 323 db close |
307 sqlite3 db test.db | 324 sqlite3 db test.db |
308 execsql { SELECT * FROM "abc 123" } | 325 execsql_intout { SELECT * FROM "abc 123" } |
309 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 326 } {1 2 3 4 5 6 7} |
310 | 327 |
311 # An error midway through a rename operation. | 328 # An error midway through a rename operation. |
312 do_test rtree-7.2.1 { | 329 do_test rtree-7.2.1 { |
313 execsql { | 330 execsql { |
314 CREATE TABLE t4_node(a); | 331 CREATE TABLE t4_node(a); |
315 } | 332 } |
316 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } | 333 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } |
317 } {1 {SQL logic error or missing database}} | 334 } {1 {SQL logic error or missing database}} |
318 do_test rtree-7.2.2 { | 335 do_test rtree-7.2.2 { |
319 execsql { SELECT * FROM "abc 123" } | 336 execsql_intout { SELECT * FROM "abc 123" } |
320 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 337 } {1 2 3 4 5 6 7} |
321 do_test rtree-7.2.3 { | 338 do_test rtree-7.2.3 { |
322 execsql { | 339 execsql { |
323 DROP TABLE t4_node; | 340 DROP TABLE t4_node; |
324 CREATE TABLE t4_rowid(a); | 341 CREATE TABLE t4_rowid(a); |
325 } | 342 } |
326 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } | 343 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } |
327 } {1 {SQL logic error or missing database}} | 344 } {1 {SQL logic error or missing database}} |
328 do_test rtree-7.2.4 { | 345 do_test rtree-7.2.4 { |
329 db close | 346 db close |
330 sqlite3 db test.db | 347 sqlite3 db test.db |
331 execsql { SELECT * FROM "abc 123" } | 348 execsql_intout { SELECT * FROM "abc 123" } |
332 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 349 } {1 2 3 4 5 6 7} |
333 do_test rtree-7.2.5 { | 350 do_test rtree-7.2.5 { |
334 execsql { DROP TABLE t4_rowid } | 351 execsql { DROP TABLE t4_rowid } |
335 execsql { ALTER TABLE "abc 123" RENAME TO t4 } | 352 execsql { ALTER TABLE "abc 123" RENAME TO t4 } |
336 execsql { SELECT * FROM t4 } | 353 execsql_intout { SELECT * FROM t4 } |
337 } {1 2.0 3.0 4.0 5.0 6.0 7.0} | 354 } {1 2 3 4 5 6 7} |
338 | 355 |
339 | 356 |
340 #---------------------------------------------------------------------------- | 357 #---------------------------------------------------------------------------- |
341 # Test cases rtree-8.* | 358 # Test cases rtree-8.* |
342 # | 359 # |
343 | 360 |
344 # Test that the function to determine if a leaf cell is part of the | 361 # Test that the function to determine if a leaf cell is part of the |
345 # result set works. | 362 # result set works. |
346 do_test rtree-8.1.1 { | 363 do_test rtree-8.1.1 { |
347 execsql { | 364 execsql { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 SELECT last_insert_rowid(); | 426 SELECT last_insert_rowid(); |
410 } | 427 } |
411 } {1} | 428 } {1} |
412 do_test rtree-11.2 { | 429 do_test rtree-11.2 { |
413 execsql { | 430 execsql { |
414 INSERT INTO t8 VALUES(NULL, 1.0, 1.0, 2.0, 2.0); | 431 INSERT INTO t8 VALUES(NULL, 1.0, 1.0, 2.0, 2.0); |
415 SELECT last_insert_rowid(); | 432 SELECT last_insert_rowid(); |
416 } | 433 } |
417 } {2} | 434 } {2} |
418 | 435 |
| 436 #------------------------------------------------------------------------- |
| 437 # Test on-conflict clause handling. |
| 438 # |
| 439 db_delete_and_reopen |
| 440 do_execsql_test 12.0.1 { |
| 441 CREATE VIRTUAL TABLE t1 USING rtree_i32(idx, x1, x2, y1, y2); |
| 442 INSERT INTO t1 VALUES(1, 1, 2, 3, 4); |
| 443 SELECT substr(hex(data),1,56) FROM t1_node; |
| 444 } {00000001000000000000000100000001000000020000000300000004} |
| 445 do_execsql_test 12.0.2 { |
| 446 INSERT INTO t1 VALUES(2, 2, 3, 4, 5); |
| 447 INSERT INTO t1 VALUES(3, 3, 4, 5, 6); |
| 448 |
| 449 CREATE TABLE source(idx, x1, x2, y1, y2); |
| 450 INSERT INTO source VALUES(5, 8, 8, 8, 8); |
| 451 INSERT INTO source VALUES(2, 7, 7, 7, 7); |
| 452 } |
| 453 db_save_and_close |
| 454 foreach {tn sql_template testdata} { |
| 455 1 "INSERT %CONF% INTO t1 VALUES(2, 7, 7, 7, 7)" { |
| 456 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} |
| 457 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 458 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 459 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 460 REPLACE 0 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7} |
| 461 } |
| 462 |
| 463 2 "INSERT %CONF% INTO t1 SELECT * FROM source" { |
| 464 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} |
| 465 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 466 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} |
| 467 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} |
| 468 REPLACE 1 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} |
| 469 } |
| 470 |
| 471 3 "UPDATE %CONF% t1 SET idx = 2 WHERE idx = 4" { |
| 472 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} |
| 473 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 474 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 475 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 476 REPLACE 1 0 {1 1 2 3 4 2 4 5 6 7 3 3 4 5 6} |
| 477 } |
| 478 |
| 479 3 "UPDATE %CONF% t1 SET idx = ((idx+1)%5)+1 WHERE idx > 2" { |
| 480 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} |
| 481 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 482 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6} |
| 483 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6} |
| 484 REPLACE 1 0 {1 4 5 6 7 2 2 3 4 5 5 3 4 5 6} |
| 485 } |
| 486 |
| 487 4 "INSERT %CONF% INTO t1 VALUES(2, 7, 6, 7, 7)" { |
| 488 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} |
| 489 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 490 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 491 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 492 REPLACE 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} |
| 493 } |
| 494 |
| 495 } { |
| 496 foreach {mode uses error data} $testdata { |
| 497 db_restore_and_reopen |
| 498 |
| 499 set sql [string map [list %CONF% "OR $mode"] $sql_template] |
| 500 set testname "12.$tn.[string tolower $mode]" |
| 501 |
| 502 execsql { |
| 503 BEGIN; |
| 504 INSERT INTO t1 VALUES(4, 4, 5, 6, 7); |
| 505 } |
| 506 |
| 507 set res(0) {0 {}} |
| 508 set res(1) {1 {constraint failed}} |
| 509 do_catchsql_test $testname.1 $sql $res($error) |
| 510 do_test $testname.2 [list sql_uses_stmt db $sql] $uses |
| 511 do_execsql_test $testname.3 { SELECT * FROM t1 ORDER BY idx } $data |
| 512 |
| 513 do_test $testname.4 { rtree_check db t1 } 0 |
| 514 db close |
| 515 } |
| 516 } |
| 517 |
| 518 #------------------------------------------------------------------------- |
| 519 # Test that bug [d2889096e7bdeac6d] has been fixed. |
| 520 # |
| 521 reset_db |
| 522 do_execsql_test 13.1 { |
| 523 CREATE VIRTUAL TABLE t9 USING rtree(id, xmin, xmax); |
| 524 INSERT INTO t9 VALUES(1,0,0); |
| 525 INSERT INTO t9 VALUES(2,0,0); |
| 526 SELECT * FROM t9 WHERE id IN (1, 2); |
| 527 } {1 0.0 0.0 2 0.0 0.0} |
| 528 |
| 529 do_execsql_test 13.2 { |
| 530 WITH r(x) AS ( |
| 531 SELECT 1 UNION ALL |
| 532 SELECT 2 UNION ALL |
| 533 SELECT 3 |
| 534 ) |
| 535 SELECT * FROM r CROSS JOIN t9 WHERE id=x; |
| 536 } {1 1 0.0 0.0 2 2 0.0 0.0} |
| 537 |
419 finish_test | 538 finish_test |
OLD | NEW |