aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test155
1 files changed, 155 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test b/libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test
new file mode 100644
index 0000000..98b60e6
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/descidx3.test
@@ -0,0 +1,155 @@
1# 2006 January 02
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# This file implements regression tests for SQLite library. The
12# focus of this script is descending indices.
13#
14# $Id: descidx3.test,v 1.5 2006/07/11 14:17:52 drh Exp $
15#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20ifcapable !bloblit {
21 finish_test
22 return
23}
24db eval {PRAGMA legacy_file_format=OFF}
25
26# This procedure sets the value of the file-format in file 'test.db'
27# to $newval. Also, the schema cookie is incremented.
28#
29proc set_file_format {newval} {
30 set bt [btree_open test.db 10 0]
31 btree_begin_transaction $bt
32 set meta [btree_get_meta $bt]
33 lset meta 2 $newval ;# File format
34 lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
35 eval "btree_update_meta $bt $meta"
36 btree_commit $bt
37 btree_close $bt
38}
39
40# This procedure returns the value of the file-format in file 'test.db'.
41#
42proc get_file_format {{fname test.db}} {
43 set bt [btree_open $fname 10 0]
44 set meta [btree_get_meta $bt]
45 btree_close $bt
46 lindex $meta 2
47}
48
49# Verify that the file format starts as 4.
50#
51do_test descidx3-1.1 {
52 execsql {
53 CREATE TABLE t1(i INTEGER PRIMARY KEY,a,b,c,d);
54 CREATE INDEX t1i1 ON t1(a DESC, b ASC, c DESC);
55 CREATE INDEX t1i2 ON t1(b DESC, c ASC, d DESC);
56 }
57 get_file_format
58} {4}
59
60# Put some information in the table and verify that the descending
61# index actually works.
62#
63do_test descidx3-2.1 {
64 execsql {
65 INSERT INTO t1 VALUES(1, NULL, NULL, NULL, NULL);
66 INSERT INTO t1 VALUES(2, 2, 2, 2, 2);
67 INSERT INTO t1 VALUES(3, 3, 3, 3, 3);
68 INSERT INTO t1 VALUES(4, 2.5, 2.5, 2.5, 2.5);
69 INSERT INTO t1 VALUES(5, -5, -5, -5, -5);
70 INSERT INTO t1 VALUES(6, 'six', 'six', 'six', 'six');
71 INSERT INTO t1 VALUES(7, x'77', x'77', x'77', x'77');
72 INSERT INTO t1 VALUES(8, 'eight', 'eight', 'eight', 'eight');
73 INSERT INTO t1 VALUES(9, x'7979', x'7979', x'7979', x'7979');
74 SELECT count(*) FROM t1;
75 }
76} 9
77do_test descidx3-2.2 {
78 execsql {
79 SELECT i FROM t1 ORDER BY a;
80 }
81} {1 5 2 4 3 8 6 7 9}
82do_test descidx3-2.3 {
83 execsql {
84 SELECT i FROM t1 ORDER BY a DESC;
85 }
86} {9 7 6 8 3 4 2 5 1}
87
88# The "natural" order for the index is decreasing
89do_test descidx3-2.4 {
90 execsql {
91 SELECT i FROM t1 WHERE a<=x'7979';
92 }
93} {9 7 6 8 3 4 2 5}
94do_test descidx3-2.5 {
95 execsql {
96 SELECT i FROM t1 WHERE a>-99;
97 }
98} {9 7 6 8 3 4 2 5}
99
100# Even when all values of t1.a are the same, sorting by A returns
101# the rows in reverse order because this the natural order of the
102# index.
103#
104do_test descidx3-3.1 {
105 execsql {
106 UPDATE t1 SET a=1;
107 SELECT i FROM t1 ORDER BY a;
108 }
109} {9 7 6 8 3 4 2 5 1}
110do_test descidx3-3.2 {
111 execsql {
112 SELECT i FROM t1 WHERE a=1 AND b>0 AND b<'zzz'
113 }
114} {2 4 3 8 6}
115do_test descidx3-3.3 {
116 execsql {
117 SELECT i FROM t1 WHERE b>0 AND b<'zzz'
118 }
119} {6 8 3 4 2}
120do_test descidx3-3.4 {
121 execsql {
122 SELECT i FROM t1 WHERE a=1 AND b>-9999 AND b<x'ffffffff'
123 }
124} {5 2 4 3 8 6 7 9}
125do_test descidx3-3.5 {
126 execsql {
127 SELECT i FROM t1 WHERE b>-9999 AND b<x'ffffffff'
128 }
129} {9 7 6 8 3 4 2 5}
130
131ifcapable subquery {
132 # If the subquery capability is not compiled in to the binary, then
133 # the IN(...) operator is not available. Hence these tests cannot be
134 # run.
135 do_test descidx3-4.1 {
136 execsql {
137 UPDATE t1 SET a=2 WHERE i<6;
138 SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
139 }
140 } {8 6 2 4 3}
141 do_test descidx3-4.2 {
142 execsql {
143 UPDATE t1 SET a=1;
144 SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
145 }
146 } {2 4 3 8 6}
147 do_test descidx3-4.3 {
148 execsql {
149 UPDATE t1 SET b=2;
150 SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
151 }
152 } {9 7 6 8 3 4 2 5 1}
153}
154
155finish_test