17578456cSdrh# 2018-05-16 27578456cSdrh# 37578456cSdrh# The author disclaims copyright to this source code. In place of 47578456cSdrh# a legal notice, here is a blessing: 57578456cSdrh# 67578456cSdrh# May you do good and not evil. 77578456cSdrh# May you find forgiveness for yourself and forgive others. 87578456cSdrh# May you share freely, never taking more than you give. 97578456cSdrh# 107578456cSdrh#*********************************************************************** 117578456cSdrh# This file contains tests for the r-tree module, specifically the 127578456cSdrh# auxiliary column mechanism. 137578456cSdrh 147578456cSdrhif {![info exists testdir]} { 157578456cSdrh set testdir [file join [file dirname [info script]] .. .. test] 167578456cSdrh} 177578456cSdrhsource [file join [file dirname [info script]] rtree_util.tcl] 187578456cSdrhsource $testdir/tester.tcl 197578456cSdrhifcapable !rtree { finish_test ; return } 207578456cSdrh 217578456cSdrhdo_execsql_test rtreeH-100 { 227578456cSdrh CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1,+label,+other); 237578456cSdrh INSERT INTO t1(x0,x1,y0,y1,label) VALUES 247578456cSdrh (0,10,0,10,'lower-left corner'), 257578456cSdrh (0,10,90,100,'upper-left corner'), 267578456cSdrh (90,100,0,10,'lower-right corner'), 277578456cSdrh (90,100,90,100,'upper-right corner'), 287578456cSdrh (40,60,40,60,'center'), 297578456cSdrh (0,5,0,100,'left edge'), 307578456cSdrh (95,100,0,100,'right edge'), 317578456cSdrh (0,100,0,5,'bottom edge'), 327578456cSdrh (0,100,95,100,'top edge'), 337578456cSdrh (0,100,0,100,'the whole thing'), 347578456cSdrh (0,50,0,100,'left half'), 357578456cSdrh (51,100,0,100,'right half'), 367578456cSdrh (0,100,0,50,'bottom half'), 377578456cSdrh (0,100,51,100,'top half'); 387578456cSdrh} {} 397578456cSdrhdo_execsql_test rtreeH-101 { 407578456cSdrh SELECT * FROM t1_rowid ORDER BY rowid 417578456cSdrh} {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} {}} 427578456cSdrh 437578456cSdrhdo_execsql_test rtreeH-102 { 447578456cSdrh SELECT * FROM t1 WHERE rowid=5; 457578456cSdrh} {5 40.0 60.0 40.0 60.0 center {}} 46*348d7f64Sdrhdo_execsql_test rtreeH-102b { 47*348d7f64Sdrh SELECT * FROM t1 WHERE rowid=5.0; 48*348d7f64Sdrh} {5 40.0 60.0 40.0 60.0 center {}} 49*348d7f64Sdrhdo_execsql_test rtreeH-102c { 50*348d7f64Sdrh SELECT * FROM t1 WHERE rowid='5'; 51*348d7f64Sdrh} {5 40.0 60.0 40.0 60.0 center {}} 52*348d7f64Sdrhdo_execsql_test rtreeH-102d { 53*348d7f64Sdrh SELECT * FROM t1 WHERE rowid='0005'; 54*348d7f64Sdrh} {5 40.0 60.0 40.0 60.0 center {}} 55*348d7f64Sdrhdo_execsql_test rtreeH-102e { 56*348d7f64Sdrh SELECT * FROM t1 WHERE rowid='+5.0e+0'; 57*348d7f64Sdrh} {5 40.0 60.0 40.0 60.0 center {}} 587578456cSdrhdo_execsql_test rtreeH-103 { 597578456cSdrh SELECT * FROM t1 WHERE label='center'; 607578456cSdrh} {5 40.0 60.0 40.0 60.0 center {}} 617578456cSdrh 62*348d7f64Sdrhdo_execsql_test rtreeH-104 { 63*348d7f64Sdrh SELECT * FROM t1 WHERE rowid='+5.0e+0x'; 64*348d7f64Sdrh} {} 65*348d7f64Sdrhdo_execsql_test rtreeH-105 { 66*348d7f64Sdrh SELECT * FROM t1 WHERE rowid=x'35'; 67*348d7f64Sdrh} {} 68*348d7f64Sdrhdo_execsql_test rtreeH-106 { 69*348d7f64Sdrh SELECT * FROM t1 WHERE rowid=null; 70*348d7f64Sdrh} {} 71*348d7f64Sdrh 72*348d7f64Sdrh 737578456cSdrhdo_rtree_integrity_test rtreeH-110 t1 747578456cSdrh 757578456cSdrhdo_execsql_test rtreeH-120 { 767578456cSdrh SELECT label FROM t1 WHERE x1<=50 ORDER BY id 777578456cSdrh} {{lower-left corner} {upper-left corner} {left edge} {left half}} 787578456cSdrhdo_execsql_test rtreeH-121 { 797578456cSdrh SELECT label FROM t1 WHERE x1<=50 AND label NOT LIKE '%corner%' ORDER BY id 807578456cSdrh} {{left edge} {left half}} 817578456cSdrh 827578456cSdrhdo_execsql_test rtreeH-200 { 837578456cSdrh WITH RECURSIVE 847578456cSdrh c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<99), 857578456cSdrh c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<99) 867578456cSdrh INSERT INTO t1(id, x0,x1,y0,y1,label) 877578456cSdrh SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2; 887578456cSdrh} {} 897578456cSdrh 907578456cSdrhdo_execsql_test rtreeH-210 { 917578456cSdrh SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50 927578456cSdrh ORDER BY id; 937578456cSdrh} {box-48,48 box-49,48 box-48,49 box-49,49} 947578456cSdrh 957578456cSdrhdo_execsql_test rtreeH-300 { 967578456cSdrh UPDATE t1 SET label='x'||label 977578456cSdrh WHERE x0>=49 AND x1<=50 AND y0>=49 AND y1<=50; 987578456cSdrh SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50 997578456cSdrh ORDER BY id; 1007578456cSdrh} {box-48,48 box-49,48 box-48,49 xbox-49,49} 1017578456cSdrh 1027578456cSdrh 1037578456cSdrhfinish_test 104