sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is testing the SELECT statement.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# $Id: select1.test,v 1.65 2008/08/04 03:51:24 danielk1977 Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
set testdir [file dirname $argv0]
|
sl@0
|
17 |
source $testdir/tester.tcl
|
sl@0
|
18 |
|
sl@0
|
19 |
# Try to select on a non-existant table.
|
sl@0
|
20 |
#
|
sl@0
|
21 |
do_test select1-1.1 {
|
sl@0
|
22 |
set v [catch {execsql {SELECT * FROM test1}} msg]
|
sl@0
|
23 |
lappend v $msg
|
sl@0
|
24 |
} {1 {no such table: test1}}
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
execsql {CREATE TABLE test1(f1 int, f2 int)}
|
sl@0
|
28 |
|
sl@0
|
29 |
do_test select1-1.2 {
|
sl@0
|
30 |
set v [catch {execsql {SELECT * FROM test1, test2}} msg]
|
sl@0
|
31 |
lappend v $msg
|
sl@0
|
32 |
} {1 {no such table: test2}}
|
sl@0
|
33 |
do_test select1-1.3 {
|
sl@0
|
34 |
set v [catch {execsql {SELECT * FROM test2, test1}} msg]
|
sl@0
|
35 |
lappend v $msg
|
sl@0
|
36 |
} {1 {no such table: test2}}
|
sl@0
|
37 |
|
sl@0
|
38 |
execsql {INSERT INTO test1(f1,f2) VALUES(11,22)}
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
# Make sure the columns are extracted correctly.
|
sl@0
|
42 |
#
|
sl@0
|
43 |
do_test select1-1.4 {
|
sl@0
|
44 |
execsql {SELECT f1 FROM test1}
|
sl@0
|
45 |
} {11}
|
sl@0
|
46 |
do_test select1-1.5 {
|
sl@0
|
47 |
execsql {SELECT f2 FROM test1}
|
sl@0
|
48 |
} {22}
|
sl@0
|
49 |
do_test select1-1.6 {
|
sl@0
|
50 |
execsql {SELECT f2, f1 FROM test1}
|
sl@0
|
51 |
} {22 11}
|
sl@0
|
52 |
do_test select1-1.7 {
|
sl@0
|
53 |
execsql {SELECT f1, f2 FROM test1}
|
sl@0
|
54 |
} {11 22}
|
sl@0
|
55 |
do_test select1-1.8 {
|
sl@0
|
56 |
execsql {SELECT * FROM test1}
|
sl@0
|
57 |
} {11 22}
|
sl@0
|
58 |
do_test select1-1.8.1 {
|
sl@0
|
59 |
execsql {SELECT *, * FROM test1}
|
sl@0
|
60 |
} {11 22 11 22}
|
sl@0
|
61 |
do_test select1-1.8.2 {
|
sl@0
|
62 |
execsql {SELECT *, min(f1,f2), max(f1,f2) FROM test1}
|
sl@0
|
63 |
} {11 22 11 22}
|
sl@0
|
64 |
do_test select1-1.8.3 {
|
sl@0
|
65 |
execsql {SELECT 'one', *, 'two', * FROM test1}
|
sl@0
|
66 |
} {one 11 22 two 11 22}
|
sl@0
|
67 |
|
sl@0
|
68 |
execsql {CREATE TABLE test2(r1 real, r2 real)}
|
sl@0
|
69 |
execsql {INSERT INTO test2(r1,r2) VALUES(1.1,2.2)}
|
sl@0
|
70 |
|
sl@0
|
71 |
do_test select1-1.9 {
|
sl@0
|
72 |
execsql {SELECT * FROM test1, test2}
|
sl@0
|
73 |
} {11 22 1.1 2.2}
|
sl@0
|
74 |
do_test select1-1.9.1 {
|
sl@0
|
75 |
execsql {SELECT *, 'hi' FROM test1, test2}
|
sl@0
|
76 |
} {11 22 1.1 2.2 hi}
|
sl@0
|
77 |
do_test select1-1.9.2 {
|
sl@0
|
78 |
execsql {SELECT 'one', *, 'two', * FROM test1, test2}
|
sl@0
|
79 |
} {one 11 22 1.1 2.2 two 11 22 1.1 2.2}
|
sl@0
|
80 |
do_test select1-1.10 {
|
sl@0
|
81 |
execsql {SELECT test1.f1, test2.r1 FROM test1, test2}
|
sl@0
|
82 |
} {11 1.1}
|
sl@0
|
83 |
do_test select1-1.11 {
|
sl@0
|
84 |
execsql {SELECT test1.f1, test2.r1 FROM test2, test1}
|
sl@0
|
85 |
} {11 1.1}
|
sl@0
|
86 |
do_test select1-1.11.1 {
|
sl@0
|
87 |
execsql {SELECT * FROM test2, test1}
|
sl@0
|
88 |
} {1.1 2.2 11 22}
|
sl@0
|
89 |
do_test select1-1.11.2 {
|
sl@0
|
90 |
execsql {SELECT * FROM test1 AS a, test1 AS b}
|
sl@0
|
91 |
} {11 22 11 22}
|
sl@0
|
92 |
do_test select1-1.12 {
|
sl@0
|
93 |
execsql {SELECT max(test1.f1,test2.r1), min(test1.f2,test2.r2)
|
sl@0
|
94 |
FROM test2, test1}
|
sl@0
|
95 |
} {11 2.2}
|
sl@0
|
96 |
do_test select1-1.13 {
|
sl@0
|
97 |
execsql {SELECT min(test1.f1,test2.r1), max(test1.f2,test2.r2)
|
sl@0
|
98 |
FROM test1, test2}
|
sl@0
|
99 |
} {1.1 22}
|
sl@0
|
100 |
|
sl@0
|
101 |
set long {This is a string that is too big to fit inside a NBFS buffer}
|
sl@0
|
102 |
do_test select1-2.0 {
|
sl@0
|
103 |
execsql "
|
sl@0
|
104 |
DROP TABLE test2;
|
sl@0
|
105 |
DELETE FROM test1;
|
sl@0
|
106 |
INSERT INTO test1 VALUES(11,22);
|
sl@0
|
107 |
INSERT INTO test1 VALUES(33,44);
|
sl@0
|
108 |
CREATE TABLE t3(a,b);
|
sl@0
|
109 |
INSERT INTO t3 VALUES('abc',NULL);
|
sl@0
|
110 |
INSERT INTO t3 VALUES(NULL,'xyz');
|
sl@0
|
111 |
INSERT INTO t3 SELECT * FROM test1;
|
sl@0
|
112 |
CREATE TABLE t4(a,b);
|
sl@0
|
113 |
INSERT INTO t4 VALUES(NULL,'$long');
|
sl@0
|
114 |
SELECT * FROM t3;
|
sl@0
|
115 |
"
|
sl@0
|
116 |
} {abc {} {} xyz 11 22 33 44}
|
sl@0
|
117 |
|
sl@0
|
118 |
# Error messges from sqliteExprCheck
|
sl@0
|
119 |
#
|
sl@0
|
120 |
do_test select1-2.1 {
|
sl@0
|
121 |
set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg]
|
sl@0
|
122 |
lappend v $msg
|
sl@0
|
123 |
} {1 {wrong number of arguments to function count()}}
|
sl@0
|
124 |
do_test select1-2.2 {
|
sl@0
|
125 |
set v [catch {execsql {SELECT count(f1) FROM test1}} msg]
|
sl@0
|
126 |
lappend v $msg
|
sl@0
|
127 |
} {0 2}
|
sl@0
|
128 |
do_test select1-2.3 {
|
sl@0
|
129 |
set v [catch {execsql {SELECT Count() FROM test1}} msg]
|
sl@0
|
130 |
lappend v $msg
|
sl@0
|
131 |
} {0 2}
|
sl@0
|
132 |
do_test select1-2.4 {
|
sl@0
|
133 |
set v [catch {execsql {SELECT COUNT(*) FROM test1}} msg]
|
sl@0
|
134 |
lappend v $msg
|
sl@0
|
135 |
} {0 2}
|
sl@0
|
136 |
do_test select1-2.5 {
|
sl@0
|
137 |
set v [catch {execsql {SELECT COUNT(*)+1 FROM test1}} msg]
|
sl@0
|
138 |
lappend v $msg
|
sl@0
|
139 |
} {0 3}
|
sl@0
|
140 |
do_test select1-2.5.1 {
|
sl@0
|
141 |
execsql {SELECT count(*),count(a),count(b) FROM t3}
|
sl@0
|
142 |
} {4 3 3}
|
sl@0
|
143 |
do_test select1-2.5.2 {
|
sl@0
|
144 |
execsql {SELECT count(*),count(a),count(b) FROM t4}
|
sl@0
|
145 |
} {1 0 1}
|
sl@0
|
146 |
do_test select1-2.5.3 {
|
sl@0
|
147 |
execsql {SELECT count(*),count(a),count(b) FROM t4 WHERE b=5}
|
sl@0
|
148 |
} {0 0 0}
|
sl@0
|
149 |
do_test select1-2.6 {
|
sl@0
|
150 |
set v [catch {execsql {SELECT min(*) FROM test1}} msg]
|
sl@0
|
151 |
lappend v $msg
|
sl@0
|
152 |
} {1 {wrong number of arguments to function min()}}
|
sl@0
|
153 |
do_test select1-2.7 {
|
sl@0
|
154 |
set v [catch {execsql {SELECT Min(f1) FROM test1}} msg]
|
sl@0
|
155 |
lappend v $msg
|
sl@0
|
156 |
} {0 11}
|
sl@0
|
157 |
do_test select1-2.8 {
|
sl@0
|
158 |
set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg]
|
sl@0
|
159 |
lappend v [lsort $msg]
|
sl@0
|
160 |
} {0 {11 33}}
|
sl@0
|
161 |
do_test select1-2.8.1 {
|
sl@0
|
162 |
execsql {SELECT coalesce(min(a),'xyzzy') FROM t3}
|
sl@0
|
163 |
} {11}
|
sl@0
|
164 |
do_test select1-2.8.2 {
|
sl@0
|
165 |
execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3}
|
sl@0
|
166 |
} {11}
|
sl@0
|
167 |
do_test select1-2.8.3 {
|
sl@0
|
168 |
execsql {SELECT min(b), min(b) FROM t4}
|
sl@0
|
169 |
} [list $long $long]
|
sl@0
|
170 |
do_test select1-2.9 {
|
sl@0
|
171 |
set v [catch {execsql {SELECT MAX(*) FROM test1}} msg]
|
sl@0
|
172 |
lappend v $msg
|
sl@0
|
173 |
} {1 {wrong number of arguments to function MAX()}}
|
sl@0
|
174 |
do_test select1-2.10 {
|
sl@0
|
175 |
set v [catch {execsql {SELECT Max(f1) FROM test1}} msg]
|
sl@0
|
176 |
lappend v $msg
|
sl@0
|
177 |
} {0 33}
|
sl@0
|
178 |
do_test select1-2.11 {
|
sl@0
|
179 |
set v [catch {execsql {SELECT max(f1,f2) FROM test1}} msg]
|
sl@0
|
180 |
lappend v [lsort $msg]
|
sl@0
|
181 |
} {0 {22 44}}
|
sl@0
|
182 |
do_test select1-2.12 {
|
sl@0
|
183 |
set v [catch {execsql {SELECT MAX(f1,f2)+1 FROM test1}} msg]
|
sl@0
|
184 |
lappend v [lsort $msg]
|
sl@0
|
185 |
} {0 {23 45}}
|
sl@0
|
186 |
do_test select1-2.13 {
|
sl@0
|
187 |
set v [catch {execsql {SELECT MAX(f1)+1 FROM test1}} msg]
|
sl@0
|
188 |
lappend v $msg
|
sl@0
|
189 |
} {0 34}
|
sl@0
|
190 |
do_test select1-2.13.1 {
|
sl@0
|
191 |
execsql {SELECT coalesce(max(a),'xyzzy') FROM t3}
|
sl@0
|
192 |
} {abc}
|
sl@0
|
193 |
do_test select1-2.13.2 {
|
sl@0
|
194 |
execsql {SELECT max(coalesce(a,'xyzzy')) FROM t3}
|
sl@0
|
195 |
} {xyzzy}
|
sl@0
|
196 |
do_test select1-2.14 {
|
sl@0
|
197 |
set v [catch {execsql {SELECT SUM(*) FROM test1}} msg]
|
sl@0
|
198 |
lappend v $msg
|
sl@0
|
199 |
} {1 {wrong number of arguments to function SUM()}}
|
sl@0
|
200 |
do_test select1-2.15 {
|
sl@0
|
201 |
set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
|
sl@0
|
202 |
lappend v $msg
|
sl@0
|
203 |
} {0 44}
|
sl@0
|
204 |
do_test select1-2.16 {
|
sl@0
|
205 |
set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
|
sl@0
|
206 |
lappend v $msg
|
sl@0
|
207 |
} {1 {wrong number of arguments to function sum()}}
|
sl@0
|
208 |
do_test select1-2.17 {
|
sl@0
|
209 |
set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
|
sl@0
|
210 |
lappend v $msg
|
sl@0
|
211 |
} {0 45}
|
sl@0
|
212 |
do_test select1-2.17.1 {
|
sl@0
|
213 |
execsql {SELECT sum(a) FROM t3}
|
sl@0
|
214 |
} {44.0}
|
sl@0
|
215 |
do_test select1-2.18 {
|
sl@0
|
216 |
set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg]
|
sl@0
|
217 |
lappend v $msg
|
sl@0
|
218 |
} {1 {no such function: XYZZY}}
|
sl@0
|
219 |
do_test select1-2.19 {
|
sl@0
|
220 |
set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg]
|
sl@0
|
221 |
lappend v $msg
|
sl@0
|
222 |
} {0 44}
|
sl@0
|
223 |
do_test select1-2.20 {
|
sl@0
|
224 |
set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg]
|
sl@0
|
225 |
lappend v $msg
|
sl@0
|
226 |
} {1 {misuse of aggregate function min()}}
|
sl@0
|
227 |
|
sl@0
|
228 |
# Ticket #2526
|
sl@0
|
229 |
#
|
sl@0
|
230 |
do_test select1-2.21 {
|
sl@0
|
231 |
catchsql {
|
sl@0
|
232 |
SELECT min(f1) AS m FROM test1 GROUP BY f1 HAVING max(m+5)<10
|
sl@0
|
233 |
}
|
sl@0
|
234 |
} {1 {misuse of aliased aggregate m}}
|
sl@0
|
235 |
do_test select1-2.22 {
|
sl@0
|
236 |
catchsql {
|
sl@0
|
237 |
SELECT coalesce(min(f1)+5,11) AS m FROM test1
|
sl@0
|
238 |
GROUP BY f1
|
sl@0
|
239 |
HAVING max(m+5)<10
|
sl@0
|
240 |
}
|
sl@0
|
241 |
} {1 {misuse of aliased aggregate m}}
|
sl@0
|
242 |
do_test select1-2.23 {
|
sl@0
|
243 |
execsql {
|
sl@0
|
244 |
CREATE TABLE tkt2526(a,b,c PRIMARY KEY);
|
sl@0
|
245 |
INSERT INTO tkt2526 VALUES('x','y',NULL);
|
sl@0
|
246 |
INSERT INTO tkt2526 VALUES('x','z',NULL);
|
sl@0
|
247 |
}
|
sl@0
|
248 |
catchsql {
|
sl@0
|
249 |
SELECT count(a) AS cn FROM tkt2526 GROUP BY a HAVING cn<max(cn)
|
sl@0
|
250 |
}
|
sl@0
|
251 |
} {1 {misuse of aliased aggregate cn}}
|
sl@0
|
252 |
|
sl@0
|
253 |
# WHERE clause expressions
|
sl@0
|
254 |
#
|
sl@0
|
255 |
do_test select1-3.1 {
|
sl@0
|
256 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<11}} msg]
|
sl@0
|
257 |
lappend v $msg
|
sl@0
|
258 |
} {0 {}}
|
sl@0
|
259 |
do_test select1-3.2 {
|
sl@0
|
260 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<=11}} msg]
|
sl@0
|
261 |
lappend v $msg
|
sl@0
|
262 |
} {0 11}
|
sl@0
|
263 |
do_test select1-3.3 {
|
sl@0
|
264 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1=11}} msg]
|
sl@0
|
265 |
lappend v $msg
|
sl@0
|
266 |
} {0 11}
|
sl@0
|
267 |
do_test select1-3.4 {
|
sl@0
|
268 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>=11}} msg]
|
sl@0
|
269 |
lappend v [lsort $msg]
|
sl@0
|
270 |
} {0 {11 33}}
|
sl@0
|
271 |
do_test select1-3.5 {
|
sl@0
|
272 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>11}} msg]
|
sl@0
|
273 |
lappend v [lsort $msg]
|
sl@0
|
274 |
} {0 33}
|
sl@0
|
275 |
do_test select1-3.6 {
|
sl@0
|
276 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1!=11}} msg]
|
sl@0
|
277 |
lappend v [lsort $msg]
|
sl@0
|
278 |
} {0 33}
|
sl@0
|
279 |
do_test select1-3.7 {
|
sl@0
|
280 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE min(f1,f2)!=11}} msg]
|
sl@0
|
281 |
lappend v [lsort $msg]
|
sl@0
|
282 |
} {0 33}
|
sl@0
|
283 |
do_test select1-3.8 {
|
sl@0
|
284 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE max(f1,f2)!=11}} msg]
|
sl@0
|
285 |
lappend v [lsort $msg]
|
sl@0
|
286 |
} {0 {11 33}}
|
sl@0
|
287 |
do_test select1-3.9 {
|
sl@0
|
288 |
set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg]
|
sl@0
|
289 |
lappend v $msg
|
sl@0
|
290 |
} {1 {wrong number of arguments to function count()}}
|
sl@0
|
291 |
|
sl@0
|
292 |
# ORDER BY expressions
|
sl@0
|
293 |
#
|
sl@0
|
294 |
do_test select1-4.1 {
|
sl@0
|
295 |
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY f1}} msg]
|
sl@0
|
296 |
lappend v $msg
|
sl@0
|
297 |
} {0 {11 33}}
|
sl@0
|
298 |
do_test select1-4.2 {
|
sl@0
|
299 |
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY -f1}} msg]
|
sl@0
|
300 |
lappend v $msg
|
sl@0
|
301 |
} {0 {33 11}}
|
sl@0
|
302 |
do_test select1-4.3 {
|
sl@0
|
303 |
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1,f2)}} msg]
|
sl@0
|
304 |
lappend v $msg
|
sl@0
|
305 |
} {0 {11 33}}
|
sl@0
|
306 |
do_test select1-4.4 {
|
sl@0
|
307 |
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg]
|
sl@0
|
308 |
lappend v $msg
|
sl@0
|
309 |
} {1 {misuse of aggregate: min(f1)}}
|
sl@0
|
310 |
|
sl@0
|
311 |
# The restriction not allowing constants in the ORDER BY clause
|
sl@0
|
312 |
# has been removed. See ticket #1768
|
sl@0
|
313 |
#do_test select1-4.5 {
|
sl@0
|
314 |
# catchsql {
|
sl@0
|
315 |
# SELECT f1 FROM test1 ORDER BY 8.4;
|
sl@0
|
316 |
# }
|
sl@0
|
317 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
318 |
#do_test select1-4.6 {
|
sl@0
|
319 |
# catchsql {
|
sl@0
|
320 |
# SELECT f1 FROM test1 ORDER BY '8.4';
|
sl@0
|
321 |
# }
|
sl@0
|
322 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
323 |
#do_test select1-4.7.1 {
|
sl@0
|
324 |
# catchsql {
|
sl@0
|
325 |
# SELECT f1 FROM test1 ORDER BY 'xyz';
|
sl@0
|
326 |
# }
|
sl@0
|
327 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
328 |
#do_test select1-4.7.2 {
|
sl@0
|
329 |
# catchsql {
|
sl@0
|
330 |
# SELECT f1 FROM test1 ORDER BY -8.4;
|
sl@0
|
331 |
# }
|
sl@0
|
332 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
333 |
#do_test select1-4.7.3 {
|
sl@0
|
334 |
# catchsql {
|
sl@0
|
335 |
# SELECT f1 FROM test1 ORDER BY +8.4;
|
sl@0
|
336 |
# }
|
sl@0
|
337 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
338 |
#do_test select1-4.7.4 {
|
sl@0
|
339 |
# catchsql {
|
sl@0
|
340 |
# SELECT f1 FROM test1 ORDER BY 4294967296; -- constant larger than 32 bits
|
sl@0
|
341 |
# }
|
sl@0
|
342 |
#} {1 {ORDER BY terms must not be non-integer constants}}
|
sl@0
|
343 |
|
sl@0
|
344 |
do_test select1-4.5 {
|
sl@0
|
345 |
execsql {
|
sl@0
|
346 |
SELECT f1 FROM test1 ORDER BY 8.4
|
sl@0
|
347 |
}
|
sl@0
|
348 |
} {11 33}
|
sl@0
|
349 |
do_test select1-4.6 {
|
sl@0
|
350 |
execsql {
|
sl@0
|
351 |
SELECT f1 FROM test1 ORDER BY '8.4'
|
sl@0
|
352 |
}
|
sl@0
|
353 |
} {11 33}
|
sl@0
|
354 |
|
sl@0
|
355 |
do_test select1-4.8 {
|
sl@0
|
356 |
execsql {
|
sl@0
|
357 |
CREATE TABLE t5(a,b);
|
sl@0
|
358 |
INSERT INTO t5 VALUES(1,10);
|
sl@0
|
359 |
INSERT INTO t5 VALUES(2,9);
|
sl@0
|
360 |
SELECT * FROM t5 ORDER BY 1;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
} {1 10 2 9}
|
sl@0
|
363 |
do_test select1-4.9.1 {
|
sl@0
|
364 |
execsql {
|
sl@0
|
365 |
SELECT * FROM t5 ORDER BY 2;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
} {2 9 1 10}
|
sl@0
|
368 |
do_test select1-4.9.2 {
|
sl@0
|
369 |
execsql {
|
sl@0
|
370 |
SELECT * FROM t5 ORDER BY +2;
|
sl@0
|
371 |
}
|
sl@0
|
372 |
} {2 9 1 10}
|
sl@0
|
373 |
do_test select1-4.10.1 {
|
sl@0
|
374 |
catchsql {
|
sl@0
|
375 |
SELECT * FROM t5 ORDER BY 3;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
} {1 {1st ORDER BY term out of range - should be between 1 and 2}}
|
sl@0
|
378 |
do_test select1-4.10.2 {
|
sl@0
|
379 |
catchsql {
|
sl@0
|
380 |
SELECT * FROM t5 ORDER BY -1;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
} {1 {1st ORDER BY term out of range - should be between 1 and 2}}
|
sl@0
|
383 |
do_test select1-4.11 {
|
sl@0
|
384 |
execsql {
|
sl@0
|
385 |
INSERT INTO t5 VALUES(3,10);
|
sl@0
|
386 |
SELECT * FROM t5 ORDER BY 2, 1 DESC;
|
sl@0
|
387 |
}
|
sl@0
|
388 |
} {2 9 3 10 1 10}
|
sl@0
|
389 |
do_test select1-4.12 {
|
sl@0
|
390 |
execsql {
|
sl@0
|
391 |
SELECT * FROM t5 ORDER BY 1 DESC, b;
|
sl@0
|
392 |
}
|
sl@0
|
393 |
} {3 10 2 9 1 10}
|
sl@0
|
394 |
do_test select1-4.13 {
|
sl@0
|
395 |
execsql {
|
sl@0
|
396 |
SELECT * FROM t5 ORDER BY b DESC, 1;
|
sl@0
|
397 |
}
|
sl@0
|
398 |
} {1 10 3 10 2 9}
|
sl@0
|
399 |
|
sl@0
|
400 |
|
sl@0
|
401 |
# ORDER BY ignored on an aggregate query
|
sl@0
|
402 |
#
|
sl@0
|
403 |
do_test select1-5.1 {
|
sl@0
|
404 |
set v [catch {execsql {SELECT max(f1) FROM test1 ORDER BY f2}} msg]
|
sl@0
|
405 |
lappend v $msg
|
sl@0
|
406 |
} {0 33}
|
sl@0
|
407 |
|
sl@0
|
408 |
execsql {CREATE TABLE test2(t1 text, t2 text)}
|
sl@0
|
409 |
execsql {INSERT INTO test2 VALUES('abc','xyz')}
|
sl@0
|
410 |
|
sl@0
|
411 |
# Check for column naming
|
sl@0
|
412 |
#
|
sl@0
|
413 |
do_test select1-6.1 {
|
sl@0
|
414 |
set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
|
sl@0
|
415 |
lappend v $msg
|
sl@0
|
416 |
} {0 {f1 11 f1 33}}
|
sl@0
|
417 |
do_test select1-6.1.1 {
|
sl@0
|
418 |
db eval {PRAGMA full_column_names=on}
|
sl@0
|
419 |
set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
|
sl@0
|
420 |
lappend v $msg
|
sl@0
|
421 |
} {0 {test1.f1 11 test1.f1 33}}
|
sl@0
|
422 |
do_test select1-6.1.2 {
|
sl@0
|
423 |
set v [catch {execsql2 {SELECT f1 as 'f1' FROM test1 ORDER BY f2}} msg]
|
sl@0
|
424 |
lappend v $msg
|
sl@0
|
425 |
} {0 {f1 11 f1 33}}
|
sl@0
|
426 |
do_test select1-6.1.3 {
|
sl@0
|
427 |
set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
|
sl@0
|
428 |
lappend v $msg
|
sl@0
|
429 |
} {0 {f1 11 f2 22}}
|
sl@0
|
430 |
do_test select1-6.1.4 {
|
sl@0
|
431 |
set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
|
sl@0
|
432 |
db eval {PRAGMA full_column_names=off}
|
sl@0
|
433 |
lappend v $msg
|
sl@0
|
434 |
} {0 {f1 11 f2 22}}
|
sl@0
|
435 |
do_test select1-6.1.5 {
|
sl@0
|
436 |
set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
|
sl@0
|
437 |
lappend v $msg
|
sl@0
|
438 |
} {0 {f1 11 f2 22}}
|
sl@0
|
439 |
do_test select1-6.1.6 {
|
sl@0
|
440 |
set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
|
sl@0
|
441 |
lappend v $msg
|
sl@0
|
442 |
} {0 {f1 11 f2 22}}
|
sl@0
|
443 |
do_test select1-6.2 {
|
sl@0
|
444 |
set v [catch {execsql2 {SELECT f1 as xyzzy FROM test1 ORDER BY f2}} msg]
|
sl@0
|
445 |
lappend v $msg
|
sl@0
|
446 |
} {0 {xyzzy 11 xyzzy 33}}
|
sl@0
|
447 |
do_test select1-6.3 {
|
sl@0
|
448 |
set v [catch {execsql2 {SELECT f1 as "xyzzy" FROM test1 ORDER BY f2}} msg]
|
sl@0
|
449 |
lappend v $msg
|
sl@0
|
450 |
} {0 {xyzzy 11 xyzzy 33}}
|
sl@0
|
451 |
do_test select1-6.3.1 {
|
sl@0
|
452 |
set v [catch {execsql2 {SELECT f1 as 'xyzzy ' FROM test1 ORDER BY f2}} msg]
|
sl@0
|
453 |
lappend v $msg
|
sl@0
|
454 |
} {0 {{xyzzy } 11 {xyzzy } 33}}
|
sl@0
|
455 |
do_test select1-6.4 {
|
sl@0
|
456 |
set v [catch {execsql2 {SELECT f1+F2 as xyzzy FROM test1 ORDER BY f2}} msg]
|
sl@0
|
457 |
lappend v $msg
|
sl@0
|
458 |
} {0 {xyzzy 33 xyzzy 77}}
|
sl@0
|
459 |
do_test select1-6.4a {
|
sl@0
|
460 |
set v [catch {execsql2 {SELECT f1+F2 FROM test1 ORDER BY f2}} msg]
|
sl@0
|
461 |
lappend v $msg
|
sl@0
|
462 |
} {0 {f1+F2 33 f1+F2 77}}
|
sl@0
|
463 |
do_test select1-6.5 {
|
sl@0
|
464 |
set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
|
sl@0
|
465 |
lappend v $msg
|
sl@0
|
466 |
} {0 {test1.f1+F2 33 test1.f1+F2 77}}
|
sl@0
|
467 |
do_test select1-6.5.1 {
|
sl@0
|
468 |
execsql2 {PRAGMA full_column_names=on}
|
sl@0
|
469 |
set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
|
sl@0
|
470 |
execsql2 {PRAGMA full_column_names=off}
|
sl@0
|
471 |
lappend v $msg
|
sl@0
|
472 |
} {0 {test1.f1+F2 33 test1.f1+F2 77}}
|
sl@0
|
473 |
do_test select1-6.6 {
|
sl@0
|
474 |
set v [catch {execsql2 {SELECT test1.f1+F2, t1 FROM test1, test2
|
sl@0
|
475 |
ORDER BY f2}} msg]
|
sl@0
|
476 |
lappend v $msg
|
sl@0
|
477 |
} {0 {test1.f1+F2 33 t1 abc test1.f1+F2 77 t1 abc}}
|
sl@0
|
478 |
do_test select1-6.7 {
|
sl@0
|
479 |
set v [catch {execsql2 {SELECT A.f1, t1 FROM test1 as A, test2
|
sl@0
|
480 |
ORDER BY f2}} msg]
|
sl@0
|
481 |
lappend v $msg
|
sl@0
|
482 |
} {0 {f1 11 t1 abc f1 33 t1 abc}}
|
sl@0
|
483 |
do_test select1-6.8 {
|
sl@0
|
484 |
set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as B
|
sl@0
|
485 |
ORDER BY f2}} msg]
|
sl@0
|
486 |
lappend v $msg
|
sl@0
|
487 |
} {1 {ambiguous column name: f1}}
|
sl@0
|
488 |
do_test select1-6.8b {
|
sl@0
|
489 |
set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
sl@0
|
490 |
ORDER BY f2}} msg]
|
sl@0
|
491 |
lappend v $msg
|
sl@0
|
492 |
} {1 {ambiguous column name: f2}}
|
sl@0
|
493 |
do_test select1-6.8c {
|
sl@0
|
494 |
set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as A
|
sl@0
|
495 |
ORDER BY f2}} msg]
|
sl@0
|
496 |
lappend v $msg
|
sl@0
|
497 |
} {1 {ambiguous column name: A.f1}}
|
sl@0
|
498 |
do_test select1-6.9.1 {
|
sl@0
|
499 |
set v [catch {execsql {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
sl@0
|
500 |
ORDER BY A.f1, B.f1}} msg]
|
sl@0
|
501 |
lappend v $msg
|
sl@0
|
502 |
} {0 {11 11 11 33 33 11 33 33}}
|
sl@0
|
503 |
do_test select1-6.9.2 {
|
sl@0
|
504 |
set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
sl@0
|
505 |
ORDER BY A.f1, B.f1}} msg]
|
sl@0
|
506 |
lappend v $msg
|
sl@0
|
507 |
} {0 {f1 11 f1 11 f1 33 f1 33 f1 11 f1 11 f1 33 f1 33}}
|
sl@0
|
508 |
|
sl@0
|
509 |
do_test select1-6.9.3 {
|
sl@0
|
510 |
db eval {
|
sl@0
|
511 |
PRAGMA short_column_names=OFF;
|
sl@0
|
512 |
PRAGMA full_column_names=OFF;
|
sl@0
|
513 |
}
|
sl@0
|
514 |
execsql2 {
|
sl@0
|
515 |
SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1
|
sl@0
|
516 |
}
|
sl@0
|
517 |
} {{test1 . f1} 11 {test1 . f2} 22}
|
sl@0
|
518 |
do_test select1-6.9.4 {
|
sl@0
|
519 |
db eval {
|
sl@0
|
520 |
PRAGMA short_column_names=OFF;
|
sl@0
|
521 |
PRAGMA full_column_names=ON;
|
sl@0
|
522 |
}
|
sl@0
|
523 |
execsql2 {
|
sl@0
|
524 |
SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1
|
sl@0
|
525 |
}
|
sl@0
|
526 |
} {test1.f1 11 test1.f2 22}
|
sl@0
|
527 |
do_test select1-6.9.5 {
|
sl@0
|
528 |
db eval {
|
sl@0
|
529 |
PRAGMA short_column_names=OFF;
|
sl@0
|
530 |
PRAGMA full_column_names=ON;
|
sl@0
|
531 |
}
|
sl@0
|
532 |
execsql2 {
|
sl@0
|
533 |
SELECT 123.45;
|
sl@0
|
534 |
}
|
sl@0
|
535 |
} {123.45 123.45}
|
sl@0
|
536 |
do_test select1-6.9.6 {
|
sl@0
|
537 |
execsql2 {
|
sl@0
|
538 |
SELECT * FROM test1 a, test1 b LIMIT 1
|
sl@0
|
539 |
}
|
sl@0
|
540 |
} {a.f1 11 a.f2 22 b.f1 11 b.f2 22}
|
sl@0
|
541 |
do_test select1-6.9.7 {
|
sl@0
|
542 |
set x [execsql2 {
|
sl@0
|
543 |
SELECT * FROM test1 a, (select 5, 6) LIMIT 1
|
sl@0
|
544 |
}]
|
sl@0
|
545 |
regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x
|
sl@0
|
546 |
set x
|
sl@0
|
547 |
} {a.f1 11 a.f2 22 sqlite_subquery.5 5 sqlite_subquery.6 6}
|
sl@0
|
548 |
do_test select1-6.9.8 {
|
sl@0
|
549 |
set x [execsql2 {
|
sl@0
|
550 |
SELECT * FROM test1 a, (select 5 AS x, 6 AS y) AS b LIMIT 1
|
sl@0
|
551 |
}]
|
sl@0
|
552 |
regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x
|
sl@0
|
553 |
set x
|
sl@0
|
554 |
} {a.f1 11 a.f2 22 b.x 5 b.y 6}
|
sl@0
|
555 |
do_test select1-6.9.9 {
|
sl@0
|
556 |
execsql2 {
|
sl@0
|
557 |
SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1
|
sl@0
|
558 |
}
|
sl@0
|
559 |
} {test1.f1 11 test1.f2 22}
|
sl@0
|
560 |
do_test select1-6.9.10 {
|
sl@0
|
561 |
execsql2 {
|
sl@0
|
562 |
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
sl@0
|
563 |
}
|
sl@0
|
564 |
} {test1.f1 11 test2.t1 abc}
|
sl@0
|
565 |
do_test select1-6.9.11 {
|
sl@0
|
566 |
db eval {
|
sl@0
|
567 |
PRAGMA short_column_names=ON;
|
sl@0
|
568 |
PRAGMA full_column_names=ON;
|
sl@0
|
569 |
}
|
sl@0
|
570 |
execsql2 {
|
sl@0
|
571 |
SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1
|
sl@0
|
572 |
}
|
sl@0
|
573 |
} {test1.f1 11 test1.f2 22}
|
sl@0
|
574 |
do_test select1-6.9.12 {
|
sl@0
|
575 |
execsql2 {
|
sl@0
|
576 |
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
sl@0
|
577 |
}
|
sl@0
|
578 |
} {test1.f1 11 test2.t1 abc}
|
sl@0
|
579 |
do_test select1-6.9.13 {
|
sl@0
|
580 |
db eval {
|
sl@0
|
581 |
PRAGMA short_column_names=ON;
|
sl@0
|
582 |
PRAGMA full_column_names=OFF;
|
sl@0
|
583 |
}
|
sl@0
|
584 |
execsql2 {
|
sl@0
|
585 |
SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1
|
sl@0
|
586 |
}
|
sl@0
|
587 |
} {f1 11 f1 11}
|
sl@0
|
588 |
do_test select1-6.9.14 {
|
sl@0
|
589 |
execsql2 {
|
sl@0
|
590 |
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
sl@0
|
591 |
}
|
sl@0
|
592 |
} {f1 11 t1 abc}
|
sl@0
|
593 |
do_test select1-6.9.15 {
|
sl@0
|
594 |
db eval {
|
sl@0
|
595 |
PRAGMA short_column_names=OFF;
|
sl@0
|
596 |
PRAGMA full_column_names=ON;
|
sl@0
|
597 |
}
|
sl@0
|
598 |
execsql2 {
|
sl@0
|
599 |
SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1
|
sl@0
|
600 |
}
|
sl@0
|
601 |
} {test1.f1 11 test1.f1 11}
|
sl@0
|
602 |
do_test select1-6.9.16 {
|
sl@0
|
603 |
execsql2 {
|
sl@0
|
604 |
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
sl@0
|
605 |
}
|
sl@0
|
606 |
} {test1.f1 11 test2.t1 abc}
|
sl@0
|
607 |
|
sl@0
|
608 |
|
sl@0
|
609 |
db eval {
|
sl@0
|
610 |
PRAGMA short_column_names=ON;
|
sl@0
|
611 |
PRAGMA full_column_names=OFF;
|
sl@0
|
612 |
}
|
sl@0
|
613 |
|
sl@0
|
614 |
ifcapable compound {
|
sl@0
|
615 |
do_test select1-6.10 {
|
sl@0
|
616 |
set v [catch {execsql2 {
|
sl@0
|
617 |
SELECT f1 FROM test1 UNION SELECT f2 FROM test1
|
sl@0
|
618 |
ORDER BY f2;
|
sl@0
|
619 |
}} msg]
|
sl@0
|
620 |
lappend v $msg
|
sl@0
|
621 |
} {0 {f1 11 f1 22 f1 33 f1 44}}
|
sl@0
|
622 |
do_test select1-6.11 {
|
sl@0
|
623 |
set v [catch {execsql2 {
|
sl@0
|
624 |
SELECT f1 FROM test1 UNION SELECT f2+100 FROM test1
|
sl@0
|
625 |
ORDER BY f2+101;
|
sl@0
|
626 |
}} msg]
|
sl@0
|
627 |
lappend v $msg
|
sl@0
|
628 |
} {1 {1st ORDER BY term does not match any column in the result set}}
|
sl@0
|
629 |
|
sl@0
|
630 |
# Ticket #2296
|
sl@0
|
631 |
ifcapable subquery&&compound {
|
sl@0
|
632 |
do_test select1-6.20 {
|
sl@0
|
633 |
execsql {
|
sl@0
|
634 |
CREATE TABLE t6(a TEXT, b TEXT);
|
sl@0
|
635 |
INSERT INTO t6 VALUES('a','0');
|
sl@0
|
636 |
INSERT INTO t6 VALUES('b','1');
|
sl@0
|
637 |
INSERT INTO t6 VALUES('c','2');
|
sl@0
|
638 |
INSERT INTO t6 VALUES('d','3');
|
sl@0
|
639 |
SELECT a FROM t6 WHERE b IN
|
sl@0
|
640 |
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
sl@0
|
641 |
ORDER BY 1 LIMIT 1)
|
sl@0
|
642 |
}
|
sl@0
|
643 |
} {a}
|
sl@0
|
644 |
do_test select1-6.21 {
|
sl@0
|
645 |
execsql {
|
sl@0
|
646 |
SELECT a FROM t6 WHERE b IN
|
sl@0
|
647 |
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
sl@0
|
648 |
ORDER BY 1 DESC LIMIT 1)
|
sl@0
|
649 |
}
|
sl@0
|
650 |
} {d}
|
sl@0
|
651 |
do_test select1-6.22 {
|
sl@0
|
652 |
execsql {
|
sl@0
|
653 |
SELECT a FROM t6 WHERE b IN
|
sl@0
|
654 |
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
sl@0
|
655 |
ORDER BY b LIMIT 2)
|
sl@0
|
656 |
ORDER BY a;
|
sl@0
|
657 |
}
|
sl@0
|
658 |
} {a b}
|
sl@0
|
659 |
do_test select1-6.23 {
|
sl@0
|
660 |
execsql {
|
sl@0
|
661 |
SELECT a FROM t6 WHERE b IN
|
sl@0
|
662 |
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
sl@0
|
663 |
ORDER BY x DESC LIMIT 2)
|
sl@0
|
664 |
ORDER BY a;
|
sl@0
|
665 |
}
|
sl@0
|
666 |
} {b d}
|
sl@0
|
667 |
}
|
sl@0
|
668 |
|
sl@0
|
669 |
} ;#ifcapable compound
|
sl@0
|
670 |
|
sl@0
|
671 |
do_test select1-7.1 {
|
sl@0
|
672 |
set v [catch {execsql {
|
sl@0
|
673 |
SELECT f1 FROM test1 WHERE f2=;
|
sl@0
|
674 |
}} msg]
|
sl@0
|
675 |
lappend v $msg
|
sl@0
|
676 |
} {1 {near ";": syntax error}}
|
sl@0
|
677 |
ifcapable compound {
|
sl@0
|
678 |
do_test select1-7.2 {
|
sl@0
|
679 |
set v [catch {execsql {
|
sl@0
|
680 |
SELECT f1 FROM test1 UNION SELECT WHERE;
|
sl@0
|
681 |
}} msg]
|
sl@0
|
682 |
lappend v $msg
|
sl@0
|
683 |
} {1 {near "WHERE": syntax error}}
|
sl@0
|
684 |
} ;# ifcapable compound
|
sl@0
|
685 |
do_test select1-7.3 {
|
sl@0
|
686 |
set v [catch {execsql {SELECT f1 FROM test1 as 'hi', test2 as}} msg]
|
sl@0
|
687 |
lappend v $msg
|
sl@0
|
688 |
} {1 {near "as": syntax error}}
|
sl@0
|
689 |
do_test select1-7.4 {
|
sl@0
|
690 |
set v [catch {execsql {
|
sl@0
|
691 |
SELECT f1 FROM test1 ORDER BY;
|
sl@0
|
692 |
}} msg]
|
sl@0
|
693 |
lappend v $msg
|
sl@0
|
694 |
} {1 {near ";": syntax error}}
|
sl@0
|
695 |
do_test select1-7.5 {
|
sl@0
|
696 |
set v [catch {execsql {
|
sl@0
|
697 |
SELECT f1 FROM test1 ORDER BY f1 desc, f2 where;
|
sl@0
|
698 |
}} msg]
|
sl@0
|
699 |
lappend v $msg
|
sl@0
|
700 |
} {1 {near "where": syntax error}}
|
sl@0
|
701 |
do_test select1-7.6 {
|
sl@0
|
702 |
set v [catch {execsql {
|
sl@0
|
703 |
SELECT count(f1,f2 FROM test1;
|
sl@0
|
704 |
}} msg]
|
sl@0
|
705 |
lappend v $msg
|
sl@0
|
706 |
} {1 {near "FROM": syntax error}}
|
sl@0
|
707 |
do_test select1-7.7 {
|
sl@0
|
708 |
set v [catch {execsql {
|
sl@0
|
709 |
SELECT count(f1,f2+) FROM test1;
|
sl@0
|
710 |
}} msg]
|
sl@0
|
711 |
lappend v $msg
|
sl@0
|
712 |
} {1 {near ")": syntax error}}
|
sl@0
|
713 |
do_test select1-7.8 {
|
sl@0
|
714 |
set v [catch {execsql {
|
sl@0
|
715 |
SELECT f1 FROM test1 ORDER BY f2, f1+;
|
sl@0
|
716 |
}} msg]
|
sl@0
|
717 |
lappend v $msg
|
sl@0
|
718 |
} {1 {near ";": syntax error}}
|
sl@0
|
719 |
do_test select1-7.9 {
|
sl@0
|
720 |
catchsql {
|
sl@0
|
721 |
SELECT f1 FROM test1 LIMIT 5+3 OFFSET 11 ORDER BY f2;
|
sl@0
|
722 |
}
|
sl@0
|
723 |
} {1 {near "ORDER": syntax error}}
|
sl@0
|
724 |
|
sl@0
|
725 |
do_test select1-8.1 {
|
sl@0
|
726 |
execsql {SELECT f1 FROM test1 WHERE 4.3+2.4 OR 1 ORDER BY f1}
|
sl@0
|
727 |
} {11 33}
|
sl@0
|
728 |
do_test select1-8.2 {
|
sl@0
|
729 |
execsql {
|
sl@0
|
730 |
SELECT f1 FROM test1 WHERE ('x' || f1) BETWEEN 'x10' AND 'x20'
|
sl@0
|
731 |
ORDER BY f1
|
sl@0
|
732 |
}
|
sl@0
|
733 |
} {11}
|
sl@0
|
734 |
do_test select1-8.3 {
|
sl@0
|
735 |
execsql {
|
sl@0
|
736 |
SELECT f1 FROM test1 WHERE 5-3==2
|
sl@0
|
737 |
ORDER BY f1
|
sl@0
|
738 |
}
|
sl@0
|
739 |
} {11 33}
|
sl@0
|
740 |
|
sl@0
|
741 |
# TODO: This test is failing because f1 is now being loaded off the
|
sl@0
|
742 |
# disk as a vdbe integer, not a string. Hence the value of f1/(f1-11)
|
sl@0
|
743 |
# changes because of rounding. Disable the test for now.
|
sl@0
|
744 |
if 0 {
|
sl@0
|
745 |
do_test select1-8.4 {
|
sl@0
|
746 |
execsql {
|
sl@0
|
747 |
SELECT coalesce(f1/(f1-11),'x'),
|
sl@0
|
748 |
coalesce(min(f1/(f1-11),5),'y'),
|
sl@0
|
749 |
coalesce(max(f1/(f1-33),6),'z')
|
sl@0
|
750 |
FROM test1 ORDER BY f1
|
sl@0
|
751 |
}
|
sl@0
|
752 |
} {x y 6 1.5 1.5 z}
|
sl@0
|
753 |
}
|
sl@0
|
754 |
do_test select1-8.5 {
|
sl@0
|
755 |
execsql {
|
sl@0
|
756 |
SELECT min(1,2,3), -max(1,2,3)
|
sl@0
|
757 |
FROM test1 ORDER BY f1
|
sl@0
|
758 |
}
|
sl@0
|
759 |
} {1 -3 1 -3}
|
sl@0
|
760 |
|
sl@0
|
761 |
|
sl@0
|
762 |
# Check the behavior when the result set is empty
|
sl@0
|
763 |
#
|
sl@0
|
764 |
# SQLite v3 always sets r(*).
|
sl@0
|
765 |
#
|
sl@0
|
766 |
# do_test select1-9.1 {
|
sl@0
|
767 |
# catch {unset r}
|
sl@0
|
768 |
# set r(*) {}
|
sl@0
|
769 |
# db eval {SELECT * FROM test1 WHERE f1<0} r {}
|
sl@0
|
770 |
# set r(*)
|
sl@0
|
771 |
# } {}
|
sl@0
|
772 |
do_test select1-9.2 {
|
sl@0
|
773 |
execsql {PRAGMA empty_result_callbacks=on}
|
sl@0
|
774 |
catch {unset r}
|
sl@0
|
775 |
set r(*) {}
|
sl@0
|
776 |
db eval {SELECT * FROM test1 WHERE f1<0} r {}
|
sl@0
|
777 |
set r(*)
|
sl@0
|
778 |
} {f1 f2}
|
sl@0
|
779 |
ifcapable subquery {
|
sl@0
|
780 |
do_test select1-9.3 {
|
sl@0
|
781 |
set r(*) {}
|
sl@0
|
782 |
db eval {SELECT * FROM test1 WHERE f1<(select count(*) from test2)} r {}
|
sl@0
|
783 |
set r(*)
|
sl@0
|
784 |
} {f1 f2}
|
sl@0
|
785 |
}
|
sl@0
|
786 |
do_test select1-9.4 {
|
sl@0
|
787 |
set r(*) {}
|
sl@0
|
788 |
db eval {SELECT * FROM test1 ORDER BY f1} r {}
|
sl@0
|
789 |
set r(*)
|
sl@0
|
790 |
} {f1 f2}
|
sl@0
|
791 |
do_test select1-9.5 {
|
sl@0
|
792 |
set r(*) {}
|
sl@0
|
793 |
db eval {SELECT * FROM test1 WHERE f1<0 ORDER BY f1} r {}
|
sl@0
|
794 |
set r(*)
|
sl@0
|
795 |
} {f1 f2}
|
sl@0
|
796 |
unset r
|
sl@0
|
797 |
|
sl@0
|
798 |
# Check for ORDER BY clauses that refer to an AS name in the column list
|
sl@0
|
799 |
#
|
sl@0
|
800 |
do_test select1-10.1 {
|
sl@0
|
801 |
execsql {
|
sl@0
|
802 |
SELECT f1 AS x FROM test1 ORDER BY x
|
sl@0
|
803 |
}
|
sl@0
|
804 |
} {11 33}
|
sl@0
|
805 |
do_test select1-10.2 {
|
sl@0
|
806 |
execsql {
|
sl@0
|
807 |
SELECT f1 AS x FROM test1 ORDER BY -x
|
sl@0
|
808 |
}
|
sl@0
|
809 |
} {33 11}
|
sl@0
|
810 |
do_test select1-10.3 {
|
sl@0
|
811 |
execsql {
|
sl@0
|
812 |
SELECT f1-23 AS x FROM test1 ORDER BY abs(x)
|
sl@0
|
813 |
}
|
sl@0
|
814 |
} {10 -12}
|
sl@0
|
815 |
do_test select1-10.4 {
|
sl@0
|
816 |
execsql {
|
sl@0
|
817 |
SELECT f1-23 AS x FROM test1 ORDER BY -abs(x)
|
sl@0
|
818 |
}
|
sl@0
|
819 |
} {-12 10}
|
sl@0
|
820 |
do_test select1-10.5 {
|
sl@0
|
821 |
execsql {
|
sl@0
|
822 |
SELECT f1-22 AS x, f2-22 as y FROM test1
|
sl@0
|
823 |
}
|
sl@0
|
824 |
} {-11 0 11 22}
|
sl@0
|
825 |
do_test select1-10.6 {
|
sl@0
|
826 |
execsql {
|
sl@0
|
827 |
SELECT f1-22 AS x, f2-22 as y FROM test1 WHERE x>0 AND y<50
|
sl@0
|
828 |
}
|
sl@0
|
829 |
} {11 22}
|
sl@0
|
830 |
do_test select1-10.7 {
|
sl@0
|
831 |
execsql {
|
sl@0
|
832 |
SELECT f1 COLLATE nocase AS x FROM test1 ORDER BY x
|
sl@0
|
833 |
}
|
sl@0
|
834 |
} {11 33}
|
sl@0
|
835 |
|
sl@0
|
836 |
# Check the ability to specify "TABLE.*" in the result set of a SELECT
|
sl@0
|
837 |
#
|
sl@0
|
838 |
do_test select1-11.1 {
|
sl@0
|
839 |
execsql {
|
sl@0
|
840 |
DELETE FROM t3;
|
sl@0
|
841 |
DELETE FROM t4;
|
sl@0
|
842 |
INSERT INTO t3 VALUES(1,2);
|
sl@0
|
843 |
INSERT INTO t4 VALUES(3,4);
|
sl@0
|
844 |
SELECT * FROM t3, t4;
|
sl@0
|
845 |
}
|
sl@0
|
846 |
} {1 2 3 4}
|
sl@0
|
847 |
do_test select1-11.2.1 {
|
sl@0
|
848 |
execsql {
|
sl@0
|
849 |
SELECT * FROM t3, t4;
|
sl@0
|
850 |
}
|
sl@0
|
851 |
} {1 2 3 4}
|
sl@0
|
852 |
do_test select1-11.2.2 {
|
sl@0
|
853 |
execsql2 {
|
sl@0
|
854 |
SELECT * FROM t3, t4;
|
sl@0
|
855 |
}
|
sl@0
|
856 |
} {a 3 b 4 a 3 b 4}
|
sl@0
|
857 |
do_test select1-11.4.1 {
|
sl@0
|
858 |
execsql {
|
sl@0
|
859 |
SELECT t3.*, t4.b FROM t3, t4;
|
sl@0
|
860 |
}
|
sl@0
|
861 |
} {1 2 4}
|
sl@0
|
862 |
do_test select1-11.4.2 {
|
sl@0
|
863 |
execsql {
|
sl@0
|
864 |
SELECT "t3".*, t4.b FROM t3, t4;
|
sl@0
|
865 |
}
|
sl@0
|
866 |
} {1 2 4}
|
sl@0
|
867 |
do_test select1-11.5.1 {
|
sl@0
|
868 |
execsql2 {
|
sl@0
|
869 |
SELECT t3.*, t4.b FROM t3, t4;
|
sl@0
|
870 |
}
|
sl@0
|
871 |
} {a 1 b 4 b 4}
|
sl@0
|
872 |
do_test select1-11.6 {
|
sl@0
|
873 |
execsql2 {
|
sl@0
|
874 |
SELECT x.*, y.b FROM t3 AS x, t4 AS y;
|
sl@0
|
875 |
}
|
sl@0
|
876 |
} {a 1 b 4 b 4}
|
sl@0
|
877 |
do_test select1-11.7 {
|
sl@0
|
878 |
execsql {
|
sl@0
|
879 |
SELECT t3.b, t4.* FROM t3, t4;
|
sl@0
|
880 |
}
|
sl@0
|
881 |
} {2 3 4}
|
sl@0
|
882 |
do_test select1-11.8 {
|
sl@0
|
883 |
execsql2 {
|
sl@0
|
884 |
SELECT t3.b, t4.* FROM t3, t4;
|
sl@0
|
885 |
}
|
sl@0
|
886 |
} {b 4 a 3 b 4}
|
sl@0
|
887 |
do_test select1-11.9 {
|
sl@0
|
888 |
execsql2 {
|
sl@0
|
889 |
SELECT x.b, y.* FROM t3 AS x, t4 AS y;
|
sl@0
|
890 |
}
|
sl@0
|
891 |
} {b 4 a 3 b 4}
|
sl@0
|
892 |
do_test select1-11.10 {
|
sl@0
|
893 |
catchsql {
|
sl@0
|
894 |
SELECT t5.* FROM t3, t4;
|
sl@0
|
895 |
}
|
sl@0
|
896 |
} {1 {no such table: t5}}
|
sl@0
|
897 |
do_test select1-11.11 {
|
sl@0
|
898 |
catchsql {
|
sl@0
|
899 |
SELECT t3.* FROM t3 AS x, t4;
|
sl@0
|
900 |
}
|
sl@0
|
901 |
} {1 {no such table: t3}}
|
sl@0
|
902 |
ifcapable subquery {
|
sl@0
|
903 |
do_test select1-11.12 {
|
sl@0
|
904 |
execsql2 {
|
sl@0
|
905 |
SELECT t3.* FROM t3, (SELECT max(a), max(b) FROM t4)
|
sl@0
|
906 |
}
|
sl@0
|
907 |
} {a 1 b 2}
|
sl@0
|
908 |
do_test select1-11.13 {
|
sl@0
|
909 |
execsql2 {
|
sl@0
|
910 |
SELECT t3.* FROM (SELECT max(a), max(b) FROM t4), t3
|
sl@0
|
911 |
}
|
sl@0
|
912 |
} {a 1 b 2}
|
sl@0
|
913 |
do_test select1-11.14 {
|
sl@0
|
914 |
execsql2 {
|
sl@0
|
915 |
SELECT * FROM t3, (SELECT max(a), max(b) FROM t4) AS 'tx'
|
sl@0
|
916 |
}
|
sl@0
|
917 |
} {a 1 b 2 max(a) 3 max(b) 4}
|
sl@0
|
918 |
do_test select1-11.15 {
|
sl@0
|
919 |
execsql2 {
|
sl@0
|
920 |
SELECT y.*, t3.* FROM t3, (SELECT max(a), max(b) FROM t4) AS y
|
sl@0
|
921 |
}
|
sl@0
|
922 |
} {max(a) 3 max(b) 4 a 1 b 2}
|
sl@0
|
923 |
}
|
sl@0
|
924 |
do_test select1-11.16 {
|
sl@0
|
925 |
execsql2 {
|
sl@0
|
926 |
SELECT y.* FROM t3 as y, t4 as z
|
sl@0
|
927 |
}
|
sl@0
|
928 |
} {a 1 b 2}
|
sl@0
|
929 |
|
sl@0
|
930 |
# Tests of SELECT statements without a FROM clause.
|
sl@0
|
931 |
#
|
sl@0
|
932 |
do_test select1-12.1 {
|
sl@0
|
933 |
execsql2 {
|
sl@0
|
934 |
SELECT 1+2+3
|
sl@0
|
935 |
}
|
sl@0
|
936 |
} {1+2+3 6}
|
sl@0
|
937 |
do_test select1-12.2 {
|
sl@0
|
938 |
execsql2 {
|
sl@0
|
939 |
SELECT 1,'hello',2
|
sl@0
|
940 |
}
|
sl@0
|
941 |
} {1 1 'hello' hello 2 2}
|
sl@0
|
942 |
do_test select1-12.3 {
|
sl@0
|
943 |
execsql2 {
|
sl@0
|
944 |
SELECT 1 AS 'a','hello' AS 'b',2 AS 'c'
|
sl@0
|
945 |
}
|
sl@0
|
946 |
} {a 1 b hello c 2}
|
sl@0
|
947 |
do_test select1-12.4 {
|
sl@0
|
948 |
execsql {
|
sl@0
|
949 |
DELETE FROM t3;
|
sl@0
|
950 |
INSERT INTO t3 VALUES(1,2);
|
sl@0
|
951 |
}
|
sl@0
|
952 |
} {}
|
sl@0
|
953 |
|
sl@0
|
954 |
ifcapable compound {
|
sl@0
|
955 |
do_test select1-12.5 {
|
sl@0
|
956 |
execsql {
|
sl@0
|
957 |
SELECT * FROM t3 UNION SELECT 3 AS 'a', 4 ORDER BY a;
|
sl@0
|
958 |
}
|
sl@0
|
959 |
} {1 2 3 4}
|
sl@0
|
960 |
|
sl@0
|
961 |
do_test select1-12.6 {
|
sl@0
|
962 |
execsql {
|
sl@0
|
963 |
SELECT 3, 4 UNION SELECT * FROM t3;
|
sl@0
|
964 |
}
|
sl@0
|
965 |
} {1 2 3 4}
|
sl@0
|
966 |
} ;# ifcapable compound
|
sl@0
|
967 |
|
sl@0
|
968 |
ifcapable subquery {
|
sl@0
|
969 |
do_test select1-12.7 {
|
sl@0
|
970 |
execsql {
|
sl@0
|
971 |
SELECT * FROM t3 WHERE a=(SELECT 1);
|
sl@0
|
972 |
}
|
sl@0
|
973 |
} {1 2}
|
sl@0
|
974 |
do_test select1-12.8 {
|
sl@0
|
975 |
execsql {
|
sl@0
|
976 |
SELECT * FROM t3 WHERE a=(SELECT 2);
|
sl@0
|
977 |
}
|
sl@0
|
978 |
} {}
|
sl@0
|
979 |
}
|
sl@0
|
980 |
|
sl@0
|
981 |
ifcapable {compound && subquery} {
|
sl@0
|
982 |
do_test select1-12.9 {
|
sl@0
|
983 |
execsql2 {
|
sl@0
|
984 |
SELECT x FROM (
|
sl@0
|
985 |
SELECT a AS x, b AS y FROM t3 UNION SELECT a,b FROM t4 ORDER BY a,b
|
sl@0
|
986 |
) ORDER BY x;
|
sl@0
|
987 |
}
|
sl@0
|
988 |
} {x 1 x 3}
|
sl@0
|
989 |
do_test select1-12.10 {
|
sl@0
|
990 |
execsql2 {
|
sl@0
|
991 |
SELECT z.x FROM (
|
sl@0
|
992 |
SELECT a AS x,b AS y FROM t3 UNION SELECT a, b FROM t4 ORDER BY a,b
|
sl@0
|
993 |
) AS 'z' ORDER BY x;
|
sl@0
|
994 |
}
|
sl@0
|
995 |
} {x 1 x 3}
|
sl@0
|
996 |
} ;# ifcapable compound
|
sl@0
|
997 |
|
sl@0
|
998 |
|
sl@0
|
999 |
# Check for a VDBE stack growth problem that existed at one point.
|
sl@0
|
1000 |
#
|
sl@0
|
1001 |
ifcapable subquery {
|
sl@0
|
1002 |
do_test select1-13.1 {
|
sl@0
|
1003 |
execsql {
|
sl@0
|
1004 |
BEGIN;
|
sl@0
|
1005 |
create TABLE abc(a, b, c, PRIMARY KEY(a, b));
|
sl@0
|
1006 |
INSERT INTO abc VALUES(1, 1, 1);
|
sl@0
|
1007 |
}
|
sl@0
|
1008 |
for {set i 0} {$i<10} {incr i} {
|
sl@0
|
1009 |
execsql {
|
sl@0
|
1010 |
INSERT INTO abc SELECT a+(select max(a) FROM abc),
|
sl@0
|
1011 |
b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc;
|
sl@0
|
1012 |
}
|
sl@0
|
1013 |
}
|
sl@0
|
1014 |
execsql {COMMIT}
|
sl@0
|
1015 |
|
sl@0
|
1016 |
# This used to seg-fault when the problem existed.
|
sl@0
|
1017 |
execsql {
|
sl@0
|
1018 |
SELECT count(
|
sl@0
|
1019 |
(SELECT a FROM abc WHERE a = NULL AND b >= upper.c)
|
sl@0
|
1020 |
) FROM abc AS upper;
|
sl@0
|
1021 |
}
|
sl@0
|
1022 |
} {0}
|
sl@0
|
1023 |
}
|
sl@0
|
1024 |
|
sl@0
|
1025 |
db close
|
sl@0
|
1026 |
file delete -force test.db
|
sl@0
|
1027 |
sqlite3 db test.db
|
sl@0
|
1028 |
do_test select1-14.1 {
|
sl@0
|
1029 |
execsql {
|
sl@0
|
1030 |
SELECT * FROM sqlite_master WHERE rowid>10;
|
sl@0
|
1031 |
SELECT * FROM sqlite_master WHERE rowid=10;
|
sl@0
|
1032 |
SELECT * FROM sqlite_master WHERE rowid<10;
|
sl@0
|
1033 |
SELECT * FROM sqlite_master WHERE rowid<=10;
|
sl@0
|
1034 |
SELECT * FROM sqlite_master WHERE rowid>=10;
|
sl@0
|
1035 |
SELECT * FROM sqlite_master;
|
sl@0
|
1036 |
}
|
sl@0
|
1037 |
} {}
|
sl@0
|
1038 |
do_test select1-14.2 {
|
sl@0
|
1039 |
execsql {
|
sl@0
|
1040 |
SELECT 10 IN (SELECT rowid FROM sqlite_master);
|
sl@0
|
1041 |
}
|
sl@0
|
1042 |
} {0}
|
sl@0
|
1043 |
|
sl@0
|
1044 |
finish_test
|