aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test184
1 files changed, 184 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test b/libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test
new file mode 100644
index 0000000..3c6b392
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/descidx2.test
@@ -0,0 +1,184 @@
1# 2005 December 21
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: descidx2.test,v 1.4 2006/07/11 14:17:52 drh Exp $
15#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20db eval {PRAGMA legacy_file_format=OFF}
21
22# This procedure sets the value of the file-format in file 'test.db'
23# to $newval. Also, the schema cookie is incremented.
24#
25proc set_file_format {newval} {
26 set bt [btree_open test.db 10 0]
27 btree_begin_transaction $bt
28 set meta [btree_get_meta $bt]
29 lset meta 2 $newval ;# File format
30 lset meta 1 [expr [lindex $meta 1]+1] ;# Schema cookie
31 eval "btree_update_meta $bt $meta"
32 btree_commit $bt
33 btree_close $bt
34}
35
36# This procedure returns the value of the file-format in file 'test.db'.
37#
38proc get_file_format {{fname test.db}} {
39 set bt [btree_open $fname 10 0]
40 set meta [btree_get_meta $bt]
41 btree_close $bt
42 lindex $meta 2
43}
44
45# Verify that the file format starts as 4
46#
47do_test descidx2-1.1 {
48 execsql {
49 CREATE TABLE t1(a,b);
50 CREATE INDEX i1 ON t1(b ASC);
51 }
52 get_file_format
53} {4}
54do_test descidx2-1.2 {
55 execsql {
56 CREATE INDEX i2 ON t1(a DESC);
57 }
58 get_file_format
59} {4}
60
61# Before adding any information to the database, set the file format
62# back to three. Then close and reopen the database. With the file
63# format set to three, SQLite should ignore the DESC argument on the
64# index.
65#
66do_test descidx2-2.0 {
67 set_file_format 3
68 db close
69 sqlite3 db test.db
70 get_file_format
71} {3}
72
73# Put some information in the table and verify that the DESC
74# on the index is ignored.
75#
76do_test descidx2-2.1 {
77 execsql {
78 INSERT INTO t1 VALUES(1,1);
79 INSERT INTO t1 VALUES(2,2);
80 INSERT INTO t1 SELECT a+2, a+2 FROM t1;
81 INSERT INTO t1 SELECT a+4, a+4 FROM t1;
82 SELECT b FROM t1 WHERE a>3 AND a<7;
83 }
84} {4 5 6}
85do_test descidx2-2.2 {
86 execsql {
87 SELECT a FROM t1 WHERE b>3 AND b<7;
88 }
89} {4 5 6}
90do_test descidx2-2.3 {
91 execsql {
92 SELECT b FROM t1 WHERE a>=3 AND a<7;
93 }
94} {3 4 5 6}
95do_test descidx2-2.4 {
96 execsql {
97 SELECT b FROM t1 WHERE a>3 AND a<=7;
98 }
99} {4 5 6 7}
100do_test descidx2-2.5 {
101 execsql {
102 SELECT b FROM t1 WHERE a>=3 AND a<=7;
103 }
104} {3 4 5 6 7}
105do_test descidx2-2.6 {
106 execsql {
107 SELECT a FROM t1 WHERE b>=3 AND b<=7;
108 }
109} {3 4 5 6 7}
110
111# This procedure executes the SQL. Then it checks to see if the OP_Sort
112# opcode was executed. If an OP_Sort did occur, then "sort" is appended
113# to the result. If no OP_Sort happened, then "nosort" is appended.
114#
115# This procedure is used to check to make sure sorting is or is not
116# occurring as expected.
117#
118proc cksort {sql} {
119 set ::sqlite_sort_count 0
120 set data [execsql $sql]
121 if {$::sqlite_sort_count} {set x sort} {set x nosort}
122 lappend data $x
123 return $data
124}
125
126# Test sorting using a descending index.
127#
128do_test descidx2-3.1 {
129 cksort {SELECT a FROM t1 ORDER BY a}
130} {1 2 3 4 5 6 7 8 nosort}
131do_test descidx2-3.2 {
132 cksort {SELECT a FROM t1 ORDER BY a ASC}
133} {1 2 3 4 5 6 7 8 nosort}
134do_test descidx2-3.3 {
135 cksort {SELECT a FROM t1 ORDER BY a DESC}
136} {8 7 6 5 4 3 2 1 nosort}
137do_test descidx2-3.4 {
138 cksort {SELECT b FROM t1 ORDER BY a}
139} {1 2 3 4 5 6 7 8 nosort}
140do_test descidx2-3.5 {
141 cksort {SELECT b FROM t1 ORDER BY a ASC}
142} {1 2 3 4 5 6 7 8 nosort}
143do_test descidx2-3.6 {
144 cksort {SELECT b FROM t1 ORDER BY a DESC}
145} {8 7 6 5 4 3 2 1 nosort}
146do_test descidx2-3.7 {
147 cksort {SELECT a FROM t1 ORDER BY b}
148} {1 2 3 4 5 6 7 8 nosort}
149do_test descidx2-3.8 {
150 cksort {SELECT a FROM t1 ORDER BY b ASC}
151} {1 2 3 4 5 6 7 8 nosort}
152do_test descidx2-3.9 {
153 cksort {SELECT a FROM t1 ORDER BY b DESC}
154} {8 7 6 5 4 3 2 1 nosort}
155do_test descidx2-3.10 {
156 cksort {SELECT b FROM t1 ORDER BY b}
157} {1 2 3 4 5 6 7 8 nosort}
158do_test descidx2-3.11 {
159 cksort {SELECT b FROM t1 ORDER BY b ASC}
160} {1 2 3 4 5 6 7 8 nosort}
161do_test descidx2-3.12 {
162 cksort {SELECT b FROM t1 ORDER BY b DESC}
163} {8 7 6 5 4 3 2 1 nosort}
164
165do_test descidx2-3.21 {
166 cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a}
167} {4 5 6 7 nosort}
168do_test descidx2-3.22 {
169 cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
170} {4 5 6 7 nosort}
171do_test descidx2-3.23 {
172 cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
173} {7 6 5 4 nosort}
174do_test descidx2-3.24 {
175 cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a}
176} {4 5 6 7 nosort}
177do_test descidx2-3.25 {
178 cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC}
179} {4 5 6 7 nosort}
180do_test descidx2-3.26 {
181 cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC}
182} {7 6 5 4 nosort}
183
184finish_test