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. The
12 # focus of this script is descending indices.
14 # $Id: descidx3.test,v 1.6 2008/03/19 00:21:31 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Do not use a codec for tests in this file, as the database file is
21 # manipulated directly using tcl scripts (using the [hexio_write] command).
29 #db eval {PRAGMA legacy_file_format=OFF}
30 sqlite3_db_config db LEGACY_FILE_FORMAT 0
32 # This procedure sets the value of the file-format in file 'test.db'
33 # to $newval. Also, the schema cookie is incremented.
35 proc set_file_format {newval} {
36 hexio_write test.db 44 [hexio_render_int32 $newval]
37 set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
39 hexio_write test.db 40 [hexio_render_int32 $schemacookie]
43 # This procedure returns the value of the file-format in file 'test.db'.
45 proc get_file_format {{fname test.db}} {
46 return [hexio_get_int [hexio_read $fname 44 4]]
49 # Verify that the file format starts as 4.
51 do_test descidx3-1.1 {
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);
60 # Put some information in the table and verify that the descending
61 # index actually works.
63 do_test descidx3-2.1 {
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;
77 do_test descidx3-2.2 {
79 SELECT i FROM t1 ORDER BY a;
82 do_test descidx3-2.3 {
84 SELECT i FROM t1 ORDER BY a DESC;
88 # The "natural" order for the index is decreasing
89 do_test descidx3-2.4 {
91 SELECT i FROM t1 WHERE a<=x'7979';
94 do_test descidx3-2.5 {
96 SELECT i FROM t1 WHERE a>-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
104 do_test descidx3-3.1 {
107 SELECT i FROM t1 ORDER BY a;
109 } {9 7 6 8 3 4 2 5 1}
110 do_test descidx3-3.2 {
112 SELECT i FROM t1 WHERE a=1 AND b>0 AND b<'zzz'
115 do_test descidx3-3.3 {
117 SELECT i FROM t1 WHERE b>0 AND b<'zzz'
120 do_test descidx3-3.4 {
122 SELECT i FROM t1 WHERE a=1 AND b>-9999 AND b<x'ffffffff'
125 do_test descidx3-3.5 {
127 SELECT i FROM t1 WHERE b>-9999 AND b<x'ffffffff'
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
135 do_test descidx3-4.1 {
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';
141 do_test descidx3-4.2 {
144 SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
147 do_test descidx3-4.3 {
150 SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
152 } {9 7 6 8 3 4 2 5 1}