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.
16 # $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
18 set testdir
[file dirname
$argv0]
19 source $testdir/tester.tcl
21 # Many of the boundary tests depend on a working 64-bit implementation.
22 if {![working_64bit_int
]} { finish_test
; return }
23 ifcapable
!altertable
{ finish_test
; return }
28 # Generate interesting boundary numbers
40 set x
[expr {wide
($x)}]
42 set boundarynum
([expr {$x+1}]) 1
43 set boundarynum
([expr {-($x+1)}]) 1
44 set boundarynum
([expr {-($x+2)}]) 1
45 set boundarynum
([expr {$x+$x+1}]) 1
46 set boundarynum
([expr {$x+$x+2}]) 1
48 set x
[expr {wide
(127)}]
49 for {set i
127} {$i<=9} {incr i
} {
51 set boundarynum
([expr {$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);"
121 set x
[format %08x
%08x
[expr {wide
($r)>>32}] $r]
124 puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
129 puts " CREATE INDEX t1i1 ON t1(a);"
130 puts " CREATE INDEX t1i2 ON t1(x);"
134 puts "do_test $tname-1.2 \173"
136 puts " SELECT count(*) FROM t1"
138 puts "\175 {[llength $nums1]}"
140 proc maketest
{tnum sql answer
} {
141 puts "do_test $::tname-$tnum \173"
145 puts "\175 {$answer}"
149 foreach r
[sort
$all_rowid] {
150 lappend ans
$r $t1ra($r) $t1rx($r)
152 maketest
1.3 {SELECT rowid
, a
, x FROM t1 ORDER BY
+rowid
} $ans
153 maketest
1.4 {SELECT rowid
, a
, x FROM t1 ORDER BY rowid
} $ans
156 foreach r
[reverse
[sort
$all_rowid]] {
157 lappend ans
$r $t1ra($r) $t1rx($r)
159 maketest
1.5 {SELECT rowid
, a
, x FROM t1 ORDER BY
+rowid DESC
} $ans
160 maketest
1.6 {SELECT rowid
, a
, x FROM t1 ORDER BY rowid DESC
} $ans
163 foreach a
[sort
$all_a] {
165 lappend ans
$r $a $t1rx($r)
167 maketest
1.7 {SELECT rowid
, a
, x FROM t1 ORDER BY
+a
} $ans
168 maketest
1.8 {SELECT rowid
, a
, x FROM t1 ORDER BY a
} $ans
171 foreach a
[reverse
[sort
$all_a]] {
173 lappend ans
$r $a $t1rx($r)
175 maketest
1.9 {SELECT rowid
, a
, x FROM t1 ORDER BY
+a DESC
} $ans
176 maketest
1.10 {SELECT rowid
, a
, x FROM t1 ORDER BY a DESC
} $ans
179 foreach x
[sort
$all_x] {
181 lappend ans
$r $t1ra($r) $x
183 maketest
1.11 {SELECT rowid
, a
, x FROM t1 ORDER BY
+x
} $ans
184 maketest
1.12 {SELECT rowid
, a
, x FROM t1 ORDER BY x
} $ans
187 foreach x
[reverse
[sort
$all_x]] {
189 lappend ans
$r $t1ra($r) $x
191 maketest
1.13 {SELECT rowid
, a
, x FROM t1 ORDER BY
+x DESC
} $ans
192 maketest
1.14 {SELECT rowid
, a
, x FROM t1 ORDER BY x DESC
} $ans
194 maketest
2.1 {UPDATE t1 SET rowid
=a
, a
=rowid
} {}
197 foreach r
[sort
$all_rowid] {
198 lappend ans
$r $t1ra($r) $t1rx($r)
200 maketest
2.3 {SELECT a
, rowid
, x FROM t1 ORDER BY
+a
} $ans
201 maketest
2.4 {SELECT a
, rowid
, x FROM t1 ORDER BY a
} $ans
204 foreach r
[reverse
[sort
$all_rowid]] {
205 lappend ans
$r $t1ra($r) $t1rx($r)
207 maketest
2.5 {SELECT a
, rowid
, x FROM t1 ORDER BY
+a DESC
} $ans
208 maketest
2.6 {SELECT a
, rowid
, x FROM t1 ORDER BY a DESC
} $ans
211 foreach a
[sort
$all_a] {
213 lappend ans
$r $a $t1rx($r)
215 maketest
2.7 {SELECT a
, rowid
, x FROM t1 ORDER BY
+rowid
} $ans
216 maketest
2.8 {SELECT a
, rowid
, x FROM t1 ORDER BY rowid
} $ans
219 foreach a
[reverse
[sort
$all_a]] {
221 lappend ans
$r $a $t1rx($r)
223 maketest
2.9 {SELECT a
, rowid
, x FROM t1 ORDER BY
+rowid DESC
} $ans
224 maketest
2.10 {SELECT a
, rowid
, x FROM t1 ORDER BY rowid DESC
} $ans
227 foreach x
[sort
$all_x] {
229 lappend ans
$r $t1ra($r) $x
231 maketest
2.11 {SELECT a
, rowid
, x FROM t1 ORDER BY
+x
} $ans
232 maketest
2.12 {SELECT a
, rowid
, x FROM t1 ORDER BY x
} $ans
235 foreach x
[reverse
[sort
$all_x]] {
237 lappend ans
$r $t1ra($r) $x
239 maketest
2.13 {SELECT a
, rowid
, x FROM t1 ORDER BY
+x DESC
} $ans
240 maketest
2.14 {SELECT a
, rowid
, x FROM t1 ORDER BY x DESC
} $ans
242 maketest
3.1 {UPDATE t1 SET rowid
=a
, a
=rowid
} {}
243 maketest
3.2 {ALTER TABLE t1 ADD COLUMN z
; UPDATE t1 SET z
=zeroblob
(600)} {}
246 foreach r
[sort
$all_rowid] {
247 lappend ans
$r $t1ra($r) $t1rx($r)
249 maketest
3.3 {SELECT rowid
, a
, x FROM t1 ORDER BY
+rowid
} $ans
250 maketest
3.4 {SELECT rowid
, a
, x FROM t1 ORDER BY rowid
} $ans
253 foreach r
[reverse
[sort
$all_rowid]] {
254 lappend ans
$r $t1ra($r) $t1rx($r)
256 maketest
3.5 {SELECT rowid
, a
, x FROM t1 ORDER BY
+rowid DESC
} $ans
257 maketest
3.6 {SELECT rowid
, a
, x FROM t1 ORDER BY rowid DESC
} $ans
260 foreach a
[sort
$all_a] {
262 lappend ans
$r $a $t1rx($r)
264 maketest
3.7 {SELECT rowid
, a
, x FROM t1 ORDER BY
+a
} $ans
265 maketest
3.8 {SELECT rowid
, a
, x FROM t1 ORDER BY a
} $ans
268 foreach a
[reverse
[sort
$all_a]] {
270 lappend ans
$r $a $t1rx($r)
272 maketest
3.9 {SELECT rowid
, a
, x FROM t1 ORDER BY
+a DESC
} $ans
273 maketest
3.10 {SELECT rowid
, a
, x FROM t1 ORDER BY a DESC
} $ans
276 foreach x
[sort
$all_x] {
278 lappend ans
$r $t1ra($r) $x
280 maketest
3.11 {SELECT rowid
, a
, x FROM t1 ORDER BY
+x
} $ans
281 maketest
3.12 {SELECT rowid
, a
, x FROM t1 ORDER BY x
} $ans
284 foreach x
[reverse
[sort
$all_x]] {
286 lappend ans
$r $t1ra($r) $x
288 maketest
3.13 {SELECT rowid
, a
, x FROM t1 ORDER BY
+x DESC
} $ans
289 maketest
3.14 {SELECT rowid
, a
, x FROM t1 ORDER BY x DESC
} $ans
292 maketest
4.1 {UPDATE t1 SET rowid
=a
, a
=rowid
, x
=z
, z
=x
} {}
295 foreach r
[sort
$all_rowid] {
296 lappend ans
$r $t1ra($r) $t1rx($r)
298 maketest
4.3 {SELECT a
, rowid
, z FROM t1 ORDER BY
+a
} $ans
299 maketest
4.4 {SELECT a
, rowid
, z FROM t1 ORDER BY a
} $ans
302 foreach r
[reverse
[sort
$all_rowid]] {
303 lappend ans
$r $t1ra($r) $t1rx($r)
305 maketest
4.5 {SELECT a
, rowid
, z FROM t1 ORDER BY
+a DESC
} $ans
306 maketest
4.6 {SELECT a
, rowid
, z FROM t1 ORDER BY a DESC
} $ans
309 foreach a
[sort
$all_a] {
311 lappend ans
$r $a $t1rx($r)
313 maketest
4.7 {SELECT a
, rowid
, z FROM t1 ORDER BY
+rowid
} $ans
314 maketest
4.8 {SELECT a
, rowid
, z FROM t1 ORDER BY rowid
} $ans
317 foreach a
[reverse
[sort
$all_a]] {
319 lappend ans
$r $a $t1rx($r)
321 maketest
4.9 {SELECT a
, rowid
, z FROM t1 ORDER BY
+rowid DESC
} $ans
322 maketest
4.10 {SELECT a
, rowid
, z FROM t1 ORDER BY rowid DESC
} $ans
325 foreach x
[sort
$all_x] {
327 lappend ans
$r $t1ra($r) $x
329 maketest
4.11 {SELECT a
, rowid
, z FROM t1 ORDER BY
+z
} $ans
330 maketest
4.12 {SELECT a
, rowid
, z FROM t1 ORDER BY z
} $ans
333 foreach x
[reverse
[sort
$all_x]] {
335 lappend ans
$r $t1ra($r) $x
337 maketest
4.13 {SELECT a
, rowid
, z FROM t1 ORDER BY
+z DESC
} $ans
338 maketest
4.14 {SELECT a
, rowid
, z FROM t1 ORDER BY z DESC
} $ans