3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The focus of this file is testing the r-tree extension.
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
18 source [file join [file dirname [info script]] rtree_util.tcl]
19 source $testdir/tester.tcl
24 # rtree-1.*: Creating/destroying r-tree tables.
25 # rtree-2.*: Test the implicit constraints - unique rowid and
26 # (coord[N]<=coord[N+1]) for even values of N. Also
27 # automatic assigning of rowid values.
28 # rtree-3.*: Linear scans of r-tree data.
29 # rtree-4.*: Test INSERT
30 # rtree-5.*: Test DELETE
31 # rtree-6.*: Test UPDATE
32 # rtree-7.*: Test renaming an r-tree table.
33 # rtree-8.*: Test constrained scans of r-tree data.
35 # rtree-12.*: Test that on-conflict clauses are supported.
36 # rtree-13.*: Test that bug [d2889096e7bdeac6d] has been fixed.
37 # rtree-14.*: Test if a non-integer is inserted into the PK column of an
38 # r-tree table, it is converted to an integer before being
39 # inserted. Also that if a non-numeric is inserted into one
40 # of the min/max dimension columns, it is converted to the
41 # required type before being inserted.
42 # rtree-15.*: Check that DROP TABLE works within a transaction that
43 # writes to an r-tree table.
51 #----------------------------------------------------------------------------
52 # Test cases rtree-1.* test CREATE and DROP table statements.
55 # Test creating and dropping an rtree table.
58 execsql { CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2) }
60 do_test rtree-1.1.2a {
61 execsql { SELECT name FROM sqlite_master ORDER BY name }
62 } {t1 t1_node t1_parent t1_rowid}
63 do_execsql_test rtree-1.1.2b {
64 SELECT name FROM pragma_table_list WHERE type='shadow' ORDER BY name;
65 } {t1_node t1_parent t1_rowid}
69 SELECT name FROM sqlite_master ORDER BY name;
73 # Test creating and dropping an rtree table with an odd name in
74 # an attached database.
77 file delete -force test2.db
79 ATTACH 'test2.db' AS aux;
80 CREATE VIRTUAL TABLE aux.'a" "b' USING rtree(ii, x1, x2, y1, y2);
84 execsql { SELECT name FROM sqlite_master ORDER BY name }
87 execsql { SELECT name FROM aux.sqlite_master ORDER BY name }
88 } {{a" "b} {a" "b_node} {a" "b_parent} {a" "b_rowid}}
91 DROP TABLE aux.'a" "b';
92 SELECT name FROM aux.sqlite_master ORDER BY name;
96 # Test that the logic for checking the number of columns specified
97 # for an rtree table. Acceptable values are odd numbers between 3 and
100 set cols [list i1 i2 i3 i4 i5 i6 i7 i8 i9 iA iB iC iD iE iF iG iH iI iJ iK]
101 for {set nCol 1} {$nCol<[llength $cols]} {incr nCol} {
103 set columns [join [lrange $cols 0 [expr {$nCol-1}]] ,]
106 if {$nCol%2 == 0} { set X {1 {Wrong number of columns for an rtree table}} }
107 if {$nCol < 3} { set X {1 {Too few columns for an rtree table}} }
108 if {$nCol > 11} { set X {1 {Too many columns for an rtree table}} }
110 do_test rtree-1.3.$nCol {
112 CREATE VIRTUAL TABLE t1 USING rtree($columns);
116 catchsql { DROP TABLE t1 }
118 do_catchsql_test rtree-1.3.1000 {
119 CREATE VIRTUAL TABLE t1000 USING rtree;
120 } {1 {Too few columns for an rtree table}}
122 # Like execsql except display output as integer where that can be
123 # done without loss of information.
125 proc execsql_intout {sql} {
127 foreach term [execsql $sql] {
128 regsub {\.0$} $term {} term
134 # Test that it is possible to open an existing database that contains
137 do_execsql_test rtree-1.4.1a {
138 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2);
139 INSERT INTO t1 VALUES(1, 5.0, 10.0);
140 SELECT substr(hex(data),1,40) FROM t1_node;
141 } {00000001000000000000000140A0000041200000}
142 do_execsql_test rtree-1.4.1b {
143 INSERT INTO t1 VALUES(2, 15.0, 20.0);
145 do_test rtree-1.4.2 {
148 execsql_intout { SELECT * FROM t1 ORDER BY ii }
150 do_test rtree-1.4.3 {
151 execsql { DROP TABLE t1 }
154 # Test that it is possible to create an r-tree table with ridiculous
157 do_test rtree-1.5.1 {
159 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim");
160 INSERT INTO t1 VALUES(1, 2, 3);
161 SELECT "the key", "x dim.", "x2'dim" FROM t1;
164 do_test rtree-1.5.1 {
165 execsql { DROP TABLE t1 }
168 # Force the r-tree constructor to fail.
170 do_test rtree-1.6.1 {
171 execsql { CREATE TABLE t1_rowid(a); }
173 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim");
175 } {1 {table "t1_rowid" already exists}}
176 do_test rtree-1.6.1 {
177 execsql { DROP TABLE t1_rowid }
180 #----------------------------------------------------------------------------
181 # Test cases rtree-2.*
183 do_test rtree-2.1.1 {
185 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
190 do_test rtree-2.1.2 {
191 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
192 execsql_intout { SELECT * FROM t1 }
194 do_test rtree-2.1.3 {
195 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
196 execsql { SELECT rowid FROM t1 ORDER BY rowid }
198 do_test rtree-2.1.3 {
199 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
200 execsql { SELECT ii FROM t1 ORDER BY ii }
203 do_test rtree-2.2.1 {
204 catchsql { INSERT INTO t1 VALUES(2, 1, 3, 2, 4) }
205 } {1 {UNIQUE constraint failed: t1.ii}}
206 do_test rtree-2.2.2 {
207 catchsql { INSERT INTO t1 VALUES(4, 1, 3, 4, 2) }
208 } {1 {rtree constraint failed: t1.(y1<=y2)}}
209 do_test rtree-2.2.3 {
210 catchsql { INSERT INTO t1 VALUES(4, 3, 1, 2, 4) }
211 } {1 {rtree constraint failed: t1.(x1<=x2)}}
212 do_test rtree-2.2.4 {
213 execsql { SELECT ii FROM t1 ORDER BY ii }
217 execsql { DROP TABLE t1 }
220 #----------------------------------------------------------------------------
221 # Test cases rtree-3.* test linear scans of r-tree table data. To test
222 # this we have to insert some data into an r-tree, but that is not the
223 # focus of these tests.
225 do_test rtree-3.1.1 {
227 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
231 do_test rtree-3.1.2 {
233 INSERT INTO t1 VALUES(5, 1, 3, 2, 4);
237 do_test rtree-3.1.3 {
239 INSERT INTO t1 VALUES(6, 2, 6, 4, 8);
242 } {5 1 3 2 4 6 2 6 4 8}
244 # Test the constraint on the coordinates (c[i]<=c[i+1] where (i%2==0)):
245 do_test rtree-3.2.1 {
246 catchsql { INSERT INTO t1 VALUES(7, 2, 6, 4, 3) }
247 } {1 {rtree constraint failed: t1.(y1<=y2)}}
248 do_test rtree-3.2.2 {
249 catchsql { INSERT INTO t1 VALUES(8, 2, 6, 3, 3) }
252 #----------------------------------------------------------------------------
253 # Test cases rtree-5.* test DELETE operations.
255 do_test rtree-5.1.1 {
256 execsql { CREATE VIRTUAL TABLE t2 USING rtree(ii, x1, x2) }
258 do_test rtree-5.1.2 {
260 INSERT INTO t2 VALUES(1, 10, 20);
261 INSERT INTO t2 VALUES(2, 30, 40);
262 INSERT INTO t2 VALUES(3, 50, 60);
263 SELECT * FROM t2 ORDER BY ii;
265 } {1 10 20 2 30 40 3 50 60}
266 do_test rtree-5.1.3 {
268 DELETE FROM t2 WHERE ii=2;
269 SELECT * FROM t2 ORDER BY ii;
272 do_test rtree-5.1.4 {
274 DELETE FROM t2 WHERE ii=1;
275 SELECT * FROM t2 ORDER BY ii;
278 do_test rtree-5.1.5 {
280 DELETE FROM t2 WHERE ii=3;
281 SELECT * FROM t2 ORDER BY ii;
284 do_test rtree-5.1.6 {
285 execsql { SELECT * FROM t2_rowid }
288 #----------------------------------------------------------------------------
289 # Test cases rtree-5.* test UPDATE operations.
291 do_test rtree-6.1.1 {
292 execsql { CREATE VIRTUAL TABLE t3 USING rtree(ii, x1, x2, y1, y2) }
294 do_test rtree-6.1.2 {
296 INSERT INTO t3 VALUES(1, 2, 3, 4, 5);
301 do_test rtree-6.1.3 {
302 execsql { UPDATE t3 SET ii = 2 }
303 execsql_intout { SELECT * FROM t3 }
306 #----------------------------------------------------------------------------
307 # Test cases rtree-7.* test rename operations.
309 do_test rtree-7.1.1 {
311 CREATE VIRTUAL TABLE t4 USING rtree(ii, x1, x2, y1, y2, z1, z2);
312 INSERT INTO t4 VALUES(1, 2, 3, 4, 5, 6, 7);
315 do_test rtree-7.1.2 {
316 execsql { ALTER TABLE t4 RENAME TO t5 }
317 execsql_intout { SELECT * FROM t5 }
319 do_test rtree-7.1.3 {
322 execsql_intout { SELECT * FROM t5 }
324 do_test rtree-7.1.4 {
325 execsql { ALTER TABLE t5 RENAME TO 'raisara "one"'''}
326 execsql_intout { SELECT * FROM "raisara ""one""'" }
328 do_test rtree-7.1.5 {
329 execsql_intout { SELECT * FROM 'raisara "one"''' }
331 do_test rtree-7.1.6 {
332 execsql { ALTER TABLE "raisara ""one""'" RENAME TO "abc 123" }
333 execsql_intout { SELECT * FROM "abc 123" }
335 do_test rtree-7.1.7 {
338 execsql_intout { SELECT * FROM "abc 123" }
341 # An error midway through a rename operation.
342 do_test rtree-7.2.1 {
344 CREATE TABLE t4_node(a);
346 catchsql { ALTER TABLE "abc 123" RENAME TO t4 }
347 } {1 {SQL logic error}}
348 do_test rtree-7.2.2 {
349 execsql_intout { SELECT * FROM "abc 123" }
351 do_test rtree-7.2.3 {
354 CREATE TABLE t4_rowid(a);
356 catchsql { ALTER TABLE "abc 123" RENAME TO t4 }
357 } {1 {SQL logic error}}
358 do_test rtree-7.2.4 {
361 execsql_intout { SELECT * FROM "abc 123" }
363 do_test rtree-7.2.5 {
364 execsql { DROP TABLE t4_rowid }
365 execsql { ALTER TABLE "abc 123" RENAME TO t4 }
366 execsql_intout { SELECT * FROM t4 }
370 #----------------------------------------------------------------------------
371 # Test cases rtree-8.*
374 # Test that the function to determine if a leaf cell is part of the
376 do_test rtree-8.1.1 {
378 CREATE VIRTUAL TABLE t6 USING rtree(ii, x1, x2);
379 INSERT INTO t6 VALUES(1, 3, 7);
380 INSERT INTO t6 VALUES(2, 4, 6);
383 do_test rtree-8.1.2 { execsql { SELECT ii FROM t6 WHERE x1>2 } } {1 2}
384 do_test rtree-8.1.3 { execsql { SELECT ii FROM t6 WHERE x1>3 } } {2}
385 do_test rtree-8.1.4 { execsql { SELECT ii FROM t6 WHERE x1>4 } } {}
386 do_test rtree-8.1.5 { execsql { SELECT ii FROM t6 WHERE x1>5 } } {}
387 do_test rtree-8.1.6 { execsql { SELECT ii FROM t6 WHERE x1>''} } {}
388 do_test rtree-8.1.7 { execsql { SELECT ii FROM t6 WHERE x1>null}} {}
389 do_test rtree-8.1.8 { execsql { SELECT ii FROM t6 WHERE x1>'2'} } {1 2}
390 do_test rtree-8.1.9 { execsql { SELECT ii FROM t6 WHERE x1>'3'} } {2}
391 do_test rtree-8.2.2 { execsql { SELECT ii FROM t6 WHERE x1>=2 } } {1 2}
392 do_test rtree-8.2.3 { execsql { SELECT ii FROM t6 WHERE x1>=3 } } {1 2}
393 do_test rtree-8.2.4 { execsql { SELECT ii FROM t6 WHERE x1>=4 } } {2}
394 do_test rtree-8.2.5 { execsql { SELECT ii FROM t6 WHERE x1>=5 } } {}
395 do_test rtree-8.2.6 { execsql { SELECT ii FROM t6 WHERE x1>=''} } {}
396 do_test rtree-8.2.7 { execsql { SELECT ii FROM t6 WHERE x1>=null}} {}
397 do_test rtree-8.2.8 { execsql { SELECT ii FROM t6 WHERE x1>='4'} } {2}
398 do_test rtree-8.2.9 { execsql { SELECT ii FROM t6 WHERE x1>='5'} } {}
399 do_test rtree-8.3.2 { execsql { SELECT ii FROM t6 WHERE x1<2 } } {}
400 do_test rtree-8.3.3 { execsql { SELECT ii FROM t6 WHERE x1<3 } } {}
401 do_test rtree-8.3.4 { execsql { SELECT ii FROM t6 WHERE x1<4 } } {1}
402 do_test rtree-8.3.5 { execsql { SELECT ii FROM t6 WHERE x1<5 } } {1 2}
403 do_test rtree-8.3.6 { execsql { SELECT ii FROM t6 WHERE x1<''} } {1 2}
404 do_test rtree-8.3.7 { execsql { SELECT ii FROM t6 WHERE x1<null}} {}
405 do_test rtree-8.3.8 { execsql { SELECT ii FROM t6 WHERE x1<'3'} } {}
406 do_test rtree-8.3.9 { execsql { SELECT ii FROM t6 WHERE x1<'4'} } {1}
407 do_test rtree-8.4.2 { execsql { SELECT ii FROM t6 WHERE x1<=2 } } {}
408 do_test rtree-8.4.3 { execsql { SELECT ii FROM t6 WHERE x1<=3 } } {1}
409 do_test rtree-8.4.4 { execsql { SELECT ii FROM t6 WHERE x1<=4 } } {1 2}
410 do_test rtree-8.4.5 { execsql { SELECT ii FROM t6 WHERE x1<=5 } } {1 2}
411 do_test rtree-8.4.6 { execsql { SELECT ii FROM t6 WHERE x1<=''} } {1 2}
412 do_test rtree-8.4.7 { execsql { SELECT ii FROM t6 WHERE x1<=null}} {}
413 do_test rtree-8.5.2 { execsql { SELECT ii FROM t6 WHERE x1=2 } } {}
414 do_test rtree-8.5.3 { execsql { SELECT ii FROM t6 WHERE x1=3 } } {1}
415 do_test rtree-8.5.4 { execsql { SELECT ii FROM t6 WHERE x1=4 } } {2}
416 do_test rtree-8.5.5 { execsql { SELECT ii FROM t6 WHERE x1=5 } } {}
417 do_test rtree-8.5.6 { execsql { SELECT ii FROM t6 WHERE x1=''} } {}
418 do_test rtree-8.5.7 { execsql { SELECT ii FROM t6 WHERE x1=null}} {}
421 #----------------------------------------------------------------------------
422 # Test cases rtree-9.*
424 # Test that ticket #3549 is fixed.
427 CREATE TABLE foo (id INTEGER PRIMARY KEY);
428 CREATE VIRTUAL TABLE bar USING rtree (id, minX, maxX, minY, maxY);
429 INSERT INTO foo VALUES (null);
430 INSERT INTO foo SELECT null FROM foo;
431 INSERT INTO foo SELECT null FROM foo;
432 INSERT INTO foo SELECT null FROM foo;
433 INSERT INTO foo SELECT null FROM foo;
434 INSERT INTO foo SELECT null FROM foo;
435 INSERT INTO foo SELECT null FROM foo;
436 DELETE FROM foo WHERE id > 40;
437 INSERT INTO bar SELECT NULL, 0, 0, 0, 0 FROM foo;
441 # This used to crash.
444 SELECT count(*) FROM bar b1, bar b2, foo s1 WHERE s1.id = b1.id;
449 SELECT count(*) FROM bar b1, bar b2, foo s1
450 WHERE b1.minX <= b2.maxX AND s1.id = b1.id;
454 #-------------------------------------------------------------------------
455 # Ticket #3970: Check that the error message is meaningful when a
456 # keyword is used as a column name.
459 catchsql { CREATE VIRTUAL TABLE t7 USING rtree(index, x1, y1, x2, y2) }
460 } {1 {near "index": syntax error}}
462 #-------------------------------------------------------------------------
463 # Test last_insert_rowid().
467 CREATE VIRTUAL TABLE t8 USING rtree(idx, x1, x2, y1, y2);
468 INSERT INTO t8 VALUES(1, 1.0, 1.0, 2.0, 2.0);
469 SELECT last_insert_rowid();
474 INSERT INTO t8 VALUES(NULL, 1.0, 1.0, 2.0, 2.0);
475 SELECT last_insert_rowid();
479 #-------------------------------------------------------------------------
480 # Test on-conflict clause handling.
483 do_execsql_test 12.0.1 {
484 CREATE VIRTUAL TABLE t1 USING rtree_i32(idx, x1, x2, y1, y2);
485 INSERT INTO t1 VALUES(1, 1, 2, 3, 4);
486 SELECT substr(hex(data),1,56) FROM t1_node;
487 } {00000001000000000000000100000001000000020000000300000004}
488 do_execsql_test 12.0.2 {
489 INSERT INTO t1 VALUES(2, 2, 3, 4, 5);
490 INSERT INTO t1 VALUES(3, 3, 4, 5, 6);
492 CREATE TABLE source(idx, x1, x2, y1, y2);
493 INSERT INTO source VALUES(5, 8, 8, 8, 8);
494 INSERT INTO source VALUES(2, 7, 7, 7, 7);
497 foreach {tn sql_template testdata} {
498 1 "INSERT %CONF% INTO t1 VALUES(2, 7, 7, 7, 7)" {
499 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
500 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
501 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
502 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
503 REPLACE 0 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7}
506 2 "INSERT %CONF% INTO t1 SELECT * FROM source" {
507 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
508 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
509 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}
510 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}
511 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}
514 3 "UPDATE %CONF% t1 SET idx = 2 WHERE idx = 4" {
515 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
516 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
517 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
518 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
519 REPLACE 0 0 {1 1 2 3 4 2 4 5 6 7 3 3 4 5 6}
522 3 "UPDATE %CONF% t1 SET idx = ((idx+1)%5)+1 WHERE idx > 2" {
523 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
524 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
525 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6}
526 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6}
527 REPLACE 1 0 {1 4 5 6 7 2 2 3 4 5 5 3 4 5 6}
530 4 "INSERT %CONF% INTO t1 VALUES(2, 7, 6, 7, 7)" {
531 ROLLBACK 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
532 ABORT 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
533 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
534 FAIL 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
535 REPLACE 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
539 foreach {mode uses error data} $testdata {
540 db_restore_and_reopen
542 set sql [string map [list %CONF% "OR $mode"] $sql_template]
543 set testname "12.$tn.[string tolower $mode]"
547 INSERT INTO t1 VALUES(4, 4, 5, 6, 7);
551 set res(1) {1 {UNIQUE constraint failed: t1.idx}}
552 set res(2) {1 {rtree constraint failed: t1.(x1<=x2)}}
554 do_catchsql_test $testname.1 $sql $res($error)
555 do_test $testname.2 [list sql_uses_stmt db $sql] $uses
556 do_execsql_test $testname.3 { SELECT * FROM t1 ORDER BY idx } $data
558 do_rtree_integrity_test $testname.4 t1
563 #-------------------------------------------------------------------------
564 # Test that bug [d2889096e7bdeac6d] has been fixed.
567 do_execsql_test 13.1 {
568 CREATE VIRTUAL TABLE t9 USING rtree(id, xmin, xmax);
569 INSERT INTO t9 VALUES(1,0,0);
570 INSERT INTO t9 VALUES(2,0,0);
571 SELECT * FROM t9 WHERE id IN (1, 2);
572 } {1 0.0 0.0 2 0.0 0.0}
574 do_execsql_test 13.2 {
580 SELECT * FROM r CROSS JOIN t9 WHERE id=x;
581 } {1 1 0.0 0.0 2 2 0.0 0.0}
583 #-------------------------------------------------------------------------
584 # Test if a non-integer is inserted into the PK column of an r-tree
585 # table, it is converted to an integer before being inserted. Also
586 # that if a non-numeric is inserted into one of the min/max dimension
587 # columns, it is converted to the required type before being inserted.
589 do_execsql_test 14.1 {
590 CREATE VIRTUAL TABLE t10 USING rtree(ii, x1, x2);
593 do_execsql_test 14.2 {
594 INSERT INTO t10 VALUES(NULL, 1, 2);
595 INSERT INTO t10 VALUES(NULL, 2, 3);
596 INSERT INTO t10 VALUES('4xxx', 3, 4);
597 INSERT INTO t10 VALUES(5.0, 4, 5);
598 INSERT INTO t10 VALUES(6.4, 5, 6);
600 do_execsql_test 14.3 {
603 1 1.0 2.0 2 2.0 3.0 4 3.0 4.0 5 4.0 5.0 6 5.0 6.0
606 do_execsql_test 14.4 {
608 INSERT INTO t10 VALUES(1, 'one', 'two');
609 INSERT INTO t10 VALUES(2, '52xyz', '81...');
611 do_execsql_test 14.5 {
617 do_execsql_test 14.6 {
618 INSERT INTO t10 VALUES(0,10,20);
619 SELECT * FROM t10 WHERE ii=NULL;
621 do_execsql_test 14.7 {
622 SELECT * FROM t10 WHERE ii='xyz';
624 do_execsql_test 14.8 {
625 SELECT * FROM t10 WHERE ii='0.0';
627 do_execsql_test 14.9 {
628 SELECT * FROM t10 WHERE ii=0.0;
632 do_execsql_test 14.104 {
634 CREATE VIRTUAL TABLE t10 USING rtree_i32(ii, x1, x2);
635 INSERT INTO t10 VALUES(1, 'one', 'two');
636 INSERT INTO t10 VALUES(2, '52xyz', '81...');
637 INSERT INTO t10 VALUES(3, 42.3, 49.9);
639 do_execsql_test 14.105 {
647 #-------------------------------------------------------------------------
649 do_execsql_test 15.0 {
650 CREATE VIRTUAL TABLE rt USING rtree(id, x1,x2, y1,y2);
651 CREATE TEMP TABLE t13(a, b, c);
653 do_execsql_test 15.1 {
655 INSERT INTO rt VALUES(1,2,3,4,5);
657 do_execsql_test 15.2 {
662 # Test cases for the new auxiliary columns feature
664 do_catchsql_test 16.100 {
665 CREATE VIRTUAL TABLE t16 USING rtree(id,x0,x1,y0,+aux1,x1);
666 } {1 {Auxiliary rtree columns must be last}}
669 CREATE VIRTUAL TABLE t16 USING rtree(
670 id, x00, x01, x10, x11, x20, x21, x30, x31, x40, x41
672 for {set i 12} {$i<=100} {incr i} {
680 CREATE VIRTUAL TABLE t16b USING rtree(
681 id, x00, x01, x10, x11, x20, x21, x30, x31, x40, x41
683 for {set i 12} {$i<=101} {incr i} {
688 } {1 {Too many columns for an rtree table}}
690 do_execsql_test 16.130 {
691 DROP TABLE IF EXISTS rt1;
692 CREATE VIRTUAL TABLE rt1 USING rtree(id, x1, x2, +aux);
693 INSERT INTO rt1 VALUES(1, 1, 2, 'aux1');
694 INSERT INTO rt1 VALUES(2, 2, 3, 'aux2');
695 INSERT INTO rt1 VALUES(3, 3, 4, 'aux3');
696 INSERT INTO rt1 VALUES(4, 4, 5, 'aux4');
697 SELECT * FROM rt1 WHERE id IN (1, 2, 3, 4);
698 } {1 1.0 2.0 aux1 2 2.0 3.0 aux2 3 3.0 4.0 aux3 4 4.0 5.0 aux4}
701 do_execsql_test 17.0 {
702 CREATE VIRTUAL TABLE t1 USING rtree(id, x1 PRIMARY KEY, x2, y1, y2);
703 CREATE VIRTUAL TABLE t2 USING rtree(id, x1, x2, y1, y2 UNIQUE);
705 do_execsql_test 17.1 {
710 do_execsql_test 17.2 {
715 do_execsql_test 18.0 {
716 CREATE VIRTUAL TABLE rt0 USING rtree(c0, c1, c2);
717 INSERT INTO rt0(c0,c1,c2) VALUES(9,2,3);
718 SELECT c0 FROM rt0 WHERE rt0.c1 > '-1';
719 SELECT rt0.c1 > '-1' FROM rt0;
724 # 2020-02-28 ticket e63b4d1a65546532
726 do_execsql_test 19.0 {
727 CREATE VIRTUAL TABLE rt0 USING rtree(a,b,c);
728 INSERT INTO rt0(a,b,c) VALUES(0,0.0,0.0);
729 CREATE VIEW v0(x) AS SELECT DISTINCT rt0.b FROM rt0;
730 SELECT v0.x FROM v0, rt0;
732 do_execsql_test 19.1 {
733 SELECT v0.x FROM v0, rt0 WHERE v0.x = rt0.b;
736 # 2022-06-20 https://sqlite.org/forum/forumpost/57bdf2217d
739 do_execsql_test 20.0 {
740 CREATE VIRTUAL TABLE rt0 USING rtree(id, x0, x1);
741 CREATE TABLE t0(a INT);
742 CREATE TABLE t1(b INT);
743 INSERT INTO rt0 VALUES(0, 0, 0);
745 do_catchsql_test 20.1 {
746 SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE +x0 = 0;
747 } {1 {ON clause references tables to its right}}
748 do_catchsql_test 20.2 {
749 SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE x0 = 0;
750 } {1 {ON clause references tables to its right}}
752 do_execsql_test 20.3 {
753 SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE +x0 = 0;
755 do_execsql_test 20.4 {
756 SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE x0 = 0;
759 # 2023-05-19 https://sqlite.org/forum/forumpost/da61c4a1b5b4af19
760 # Do not omit constraints that involve equality comparisons of
761 # floating-point values.
764 do_execsql_test 21.0 {
765 CREATE VIRTUAL TABLE t1 USING rtree(id, x0, x1);
766 INSERT INTO t1 VALUES(0, 1, 9223372036854775807);
767 SELECT count(*) FROM t1 WHERE x1=9223372036854775807;
769 do_execsql_test 21.1 {
770 SELECT x1=9223372036854775807 FROM t1;
773 # 2023-05-22 https://sqlite.org/forum/forumpost/da70ee0d0d
774 # Round-off error associated with using large integer constraints on
777 if {$tcl_platform(machine)!="i686" || $tcl_platform(os)!="Linux"} {
779 do_execsql_test 22.0 {
780 CREATE VIRTUAL TABLE t1 USING rtree ( id, x0, x1 );
781 INSERT INTO t1 VALUES (123, 9223372036854775799, 9223372036854775800);
782 SELECT id FROM t1 WHERE x0 > 9223372036854775807;
784 do_execsql_test 22.1 {
785 SELECT id, x0 > 9223372036854775807 AS 'a0' FROM t1;
789 # 2023-10-14 dbsqlfuzz --sql-fuzz find. rtreecheck() should not call
790 # BEGIN/COMMIT because that causes problems with statement transactions,
791 # and it is unnecessary.
795 db eval {CREATE TABLE t1(a,b,c);}
796 catch {db eval {CREATE TABLE t2 AS SELECT rtreecheck('t1') AS y;}}
797 db eval {PRAGMA integrity_check;}