add pragma page_size compatibility so it will operate on encrypted databases
[sqlcipher.git] / test / make-where7.tcl
blob706f18451c27124ff88e8d93bc6470e3ece7d63c
1 #!/usr/bin/tclsh
3 # Run this script to generate randomized test cases for the where7.test
4 # script. The output will need to be manually copied and pasted into
5 # the where7.test script.
7 puts "do_test where7-2.1 \173"
8 puts " db eval \173"
9 puts " CREATE TABLE t2(a INTEGER PRIMARY KEY,b,c,d,e,f,g);"
10 set NA 100
11 for {set a 1} {$a<=$NA} {incr a} {
12 set b [expr {$a*11}]
13 set div3 [expr {int(($a+2)/3)}]
14 set c [expr {$div3*1001}]
15 set d [expr {$a*1.001}]
16 set e [expr {$div3*100.1}]
17 set x [expr {$a%26}]
18 set f [string range {abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz} \
19 $x [expr {$x+8}]]
20 set div5 [expr {int(($a+7)/5)}]
21 set x [expr {$div5%26}]
22 set g [string range {zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba} \
23 $x [expr {$x+6}]]
24 puts " INSERT INTO t2 VALUES($a,$b,$c,$d,$e,'$f','$g');"
25 lappend fidx($f) $a
26 lappend gidx($g) $a
27 set gof($a) $g
28 set fof($a) $f
30 set expr "a=$a"
31 set term($expr) $a
32 set expr "((a BETWEEN [expr {$a-1}] AND [expr {$a+1}]) AND a!=$a)"
33 set x {}
34 if {$a>1} {set x [expr {$a-1}]}
35 if {$a<$NA} {lappend x [expr {$a+1}]}
36 set term($expr) $x
37 set expr "b=$b"
38 set term($expr) $a
39 set expr "b=[expr {$a*11+3}]"
40 set term($expr) {}
41 set expr "c=$c"
42 lappend term($expr) $a
43 set expr "(d>=$a.0 AND d<[expr {$a+1.0}] AND d NOT NULL)"
44 lappend term($expr) $a
45 set expr "f='$f'"
46 lappend term($expr) $a
47 set expr \
48 "(f GLOB '?[string range $f 1 4]*' AND f GLOB '[string range $f 0 3]*')"
49 lappend term($expr) $a
50 set expr "(g='$g' AND f GLOB '[string range $f 0 4]*')"
51 lappend term($expr) $a
53 puts " CREATE INDEX t2b ON t2(b);"
54 puts " CREATE INDEX t2c ON t2(c);"
55 puts " CREATE INDEX t2d ON t2(d);"
56 puts " CREATE INDEX t2e ON t2(e);"
57 puts " CREATE INDEX t2f ON t2(f);"
58 puts " CREATE INDEX t2g ON t2(g);"
59 puts " CREATE TABLE t3(a INTEGER PRIMARY KEY,b,c,d,e,f,g);"
60 puts " INSERT INTO t3 SELECT * FROM t2;"
61 puts " CREATE INDEX t3b ON t3(b,c);"
62 puts " CREATE INDEX t3c ON t3(c,e);"
63 puts " CREATE INDEX t3d ON t3(d,g);"
64 puts " CREATE INDEX t3e ON t3(e,f,g);"
65 puts " CREATE INDEX t3f ON t3(f,b,d,c);"
66 puts " CREATE INDEX t3g ON t3(g,f);"
68 puts " \175"
69 puts "\175 {}"
71 set term(b<0) {}
72 set term(1000000<b) {}
73 set term(c<=10) {}
74 set term(c>=[expr {int(($NA+2)/3)*1001+1}]) {}
75 set term(d<0.0) {}
76 set term(d>1e10) {}
77 set expr {e IS NULL}
78 set term($expr) {}
79 set expr {f IS NULL}
80 set term($expr) {}
81 set expr {g IS NULL}
82 set term($expr) {}
84 set NT 1000
85 set termlist [array names term]
86 set nterm [llength $termlist]
87 for {set i 2} {$i<=$NT+1} {incr i} {
88 set n [expr {int(rand()*10)+2}]
89 set w {}
90 unset -nocomplain r
91 for {set j 0} {$j<$n} {incr j} {
92 set k [expr {int(rand()*$nterm)}]
93 set t [lindex $termlist $k]
94 lappend w $t
95 foreach a $term($t) {
96 set r($a) 1
99 if {[info exists seen($w)]} {
100 incr i -1
101 continue
103 set seen($w) 1
104 set result [lsort -int [array names r]]
105 puts "do_test where7-2.$i.1 \173"
106 puts " count_steps_sort \173"
107 puts " SELECT a FROM t2"
108 set wc [join $w "\n OR "]
109 puts " WHERE $wc"
110 puts " \175"
111 puts "\175 {$result scan 0 sort 0}"
112 puts "do_test where7-2.$i.2 \173"
113 puts " count_steps_sort \173"
114 puts " SELECT a FROM t3"
115 set wc [join $w "\n OR "]
116 puts " WHERE $wc"
117 puts " \175"
118 puts "\175 {$result scan 0 sort 0}"
120 puts "finish_test"