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