| 1 |
# 2008 Feb 19 |
| 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 |
# |
| 12 |
# The focus of this file is testing the r-tree extension. |
| 13 |
# |
| 14 |
|
| 15 |
if {![info exists testdir]} { |
| 16 |
set testdir [file join [file dirname [info script]] .. .. test] |
| 17 |
} |
| 18 |
source [file join [file dirname [info script]] rtree_util.tcl] |
| 19 |
source $testdir/tester.tcl |
| 20 |
|
| 21 |
ifcapable !rtree { |
| 22 |
finish_test |
| 23 |
return |
| 24 |
} |
| 25 |
|
| 26 |
set ::NROW 1000 |
| 27 |
set ::NDEL 10 |
| 28 |
set ::NSELECT 100 |
| 29 |
|
| 30 |
if {[info exists G(isquick)] && $G(isquick)} { |
| 31 |
set ::NROW 100 |
| 32 |
set ::NSELECT 10 |
| 33 |
} |
| 34 |
|
| 35 |
foreach module {rtree_i32 rtree} { |
| 36 |
if {$module=="rtree_i32"} {set etype INT} {set etype REAL} |
| 37 |
for {set nDim 1} {$nDim <= 5} {incr nDim} { |
| 38 |
|
| 39 |
do_test rtree2-$module.$nDim.1 { |
| 40 |
set cols [list] |
| 41 |
foreach c [list c0 c1 c2 c3 c4 c5 c6 c7 c8 c9] { |
| 42 |
lappend cols "$c $etype" |
| 43 |
} |
| 44 |
set cols [join [lrange $cols 0 [expr {$nDim*2-1}]] ", "] |
| 45 |
execsql " |
| 46 |
CREATE VIRTUAL TABLE t1 USING ${module}(ii, $cols); |
| 47 |
CREATE TABLE t2 (ii, $cols); |
| 48 |
" |
| 49 |
} {} |
| 50 |
|
| 51 |
do_test rtree2-$module.$nDim.2 { |
| 52 |
db transaction { |
| 53 |
for {set ii 0} {$ii < $::NROW} {incr ii} { |
| 54 |
#puts "Row $ii" |
| 55 |
set values [list] |
| 56 |
for {set jj 0} {$jj<$nDim*2} {incr jj} { |
| 57 |
lappend values [expr int(rand()*1000)] |
| 58 |
} |
| 59 |
set values [join $values ,] |
| 60 |
#puts [rtree_treedump db t1] |
| 61 |
#puts "INSERT INTO t2 VALUES($ii, $values)" |
| 62 |
set rc [catch {db eval "INSERT INTO t1 VALUES($ii, $values)"}] |
| 63 |
if {$rc} { |
| 64 |
incr ii -1 |
| 65 |
} else { |
| 66 |
db eval "INSERT INTO t2 VALUES($ii, $values)" |
| 67 |
} |
| 68 |
#if {[rtree_check db t1]} { |
| 69 |
#puts [rtree_treedump db t1] |
| 70 |
#exit |
| 71 |
#} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
set t1 [execsql {SELECT * FROM t1 ORDER BY ii}] |
| 76 |
set t2 [execsql {SELECT * FROM t2 ORDER BY ii}] |
| 77 |
set rc [expr {$t1 eq $t2}] |
| 78 |
if {$rc != 1} { |
| 79 |
puts $t1 |
| 80 |
puts $t2 |
| 81 |
} |
| 82 |
set rc |
| 83 |
} {1} |
| 84 |
|
| 85 |
do_rtree_integrity_test rtree2-$module.$nDim.3 t1 |
| 86 |
|
| 87 |
set OPS [list < > <= >= =] |
| 88 |
for {set ii 0} {$ii < $::NSELECT} {incr ii} { |
| 89 |
do_test rtree2-$module.$nDim.4.$ii.1 { |
| 90 |
set where [list] |
| 91 |
foreach look_three_dots! {. . .} { |
| 92 |
set colidx [expr int(rand()*($nDim*2+1))-1] |
| 93 |
if {$colidx<0} { |
| 94 |
set col ii |
| 95 |
} else { |
| 96 |
set col "c$colidx" |
| 97 |
} |
| 98 |
set op [lindex $OPS [expr int(rand()*[llength $OPS])]] |
| 99 |
set val [expr int(rand()*1000)] |
| 100 |
lappend where "$col $op $val" |
| 101 |
} |
| 102 |
set where [join $where " AND "] |
| 103 |
|
| 104 |
set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"] |
| 105 |
set t2 [execsql "SELECT * FROM t2 WHERE $where ORDER BY ii"] |
| 106 |
set rc [expr {$t1 eq $t2}] |
| 107 |
if {$rc != 1} { |
| 108 |
#puts $where |
| 109 |
puts $t1 |
| 110 |
puts $t2 |
| 111 |
#puts [rtree_treedump db t1] |
| 112 |
#breakpoint |
| 113 |
#set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"] |
| 114 |
#exit |
| 115 |
} |
| 116 |
set rc |
| 117 |
} {1} |
| 118 |
} |
| 119 |
|
| 120 |
for {set ii 0} {$ii < $::NROW} {incr ii $::NDEL} { |
| 121 |
#puts [rtree_treedump db t1] |
| 122 |
do_test rtree2-$module.$nDim.5.$ii.1 { |
| 123 |
execsql "DELETE FROM t2 WHERE ii <= $::ii" |
| 124 |
execsql "DELETE FROM t1 WHERE ii <= $::ii" |
| 125 |
|
| 126 |
set t1 [execsql {SELECT * FROM t1 ORDER BY ii}] |
| 127 |
set t2 [execsql {SELECT * FROM t2 ORDER BY ii}] |
| 128 |
set rc [expr {$t1 eq $t2}] |
| 129 |
if {$rc != 1} { |
| 130 |
puts $t1 |
| 131 |
puts $t2 |
| 132 |
} |
| 133 |
set rc |
| 134 |
} {1} |
| 135 |
do_rtree_integrity_test rtree2-$module.$nDim.5.$ii.2 t1 |
| 136 |
} |
| 137 |
|
| 138 |
do_test rtree2-$module.$nDim.6 { |
| 139 |
execsql { |
| 140 |
DROP TABLE t1; |
| 141 |
DROP TABLE t2; |
| 142 |
} |
| 143 |
} {} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
finish_test |