1 puts {# 2008 December 11
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 implements regression tests for SQLite library.
13 # This file is automatically generated from a separate TCL script.
14 # This file seeks to exercise integer boundary values.
17 set testdir
[file dirname
$argv0]
18 source $testdir/tester.tcl
20 # Many of the boundary tests depend on a working 64-bit implementation.
21 if {![working_64bit_int
]} { finish_test
; return }
26 # Generate interesting boundary numbers
40 set x
[expr {wide
($x)}]
42 set boundarynum
([expr {wide
($x+1)}]) 1
43 set boundarynum
([expr {wide
(-($x+1))}]) 1
44 set boundarynum
([expr {wide
(-($x+2))}]) 1
45 set boundarynum
([expr {wide
($x+$x+1)}]) 1
46 set boundarynum
([expr {wide
($x+$x+2)}]) 1
48 set x
[expr {wide
(127)}]
49 for {set i
1} {$i<=9} {incr i
} {
51 set boundarynum
([expr {wide
($x+1)}]) 1
52 set x
[expr {wide
($x*128 + 127)}]
55 # Scramble the $inlist into a random order.
57 proc scramble
{inlist
} {
60 lappend y
[list [expr {rand
()}] $x]
65 lappend outlist
[lindex $x 1]
70 # A simple selection sort. Not trying to be efficient.
74 set mn
[lindex $inlist 0]
76 if {$x<$mn} {set mn
$x}
83 if {$x>$mx && (!$valid ||
$mn>$x)} {
95 # Reverse the order of a list
97 proc reverse
{inlist
} {
98 set i
[llength $inlist]
100 for {incr i
-1} {$i>=0} {incr i
-1} {
101 lappend outlist
[lindex $inlist $i]
106 set nums1
[scramble
[array names boundarynum
]]
107 set nums2
[scramble
[array names boundarynum
]]
110 puts "do_test $tname-1.1 \173"
112 puts " CREATE TABLE t1(a,x);"
118 set x
[format %016x
[expr {wide
($r)}]]
121 puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
123 puts " CREATE INDEX t1i1 ON t1(a);"
124 puts " CREATE INDEX t1i2 ON t1(x);"
128 puts "do_test $tname-1.2 \173"
130 puts " SELECT count(*) FROM t1"
134 puts "do_test $tname-1.3 \173"
136 puts " CREATE TABLE t2(r,a);"
137 puts " INSERT INTO t2 SELECT rowid, a FROM t1;"
138 puts " CREATE INDEX t2i1 ON t2(r);"
139 puts " CREATE INDEX t2i2 ON t2(a);"
140 puts " INSERT INTO t2 VALUES(9.22337303685477580800e+18,65);"
141 set t1ra
(9.22337303685477580800e+18) 65
142 set t1ar
(65) 9.22337303685477580800e+18)
143 puts " INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66);"
144 set t1ra
(-9.22337303685477580800e
+18
) 66
145 set t1ar
(66) -9.22337303685477580800e
+18
)
146 puts " SELECT count(*) FROM t2;"
151 lappend nums3
9.22337303685477580800e+18
152 lappend nums3
-9.22337303685477580800e
+18
160 if {abs
($r)<0x7FFFFFFFFFFFFFFF ||
$r==-9223372036854775808} {
163 puts "do_test $tname-2.$i.1 \173"
165 puts " SELECT t1.* FROM t1, t2 WHERE t1.rowid=$r AND t2.a=t1.a"
168 puts "do_test $tname-2.$i.2 \173"
170 puts " SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='$x'"
173 puts "do_test $tname-2.$i.3 \173"
175 puts " SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=$a"
180 foreach op
{> >= < <=} subno
{gt ge lt le
} {
182 ################################################################ 2.x.y.1
188 lappend aset
$t1ra($rx)
191 puts "do_test $tname-2.$i.$subno.1 \173"
193 puts " SELECT t2.a FROM t1 JOIN t2 USING(a)"
194 puts " WHERE t1.rowid $op $r ORDER BY t2.a"
196 puts "\175 {[sort $aset]}"
198 ################################################################ 2.x.y.2
199 puts "do_test $tname-2.$i.$subno.2 \173"
201 puts " SELECT t2.a FROM t2 NATURAL JOIN t1"
202 puts " WHERE t1.rowid $op $r ORDER BY t1.a DESC"
204 puts "\175 {[reverse [sort $aset]]}"
207 ################################################################ 2.x.y.3
210 foreach rx
[sort
$rset] {
211 lappend aset
$t1ra($rx)
213 puts "do_test $tname-2.$i.$subno.3 \173"
215 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
216 puts " WHERE t2.a=$ax"
217 puts " ORDER BY t1.rowid"
221 ################################################################ 2.x.y.4
223 foreach rx
[reverse
[sort
$rset]] {
224 lappend aset
$t1ra($rx)
226 puts "do_test $tname-2.$i.$subno.4 \173"
228 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
229 puts " WHERE t2.a=$ax"
230 puts " ORDER BY t1.rowid DESC"
234 ################################################################ 2.x.y.5
238 lappend xset
$t1rx($rx)
240 foreach x
[sort
$xset] {
242 lappend aset
$t1ra($rx)
244 puts "do_test $tname-2.$i.$subno.5 \173"
246 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
247 puts " WHERE t2.a=$ax"
252 ################################################################ 2.x.y.10
253 if {[string length
$r5]>15} continue
261 foreach rx
[sort
$rset] {
262 lappend aset
$t1ra($rx)
264 puts "do_test $tname-2.$i.$subno.10 \173"
266 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
267 puts " WHERE t2.a=$ax"
268 puts " ORDER BY t1.rowid"
272 ################################################################ 2.x.y.11
274 foreach rx
[reverse
[sort
$rset]] {
275 lappend aset
$t1ra($rx)
277 puts "do_test $tname-2.$i.$subno.11 \173"
279 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
280 puts " WHERE t2.a=$ax"
281 puts " ORDER BY t1.rowid DESC"