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 #***********************************************************************
11 # This file contains tests for the r-tree module, specifically the
12 # auxiliary column mechanism.
14 if {![info exists testdir]} {
15 set testdir [file join [file dirname [info script]] .. .. test]
17 source [file join [file dirname [info script]] rtree_util.tcl]
18 source $testdir/tester.tcl
19 ifcapable !rtree { finish_test ; return }
21 do_execsql_test rtreeH-100 {
22 CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1,+label,+other);
23 INSERT INTO t1(x0,x1,y0,y1,label) VALUES
24 (0,10,0,10,'lower-left corner'),
25 (0,10,90,100,'upper-left corner'),
26 (90,100,0,10,'lower-right corner'),
27 (90,100,90,100,'upper-right corner'),
28 (40,60,40,60,'center'),
29 (0,5,0,100,'left edge'),
30 (95,100,0,100,'right edge'),
31 (0,100,0,5,'bottom edge'),
32 (0,100,95,100,'top edge'),
33 (0,100,0,100,'the whole thing'),
34 (0,50,0,100,'left half'),
35 (51,100,0,100,'right half'),
36 (0,100,0,50,'bottom half'),
37 (0,100,51,100,'top half');
39 do_execsql_test rtreeH-101 {
40 SELECT * FROM t1_rowid ORDER BY rowid
41 } {1 1 {lower-left corner} {} 2 1 {upper-left corner} {} 3 1 {lower-right corner} {} 4 1 {upper-right corner} {} 5 1 center {} 6 1 {left edge} {} 7 1 {right edge} {} 8 1 {bottom edge} {} 9 1 {top edge} {} 10 1 {the whole thing} {} 11 1 {left half} {} 12 1 {right half} {} 13 1 {bottom half} {} 14 1 {top half} {}}
43 do_execsql_test rtreeH-102 {
44 SELECT * FROM t1 WHERE rowid=5;
45 } {5 40.0 60.0 40.0 60.0 center {}}
46 do_execsql_test rtreeH-102b {
47 SELECT * FROM t1 WHERE rowid=5.0;
48 } {5 40.0 60.0 40.0 60.0 center {}}
49 do_execsql_test rtreeH-102c {
50 SELECT * FROM t1 WHERE rowid='5';
51 } {5 40.0 60.0 40.0 60.0 center {}}
52 do_execsql_test rtreeH-102d {
53 SELECT * FROM t1 WHERE rowid='0005';
54 } {5 40.0 60.0 40.0 60.0 center {}}
55 do_execsql_test rtreeH-102e {
56 SELECT * FROM t1 WHERE rowid='+5.0e+0';
57 } {5 40.0 60.0 40.0 60.0 center {}}
58 do_execsql_test rtreeH-103 {
59 SELECT * FROM t1 WHERE label='center';
60 } {5 40.0 60.0 40.0 60.0 center {}}
62 do_execsql_test rtreeH-104 {
63 SELECT * FROM t1 WHERE rowid='+5.0e+0x';
65 do_execsql_test rtreeH-105 {
66 SELECT * FROM t1 WHERE rowid=x'35';
68 do_execsql_test rtreeH-106 {
69 SELECT * FROM t1 WHERE rowid=null;
73 do_rtree_integrity_test rtreeH-110 t1
75 do_execsql_test rtreeH-120 {
76 SELECT label FROM t1 WHERE x1<=50 ORDER BY id
77 } {{lower-left corner} {upper-left corner} {left edge} {left half}}
78 do_execsql_test rtreeH-121 {
79 SELECT label FROM t1 WHERE x1<=50 AND label NOT LIKE '%corner%' ORDER BY id
80 } {{left edge} {left half}}
82 do_execsql_test rtreeH-200 {
84 c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<99),
85 c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<99)
86 INSERT INTO t1(id, x0,x1,y0,y1,label)
87 SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
90 do_execsql_test rtreeH-210 {
91 SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50
93 } {box-48,48 box-49,48 box-48,49 box-49,49}
95 do_execsql_test rtreeH-300 {
96 UPDATE t1 SET label='x'||label
97 WHERE x0>=49 AND x1<=50 AND y0>=49 AND y1<=50;
98 SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50
100 } {box-48,48 box-49,48 box-48,49 xbox-49,49}