blob: 353031e74e3dc8831ff96d4a979b4fbd99ffac40 [file] [log] [blame]
dand7e86892013-03-12 18:44:49 +00001# 2013 March 13
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.
12#
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16set ::testprefix tkt-4dd95f6943
17
18do_execsql_test 1.0 {
19 CREATE TABLE t1(x);
20 INSERT INTO t1 VALUES (3), (4), (2), (1), (5), (6);
21}
22
23foreach {tn1 idx} {
24 1 { CREATE INDEX i1 ON t1(x ASC) }
25 2 { CREATE INDEX i1 ON t1(x DESC) }
26} {
27 do_execsql_test 1.$tn1.1 { DROP INDEX IF EXISTS i1; }
28 do_execsql_test 1.$tn1.2 $idx
29
30 do_execsql_test 1.$tn1.3 {
31 SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x ASC;
32 } {2 4 5}
33
34 do_execsql_test 1.$tn1.4 {
35 SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x DESC;
36 } {5 4 2}
37}
38
39
40do_execsql_test 2.0 {
41 CREATE TABLE t2(x, y);
42 INSERT INTO t2 VALUES (5, 3), (5, 4), (5, 2), (5, 1), (5, 5), (5, 6);
43 INSERT INTO t2 VALUES (1, 3), (1, 4), (1, 2), (1, 1), (1, 5), (1, 6);
44 INSERT INTO t2 VALUES (3, 3), (3, 4), (3, 2), (3, 1), (3, 5), (3, 6);
45 INSERT INTO t2 VALUES (2, 3), (2, 4), (2, 2), (2, 1), (2, 5), (2, 6);
46 INSERT INTO t2 VALUES (4, 3), (4, 4), (4, 2), (4, 1), (4, 5), (4, 6);
47 INSERT INTO t2 VALUES (6, 3), (6, 4), (6, 2), (6, 1), (6, 5), (6, 6);
48
49 CREATE TABLE t3(a, b);
50 INSERT INTO t3 VALUES (2, 2), (4, 4), (5, 5);
dan27e6df42013-03-13 07:02:04 +000051 CREATE UNIQUE INDEX t3i1 ON t3(a ASC);
52 CREATE UNIQUE INDEX t3i2 ON t3(b DESC);
dand7e86892013-03-12 18:44:49 +000053}
54
55foreach {tn1 idx} {
56 1 { CREATE INDEX i1 ON t2(x ASC, y ASC) }
57 2 { CREATE INDEX i1 ON t2(x ASC, y DESC) }
58 3 { CREATE INDEX i1 ON t2(x DESC, y ASC) }
59 4 { CREATE INDEX i1 ON t2(x DESC, y DESC) }
60
61 5 { CREATE INDEX i1 ON t2(y ASC, x ASC) }
62 6 { CREATE INDEX i1 ON t2(y ASC, x DESC) }
63 7 { CREATE INDEX i1 ON t2(y DESC, x ASC) }
64 8 { CREATE INDEX i1 ON t2(y DESC, x DESC) }
65} {
66 do_execsql_test 2.$tn1.1 { DROP INDEX IF EXISTS i1; }
67 do_execsql_test 2.$tn1.2 $idx
68
69 foreach {tn2 inexpr} {
dan27e6df42013-03-13 07:02:04 +000070 3 "(2, 4, 5)"
71 4 "(SELECT a FROM t3)"
72 5 "(SELECT b FROM t3)"
dand7e86892013-03-12 18:44:49 +000073 } {
dan27e6df42013-03-13 07:02:04 +000074 do_execsql_test 2.$tn1.$tn2.1 "
dand7e86892013-03-12 18:44:49 +000075 SELECT x, y FROM t2 WHERE x = 1 AND y IN $inexpr ORDER BY x ASC, y ASC;
76 " {1 2 1 4 1 5}
dan27e6df42013-03-13 07:02:04 +000077
78 do_execsql_test 2.$tn1.$tn2.2 "
dand7e86892013-03-12 18:44:49 +000079 SELECT x, y FROM t2 WHERE x = 2 AND y IN $inexpr ORDER BY x ASC, y DESC;
80 " {2 5 2 4 2 2}
dan27e6df42013-03-13 07:02:04 +000081
82 do_execsql_test 2.$tn1.$tn2.3 "
dand7e86892013-03-12 18:44:49 +000083 SELECT x, y FROM t2 WHERE x = 3 AND y IN $inexpr ORDER BY x DESC, y ASC;
84 " {3 2 3 4 3 5}
dan27e6df42013-03-13 07:02:04 +000085
86 do_execsql_test 2.$tn1.$tn2.4 "
dand7e86892013-03-12 18:44:49 +000087 SELECT x, y FROM t2 WHERE x = 4 AND y IN $inexpr ORDER BY x DESC, y DESC;
88 " {4 5 4 4 4 2}
dan27e6df42013-03-13 07:02:04 +000089
90 do_execsql_test 2.$tn1.$tn2.5 "
91 SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
92 ORDER BY a, x ASC, y ASC;
93 " {4 1 2 4 1 4 4 1 5}
94 do_execsql_test 2.$tn1.$tn2.6 "
95 SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
96 ORDER BY x ASC, y ASC;
97 " {2 1 2 2 1 4 2 1 5}
98
99 do_execsql_test 2.$tn1.$tn2.7 "
100 SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
101 ORDER BY a, x ASC, y DESC;
102 " {4 1 5 4 1 4 4 1 2}
103 do_execsql_test 2.$tn1.8 "
104 SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
105 ORDER BY x ASC, y DESC;
106 " {2 1 5 2 1 4 2 1 2}
107
108 do_execsql_test 2.$tn1.$tn2.9 "
109 SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
110 ORDER BY a, x DESC, y ASC;
111 " {4 1 2 4 1 4 4 1 5}
112 do_execsql_test 2.$tn1.10 "
113 SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
114 ORDER BY x DESC, y ASC;
115 " {2 1 2 2 1 4 2 1 5}
116
117 do_execsql_test 2.$tn1.$tn2.11 "
118 SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
119 ORDER BY a, x DESC, y DESC;
120 " {4 1 5 4 1 4 4 1 2}
121 do_execsql_test 2.$tn1.$tn2.12 "
122 SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
123 ORDER BY x DESC, y DESC;
124 " {2 1 5 2 1 4 2 1 2}
dand7e86892013-03-12 18:44:49 +0000125 }
126}
127
drh725e1ae2013-03-12 23:58:42 +0000128do_execsql_test 3.0 {
129 CREATE TABLE t7(x);
130 INSERT INTO t7 VALUES (1), (2), (3);
131 CREATE INDEX i7 ON t7(x);
dand7e86892013-03-12 18:44:49 +0000132
drh725e1ae2013-03-12 23:58:42 +0000133 CREATE TABLE t8(y);
134 INSERT INTO t8 VALUES (1), (2), (3);
dan27e6df42013-03-13 07:02:04 +0000135}
drh725e1ae2013-03-12 23:58:42 +0000136
dan27e6df42013-03-13 07:02:04 +0000137foreach {tn idxdir sortdir sortdata} {
138 1 ASC ASC {1 2 3}
139 2 ASC DESC {3 2 1}
140 3 DESC ASC {1 2 3}
141 4 ASC DESC {3 2 1}
142} {
143
144 do_execsql_test 3.$tn "
145 DROP INDEX IF EXISTS i8;
146 CREATE UNIQUE INDEX i8 ON t8(y $idxdir);
147 SELECT x FROM t7 WHERE x IN (SELECT y FROM t8) ORDER BY x $sortdir;
148 " $sortdata
149}
drh725e1ae2013-03-12 23:58:42 +0000150
151finish_test