1# 2018-05-16 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 contains tests for the r-tree module, specifically the 12# auxiliary column mechanism. 13 14if {![info exists testdir]} { 15 set testdir [file join [file dirname [info script]] .. .. test] 16} 17source [file join [file dirname [info script]] rtree_util.tcl] 18source $testdir/tester.tcl 19ifcapable !rtree { finish_test ; return } 20 21do_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'); 38} {} 39do_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} {}} 42 43do_execsql_test rtreeH-102 { 44 SELECT * FROM t1 WHERE rowid=5; 45} {5 40.0 60.0 40.0 60.0 center {}} 46do_execsql_test rtreeH-102b { 47 SELECT * FROM t1 WHERE rowid=5.0; 48} {5 40.0 60.0 40.0 60.0 center {}} 49do_execsql_test rtreeH-102c { 50 SELECT * FROM t1 WHERE rowid='5'; 51} {5 40.0 60.0 40.0 60.0 center {}} 52do_execsql_test rtreeH-102d { 53 SELECT * FROM t1 WHERE rowid='0005'; 54} {5 40.0 60.0 40.0 60.0 center {}} 55do_execsql_test rtreeH-102e { 56 SELECT * FROM t1 WHERE rowid='+5.0e+0'; 57} {5 40.0 60.0 40.0 60.0 center {}} 58do_execsql_test rtreeH-103 { 59 SELECT * FROM t1 WHERE label='center'; 60} {5 40.0 60.0 40.0 60.0 center {}} 61 62do_execsql_test rtreeH-104 { 63 SELECT * FROM t1 WHERE rowid='+5.0e+0x'; 64} {} 65do_execsql_test rtreeH-105 { 66 SELECT * FROM t1 WHERE rowid=x'35'; 67} {} 68do_execsql_test rtreeH-106 { 69 SELECT * FROM t1 WHERE rowid=null; 70} {} 71 72 73do_rtree_integrity_test rtreeH-110 t1 74 75do_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}} 78do_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}} 81 82do_execsql_test rtreeH-200 { 83 WITH RECURSIVE 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; 88} {} 89 90do_execsql_test rtreeH-210 { 91 SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50 92 ORDER BY id; 93} {box-48,48 box-49,48 box-48,49 box-49,49} 94 95do_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 99 ORDER BY id; 100} {box-48,48 box-49,48 box-48,49 xbox-49,49} 101 102 103finish_test 104