2001-09-16 04:13:26 +04:00
|
|
|
# 2001 September 15
|
2000-05-31 21:59:25 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
2000-05-31 21:59:25 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
2000-05-31 21:59:25 +04:00
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library. The
|
|
|
|
# focus of this file is testing the SELECT statement.
|
|
|
|
#
|
2009-05-28 05:00:55 +04:00
|
|
|
# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $
|
2000-05-31 21:59:25 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
# Try to select on a non-existant table.
|
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT * FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {no such table: test1}}
|
|
|
|
|
2005-12-15 13:11:30 +03:00
|
|
|
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {CREATE TABLE test1(f1 int, f2 int)}
|
|
|
|
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.2 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT * FROM test1, test2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {no such table: test2}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.3 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT * FROM test2, test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {no such table: test2}}
|
|
|
|
|
|
|
|
execsql {INSERT INTO test1(f1,f2) VALUES(11,22)}
|
|
|
|
|
|
|
|
|
2000-06-21 17:59:10 +04:00
|
|
|
# Make sure the columns are extracted correctly.
|
2000-05-31 21:59:25 +04:00
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.4 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT f1 FROM test1}
|
|
|
|
} {11}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.5 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT f2 FROM test1}
|
|
|
|
} {22}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.6 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT f2, f1 FROM test1}
|
|
|
|
} {22 11}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.7 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT f1, f2 FROM test1}
|
|
|
|
} {11 22}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.8 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT * FROM test1}
|
|
|
|
} {11 22}
|
2001-12-16 23:05:05 +03:00
|
|
|
do_test select1-1.8.1 {
|
|
|
|
execsql {SELECT *, * FROM test1}
|
|
|
|
} {11 22 11 22}
|
|
|
|
do_test select1-1.8.2 {
|
|
|
|
execsql {SELECT *, min(f1,f2), max(f1,f2) FROM test1}
|
|
|
|
} {11 22 11 22}
|
|
|
|
do_test select1-1.8.3 {
|
|
|
|
execsql {SELECT 'one', *, 'two', * FROM test1}
|
|
|
|
} {one 11 22 two 11 22}
|
2000-05-31 21:59:25 +04:00
|
|
|
|
|
|
|
execsql {CREATE TABLE test2(r1 real, r2 real)}
|
|
|
|
execsql {INSERT INTO test2(r1,r2) VALUES(1.1,2.2)}
|
|
|
|
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.9 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT * FROM test1, test2}
|
|
|
|
} {11 22 1.1 2.2}
|
2001-12-16 23:05:05 +03:00
|
|
|
do_test select1-1.9.1 {
|
|
|
|
execsql {SELECT *, 'hi' FROM test1, test2}
|
|
|
|
} {11 22 1.1 2.2 hi}
|
|
|
|
do_test select1-1.9.2 {
|
|
|
|
execsql {SELECT 'one', *, 'two', * FROM test1, test2}
|
|
|
|
} {one 11 22 1.1 2.2 two 11 22 1.1 2.2}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.10 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT test1.f1, test2.r1 FROM test1, test2}
|
|
|
|
} {11 1.1}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.11 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT test1.f1, test2.r1 FROM test2, test1}
|
|
|
|
} {11 1.1}
|
2001-11-06 17:10:41 +03:00
|
|
|
do_test select1-1.11.1 {
|
|
|
|
execsql {SELECT * FROM test2, test1}
|
|
|
|
} {1.1 2.2 11 22}
|
|
|
|
do_test select1-1.11.2 {
|
|
|
|
execsql {SELECT * FROM test1 AS a, test1 AS b}
|
|
|
|
} {11 22 11 22}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.12 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT max(test1.f1,test2.r1), min(test1.f2,test2.r2)
|
|
|
|
FROM test2, test1}
|
|
|
|
} {11 2.2}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-1.13 {
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {SELECT min(test1.f1,test2.r1), max(test1.f2,test2.r2)
|
|
|
|
FROM test1, test2}
|
|
|
|
} {1.1 22}
|
|
|
|
|
2002-03-02 20:04:07 +03:00
|
|
|
set long {This is a string that is too big to fit inside a NBFS buffer}
|
|
|
|
do_test select1-2.0 {
|
|
|
|
execsql "
|
|
|
|
DROP TABLE test2;
|
|
|
|
DELETE FROM test1;
|
|
|
|
INSERT INTO test1 VALUES(11,22);
|
|
|
|
INSERT INTO test1 VALUES(33,44);
|
|
|
|
CREATE TABLE t3(a,b);
|
|
|
|
INSERT INTO t3 VALUES('abc',NULL);
|
|
|
|
INSERT INTO t3 VALUES(NULL,'xyz');
|
|
|
|
INSERT INTO t3 SELECT * FROM test1;
|
|
|
|
CREATE TABLE t4(a,b);
|
|
|
|
INSERT INTO t4 VALUES(NULL,'$long');
|
|
|
|
SELECT * FROM t3;
|
|
|
|
"
|
|
|
|
} {abc {} {} xyz 11 22 33 44}
|
2000-05-31 21:59:25 +04:00
|
|
|
|
|
|
|
# Error messges from sqliteExprCheck
|
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:04:48 +03:00
|
|
|
} {1 {wrong number of arguments to function count()}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.2 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT count(f1) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 2}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.3 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT Count() FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 2}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.4 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT COUNT(*) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 2}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.5 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT COUNT(*)+1 FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2000-06-06 21:27:05 +04:00
|
|
|
} {0 3}
|
2002-03-02 20:04:07 +03:00
|
|
|
do_test select1-2.5.1 {
|
|
|
|
execsql {SELECT count(*),count(a),count(b) FROM t3}
|
|
|
|
} {4 3 3}
|
|
|
|
do_test select1-2.5.2 {
|
|
|
|
execsql {SELECT count(*),count(a),count(b) FROM t4}
|
|
|
|
} {1 0 1}
|
|
|
|
do_test select1-2.5.3 {
|
|
|
|
execsql {SELECT count(*),count(a),count(b) FROM t4 WHERE b=5}
|
|
|
|
} {0 0 0}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.6 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT min(*) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:14:18 +03:00
|
|
|
} {1 {wrong number of arguments to function min()}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.7 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT Min(f1) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 11}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.8 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 {11 33}}
|
2002-03-02 20:04:07 +03:00
|
|
|
do_test select1-2.8.1 {
|
|
|
|
execsql {SELECT coalesce(min(a),'xyzzy') FROM t3}
|
2004-07-19 00:52:32 +04:00
|
|
|
} {11}
|
2002-03-02 20:04:07 +03:00
|
|
|
do_test select1-2.8.2 {
|
|
|
|
execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3}
|
|
|
|
} {11}
|
|
|
|
do_test select1-2.8.3 {
|
|
|
|
execsql {SELECT min(b), min(b) FROM t4}
|
|
|
|
} [list $long $long]
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.9 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT MAX(*) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:14:18 +03:00
|
|
|
} {1 {wrong number of arguments to function MAX()}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.10 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT Max(f1) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 33}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.11 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT max(f1,f2) FROM test1}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 {22 44}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.12 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT MAX(f1,f2)+1 FROM test1}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 {23 45}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.13 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT MAX(f1)+1 FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2000-06-06 21:27:05 +04:00
|
|
|
} {0 34}
|
2002-03-02 20:04:07 +03:00
|
|
|
do_test select1-2.13.1 {
|
|
|
|
execsql {SELECT coalesce(max(a),'xyzzy') FROM t3}
|
2002-05-30 03:22:23 +04:00
|
|
|
} {abc}
|
2002-05-27 05:04:51 +04:00
|
|
|
do_test select1-2.13.2 {
|
2002-03-02 20:04:07 +03:00
|
|
|
execsql {SELECT max(coalesce(a,'xyzzy')) FROM t3}
|
|
|
|
} {xyzzy}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.14 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT SUM(*) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:04:48 +03:00
|
|
|
} {1 {wrong number of arguments to function SUM()}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.15 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2005-09-08 14:37:01 +04:00
|
|
|
} {0 44}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.16 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:04:48 +03:00
|
|
|
} {1 {wrong number of arguments to function sum()}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.17 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2005-09-08 14:37:01 +04:00
|
|
|
} {0 45}
|
2002-03-02 20:04:07 +03:00
|
|
|
do_test select1-2.17.1 {
|
|
|
|
execsql {SELECT sum(a) FROM t3}
|
2006-02-10 01:13:41 +03:00
|
|
|
} {44.0}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.18 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {no such function: XYZZY}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.19 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2005-09-08 14:37:01 +04:00
|
|
|
} {0 44}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-2.20 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg]
|
|
|
|
lappend v $msg
|
2002-02-24 02:45:45 +03:00
|
|
|
} {1 {misuse of aggregate function min()}}
|
2000-05-31 21:59:25 +04:00
|
|
|
|
2007-07-24 02:51:15 +04:00
|
|
|
# Ticket #2526
|
|
|
|
#
|
|
|
|
do_test select1-2.21 {
|
|
|
|
catchsql {
|
|
|
|
SELECT min(f1) AS m FROM test1 GROUP BY f1 HAVING max(m+5)<10
|
|
|
|
}
|
|
|
|
} {1 {misuse of aliased aggregate m}}
|
|
|
|
do_test select1-2.22 {
|
|
|
|
catchsql {
|
|
|
|
SELECT coalesce(min(f1)+5,11) AS m FROM test1
|
|
|
|
GROUP BY f1
|
|
|
|
HAVING max(m+5)<10
|
|
|
|
}
|
|
|
|
} {1 {misuse of aliased aggregate m}}
|
|
|
|
do_test select1-2.23 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE tkt2526(a,b,c PRIMARY KEY);
|
|
|
|
INSERT INTO tkt2526 VALUES('x','y',NULL);
|
|
|
|
INSERT INTO tkt2526 VALUES('x','z',NULL);
|
|
|
|
}
|
|
|
|
catchsql {
|
|
|
|
SELECT count(a) AS cn FROM tkt2526 GROUP BY a HAVING cn<max(cn)
|
|
|
|
}
|
|
|
|
} {1 {misuse of aliased aggregate cn}}
|
|
|
|
|
2000-05-31 21:59:25 +04:00
|
|
|
# WHERE clause expressions
|
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<11}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.2 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<=11}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 11}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.3 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1=11}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 11}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.4 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>=11}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 {11 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.5 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>11}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 33}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.6 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE f1!=11}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 33}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.7 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE min(f1,f2)!=11}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 33}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.8 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE max(f1,f2)!=11}} msg]
|
|
|
|
lappend v [lsort $msg]
|
|
|
|
} {0 {11 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-3.9 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg]
|
|
|
|
lappend v $msg
|
2002-02-28 06:04:48 +03:00
|
|
|
} {1 {wrong number of arguments to function count()}}
|
2000-05-31 21:59:25 +04:00
|
|
|
|
|
|
|
# ORDER BY expressions
|
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-4.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY f1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {11 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-4.2 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY -f1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {33 11}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-4.3 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1,f2)}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {11 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-4.4 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg]
|
|
|
|
lappend v $msg
|
2009-05-27 14:31:29 +04:00
|
|
|
} {1 {misuse of aggregate: min()}}
|
2006-04-11 18:16:21 +04:00
|
|
|
|
|
|
|
# The restriction not allowing constants in the ORDER BY clause
|
|
|
|
# has been removed. See ticket #1768
|
|
|
|
#do_test select1-4.5 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY 8.4;
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
#do_test select1-4.6 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY '8.4';
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
#do_test select1-4.7.1 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY 'xyz';
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
#do_test select1-4.7.2 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY -8.4;
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
#do_test select1-4.7.3 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY +8.4;
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
#do_test select1-4.7.4 {
|
|
|
|
# catchsql {
|
|
|
|
# SELECT f1 FROM test1 ORDER BY 4294967296; -- constant larger than 32 bits
|
|
|
|
# }
|
|
|
|
#} {1 {ORDER BY terms must not be non-integer constants}}
|
|
|
|
|
2002-01-22 17:11:29 +03:00
|
|
|
do_test select1-4.5 {
|
2006-04-11 18:16:21 +04:00
|
|
|
execsql {
|
|
|
|
SELECT f1 FROM test1 ORDER BY 8.4
|
2002-01-22 17:11:29 +03:00
|
|
|
}
|
2006-04-11 18:16:21 +04:00
|
|
|
} {11 33}
|
2002-06-02 20:09:01 +04:00
|
|
|
do_test select1-4.6 {
|
2006-04-11 18:16:21 +04:00
|
|
|
execsql {
|
|
|
|
SELECT f1 FROM test1 ORDER BY '8.4'
|
2005-01-15 04:52:31 +03:00
|
|
|
}
|
2006-04-11 18:16:21 +04:00
|
|
|
} {11 33}
|
|
|
|
|
2002-06-02 20:09:01 +04:00
|
|
|
do_test select1-4.8 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t5(a,b);
|
|
|
|
INSERT INTO t5 VALUES(1,10);
|
|
|
|
INSERT INTO t5 VALUES(2,9);
|
|
|
|
SELECT * FROM t5 ORDER BY 1;
|
|
|
|
}
|
|
|
|
} {1 10 2 9}
|
2005-01-15 04:52:31 +03:00
|
|
|
do_test select1-4.9.1 {
|
2002-06-02 20:09:01 +04:00
|
|
|
execsql {
|
|
|
|
SELECT * FROM t5 ORDER BY 2;
|
|
|
|
}
|
|
|
|
} {2 9 1 10}
|
2005-01-15 04:52:31 +03:00
|
|
|
do_test select1-4.9.2 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t5 ORDER BY +2;
|
|
|
|
}
|
|
|
|
} {2 9 1 10}
|
|
|
|
do_test select1-4.10.1 {
|
2002-06-02 20:09:01 +04:00
|
|
|
catchsql {
|
|
|
|
SELECT * FROM t5 ORDER BY 3;
|
|
|
|
}
|
2007-12-13 10:58:50 +03:00
|
|
|
} {1 {1st ORDER BY term out of range - should be between 1 and 2}}
|
2005-01-15 04:52:31 +03:00
|
|
|
do_test select1-4.10.2 {
|
|
|
|
catchsql {
|
|
|
|
SELECT * FROM t5 ORDER BY -1;
|
|
|
|
}
|
2007-12-13 10:58:50 +03:00
|
|
|
} {1 {1st ORDER BY term out of range - should be between 1 and 2}}
|
2002-06-02 20:09:01 +04:00
|
|
|
do_test select1-4.11 {
|
|
|
|
execsql {
|
|
|
|
INSERT INTO t5 VALUES(3,10);
|
|
|
|
SELECT * FROM t5 ORDER BY 2, 1 DESC;
|
|
|
|
}
|
|
|
|
} {2 9 3 10 1 10}
|
|
|
|
do_test select1-4.12 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t5 ORDER BY 1 DESC, b;
|
|
|
|
}
|
|
|
|
} {3 10 2 9 1 10}
|
|
|
|
do_test select1-4.13 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t5 ORDER BY b DESC, 1;
|
|
|
|
}
|
|
|
|
} {1 10 3 10 2 9}
|
|
|
|
|
2000-05-31 21:59:25 +04:00
|
|
|
|
|
|
|
# ORDER BY ignored on an aggregate query
|
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-5.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql {SELECT max(f1) FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 33}
|
|
|
|
|
2008-07-15 04:27:34 +04:00
|
|
|
execsql {CREATE TABLE test2(t1 text, t2 text)}
|
2000-05-31 21:59:25 +04:00
|
|
|
execsql {INSERT INTO test2 VALUES('abc','xyz')}
|
|
|
|
|
2000-06-21 17:59:10 +04:00
|
|
|
# Check for column naming
|
2000-05-31 21:59:25 +04:00
|
|
|
#
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.1 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {f1 11 f1 33}}
|
2001-10-06 20:33:02 +04:00
|
|
|
do_test select1-6.1.1 {
|
2006-03-14 16:10:42 +03:00
|
|
|
db eval {PRAGMA full_column_names=on}
|
2001-10-06 20:33:02 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2001-10-15 04:44:35 +04:00
|
|
|
} {0 {test1.f1 11 test1.f1 33}}
|
2001-10-06 20:33:02 +04:00
|
|
|
do_test select1-6.1.2 {
|
2001-10-15 04:44:35 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1 as 'f1' FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {f1 11 f1 33}}
|
|
|
|
do_test select1-6.1.3 {
|
2001-10-06 20:33:02 +04:00
|
|
|
set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
|
|
|
|
lappend v $msg
|
2005-01-18 20:20:10 +03:00
|
|
|
} {0 {f1 11 f2 22}}
|
2001-10-15 04:44:35 +04:00
|
|
|
do_test select1-6.1.4 {
|
2001-10-18 16:34:46 +04:00
|
|
|
set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
|
2006-03-14 16:10:42 +03:00
|
|
|
db eval {PRAGMA full_column_names=off}
|
2001-10-18 16:34:46 +04:00
|
|
|
lappend v $msg
|
2005-01-18 20:20:10 +03:00
|
|
|
} {0 {f1 11 f2 22}}
|
2001-10-18 16:34:46 +04:00
|
|
|
do_test select1-6.1.5 {
|
2001-10-06 20:33:02 +04:00
|
|
|
set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {f1 11 f2 22}}
|
2001-10-18 16:34:46 +04:00
|
|
|
do_test select1-6.1.6 {
|
|
|
|
set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {f1 11 f2 22}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.2 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1 as xyzzy FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {xyzzy 11 xyzzy 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.3 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1 as "xyzzy" FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {xyzzy 11 xyzzy 33}}
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-6.3.1 {
|
|
|
|
set v [catch {execsql2 {SELECT f1 as 'xyzzy ' FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {{xyzzy } 11 {xyzzy } 33}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.4 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT f1+F2 as xyzzy FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {xyzzy 33 xyzzy 77}}
|
2001-04-04 15:48:57 +04:00
|
|
|
do_test select1-6.4a {
|
|
|
|
set v [catch {execsql2 {SELECT f1+F2 FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {f1+F2 33 f1+F2 77}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.5 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2000-07-29 17:06:59 +04:00
|
|
|
} {0 {test1.f1+F2 33 test1.f1+F2 77}}
|
2001-10-15 04:44:35 +04:00
|
|
|
do_test select1-6.5.1 {
|
|
|
|
execsql2 {PRAGMA full_column_names=on}
|
|
|
|
set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
|
|
|
|
execsql2 {PRAGMA full_column_names=off}
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {test1.f1+F2 33 test1.f1+F2 77}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.6 {
|
2000-05-31 21:59:25 +04:00
|
|
|
set v [catch {execsql2 {SELECT test1.f1+F2, t1 FROM test1, test2
|
|
|
|
ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2000-07-29 17:06:59 +04:00
|
|
|
} {0 {test1.f1+F2 33 t1 abc test1.f1+F2 77 t1 abc}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.7 {
|
2000-05-31 22:20:14 +04:00
|
|
|
set v [catch {execsql2 {SELECT A.f1, t1 FROM test1 as A, test2
|
|
|
|
ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2005-01-18 19:02:40 +03:00
|
|
|
} {0 {f1 11 t1 abc f1 33 t1 abc}}
|
2000-06-06 21:27:05 +04:00
|
|
|
do_test select1-6.8 {
|
2000-05-31 22:20:14 +04:00
|
|
|
set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as B
|
|
|
|
ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2000-06-21 17:59:10 +04:00
|
|
|
} {1 {ambiguous column name: f1}}
|
2000-06-07 19:11:27 +04:00
|
|
|
do_test select1-6.8b {
|
2000-05-31 22:20:14 +04:00
|
|
|
set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
|
|
|
ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2000-06-21 17:59:10 +04:00
|
|
|
} {1 {ambiguous column name: f2}}
|
2000-06-07 19:11:27 +04:00
|
|
|
do_test select1-6.8c {
|
|
|
|
set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as A
|
|
|
|
ORDER BY f2}} msg]
|
|
|
|
lappend v $msg
|
2000-06-21 17:59:10 +04:00
|
|
|
} {1 {ambiguous column name: A.f1}}
|
2005-01-18 19:02:40 +03:00
|
|
|
do_test select1-6.9.1 {
|
|
|
|
set v [catch {execsql {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
|
|
|
ORDER BY A.f1, B.f1}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {0 {11 11 11 33 33 11 33 33}}
|
|
|
|
do_test select1-6.9.2 {
|
2000-05-31 22:20:14 +04:00
|
|
|
set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
|
|
|
|
ORDER BY A.f1, B.f1}} msg]
|
|
|
|
lappend v $msg
|
2005-01-18 19:02:40 +03:00
|
|
|
} {0 {f1 11 f1 11 f1 33 f1 33 f1 11 f1 11 f1 33 f1 33}}
|
2004-11-22 16:35:41 +03:00
|
|
|
|
2008-07-09 05:39:44 +04:00
|
|
|
do_test select1-6.9.3 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=OFF;
|
|
|
|
PRAGMA full_column_names=OFF;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1
|
|
|
|
}
|
|
|
|
} {{test1 . f1} 11 {test1 . f2} 22}
|
|
|
|
do_test select1-6.9.4 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=OFF;
|
|
|
|
PRAGMA full_column_names=ON;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test1.f2 22}
|
|
|
|
do_test select1-6.9.5 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=OFF;
|
|
|
|
PRAGMA full_column_names=ON;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT 123.45;
|
|
|
|
}
|
|
|
|
} {123.45 123.45}
|
2008-07-10 04:32:42 +04:00
|
|
|
do_test select1-6.9.6 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT * FROM test1 a, test1 b LIMIT 1
|
|
|
|
}
|
|
|
|
} {a.f1 11 a.f2 22 b.f1 11 b.f2 22}
|
|
|
|
do_test select1-6.9.7 {
|
|
|
|
set x [execsql2 {
|
|
|
|
SELECT * FROM test1 a, (select 5, 6) LIMIT 1
|
|
|
|
}]
|
|
|
|
regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x
|
|
|
|
set x
|
|
|
|
} {a.f1 11 a.f2 22 sqlite_subquery.5 5 sqlite_subquery.6 6}
|
|
|
|
do_test select1-6.9.8 {
|
|
|
|
set x [execsql2 {
|
|
|
|
SELECT * FROM test1 a, (select 5 AS x, 6 AS y) AS b LIMIT 1
|
|
|
|
}]
|
|
|
|
regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x
|
|
|
|
set x
|
|
|
|
} {a.f1 11 a.f2 22 b.x 5 b.y 6}
|
2008-07-15 04:27:34 +04:00
|
|
|
do_test select1-6.9.9 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test1.f2 22}
|
|
|
|
do_test select1-6.9.10 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test2.t1 abc}
|
|
|
|
do_test select1-6.9.11 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=ON;
|
|
|
|
PRAGMA full_column_names=ON;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test1.f2 22}
|
|
|
|
do_test select1-6.9.12 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test2.t1 abc}
|
|
|
|
do_test select1-6.9.13 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=ON;
|
|
|
|
PRAGMA full_column_names=OFF;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1
|
|
|
|
}
|
|
|
|
} {f1 11 f1 11}
|
|
|
|
do_test select1-6.9.14 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
|
|
|
}
|
|
|
|
} {f1 11 t1 abc}
|
|
|
|
do_test select1-6.9.15 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=OFF;
|
|
|
|
PRAGMA full_column_names=ON;
|
|
|
|
}
|
|
|
|
execsql2 {
|
|
|
|
SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test1.f1 11}
|
|
|
|
do_test select1-6.9.16 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT f1, t1 FROM test1, test2 LIMIT 1
|
|
|
|
}
|
|
|
|
} {test1.f1 11 test2.t1 abc}
|
|
|
|
|
2008-07-10 04:32:42 +04:00
|
|
|
|
2008-07-09 05:39:44 +04:00
|
|
|
db eval {
|
|
|
|
PRAGMA short_column_names=ON;
|
|
|
|
PRAGMA full_column_names=OFF;
|
|
|
|
}
|
|
|
|
|
2004-11-22 16:35:41 +03:00
|
|
|
ifcapable compound {
|
2001-04-04 15:48:57 +04:00
|
|
|
do_test select1-6.10 {
|
|
|
|
set v [catch {execsql2 {
|
|
|
|
SELECT f1 FROM test1 UNION SELECT f2 FROM test1
|
|
|
|
ORDER BY f2;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
2006-03-26 05:21:22 +04:00
|
|
|
} {0 {f1 11 f1 22 f1 33 f1 44}}
|
2001-04-04 15:48:57 +04:00
|
|
|
do_test select1-6.11 {
|
|
|
|
set v [catch {execsql2 {
|
|
|
|
SELECT f1 FROM test1 UNION SELECT f2+100 FROM test1
|
2007-12-09 00:10:20 +03:00
|
|
|
ORDER BY f2+101;
|
2001-04-04 15:48:57 +04:00
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
2007-12-13 10:58:50 +03:00
|
|
|
} {1 {1st ORDER BY term does not match any column in the result set}}
|
2007-04-13 20:06:32 +04:00
|
|
|
|
|
|
|
# Ticket #2296
|
2008-08-04 07:51:24 +04:00
|
|
|
ifcapable subquery&&compound {
|
2007-04-13 20:06:32 +04:00
|
|
|
do_test select1-6.20 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t6(a TEXT, b TEXT);
|
|
|
|
INSERT INTO t6 VALUES('a','0');
|
|
|
|
INSERT INTO t6 VALUES('b','1');
|
|
|
|
INSERT INTO t6 VALUES('c','2');
|
|
|
|
INSERT INTO t6 VALUES('d','3');
|
|
|
|
SELECT a FROM t6 WHERE b IN
|
|
|
|
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
|
|
|
ORDER BY 1 LIMIT 1)
|
|
|
|
}
|
|
|
|
} {a}
|
|
|
|
do_test select1-6.21 {
|
|
|
|
execsql {
|
|
|
|
SELECT a FROM t6 WHERE b IN
|
|
|
|
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
|
|
|
ORDER BY 1 DESC LIMIT 1)
|
|
|
|
}
|
|
|
|
} {d}
|
|
|
|
do_test select1-6.22 {
|
|
|
|
execsql {
|
|
|
|
SELECT a FROM t6 WHERE b IN
|
|
|
|
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
|
|
|
ORDER BY b LIMIT 2)
|
|
|
|
ORDER BY a;
|
|
|
|
}
|
|
|
|
} {a b}
|
|
|
|
do_test select1-6.23 {
|
|
|
|
execsql {
|
|
|
|
SELECT a FROM t6 WHERE b IN
|
|
|
|
(SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x
|
|
|
|
ORDER BY x DESC LIMIT 2)
|
|
|
|
ORDER BY a;
|
|
|
|
}
|
|
|
|
} {b d}
|
2007-12-10 08:03:46 +03:00
|
|
|
}
|
2007-04-13 20:06:32 +04:00
|
|
|
|
2004-11-22 16:35:41 +03:00
|
|
|
} ;#ifcapable compound
|
2000-05-31 21:59:25 +04:00
|
|
|
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-7.1 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT f1 FROM test1 WHERE f2=;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near ";": syntax error}}
|
2004-11-22 16:35:41 +03:00
|
|
|
ifcapable compound {
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-7.2 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT f1 FROM test1 UNION SELECT WHERE;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near "WHERE": syntax error}}
|
2004-11-22 16:35:41 +03:00
|
|
|
} ;# ifcapable compound
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-7.3 {
|
|
|
|
set v [catch {execsql {SELECT f1 FROM test1 as 'hi', test2 as}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near "as": syntax error}}
|
|
|
|
do_test select1-7.4 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT f1 FROM test1 ORDER BY;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near ";": syntax error}}
|
|
|
|
do_test select1-7.5 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT f1 FROM test1 ORDER BY f1 desc, f2 where;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near "where": syntax error}}
|
|
|
|
do_test select1-7.6 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT count(f1,f2 FROM test1;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near "FROM": syntax error}}
|
|
|
|
do_test select1-7.7 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT count(f1,f2+) FROM test1;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near ")": syntax error}}
|
|
|
|
do_test select1-7.8 {
|
|
|
|
set v [catch {execsql {
|
|
|
|
SELECT f1 FROM test1 ORDER BY f2, f1+;
|
|
|
|
}} msg]
|
|
|
|
lappend v $msg
|
|
|
|
} {1 {near ";": syntax error}}
|
2007-04-06 19:02:13 +04:00
|
|
|
do_test select1-7.9 {
|
|
|
|
catchsql {
|
|
|
|
SELECT f1 FROM test1 LIMIT 5+3 OFFSET 11 ORDER BY f2;
|
|
|
|
}
|
|
|
|
} {1 {near "ORDER": syntax error}}
|
2001-04-13 03:21:58 +04:00
|
|
|
|
|
|
|
do_test select1-8.1 {
|
|
|
|
execsql {SELECT f1 FROM test1 WHERE 4.3+2.4 OR 1 ORDER BY f1}
|
|
|
|
} {11 33}
|
|
|
|
do_test select1-8.2 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1 FROM test1 WHERE ('x' || f1) BETWEEN 'x10' AND 'x20'
|
|
|
|
ORDER BY f1
|
|
|
|
}
|
|
|
|
} {11}
|
|
|
|
do_test select1-8.3 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1 FROM test1 WHERE 5-3==2
|
|
|
|
ORDER BY f1
|
|
|
|
}
|
|
|
|
} {11 33}
|
2004-05-12 15:24:02 +04:00
|
|
|
|
|
|
|
# TODO: This test is failing because f1 is now being loaded off the
|
|
|
|
# disk as a vdbe integer, not a string. Hence the value of f1/(f1-11)
|
|
|
|
# changes because of rounding. Disable the test for now.
|
|
|
|
if 0 {
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-8.4 {
|
|
|
|
execsql {
|
2002-05-27 05:04:51 +04:00
|
|
|
SELECT coalesce(f1/(f1-11),'x'),
|
|
|
|
coalesce(min(f1/(f1-11),5),'y'),
|
|
|
|
coalesce(max(f1/(f1-33),6),'z')
|
2001-04-13 03:21:58 +04:00
|
|
|
FROM test1 ORDER BY f1
|
|
|
|
}
|
2002-05-27 05:04:51 +04:00
|
|
|
} {x y 6 1.5 1.5 z}
|
2004-05-12 15:24:02 +04:00
|
|
|
}
|
2001-04-13 03:21:58 +04:00
|
|
|
do_test select1-8.5 {
|
|
|
|
execsql {
|
|
|
|
SELECT min(1,2,3), -max(1,2,3)
|
|
|
|
FROM test1 ORDER BY f1
|
|
|
|
}
|
|
|
|
} {1 -3 1 -3}
|
|
|
|
|
2001-10-19 20:44:56 +04:00
|
|
|
|
|
|
|
# Check the behavior when the result set is empty
|
|
|
|
#
|
2004-05-28 15:37:27 +04:00
|
|
|
# SQLite v3 always sets r(*).
|
|
|
|
#
|
|
|
|
# do_test select1-9.1 {
|
|
|
|
# catch {unset r}
|
|
|
|
# set r(*) {}
|
|
|
|
# db eval {SELECT * FROM test1 WHERE f1<0} r {}
|
|
|
|
# set r(*)
|
|
|
|
# } {}
|
2001-10-19 20:44:56 +04:00
|
|
|
do_test select1-9.2 {
|
|
|
|
execsql {PRAGMA empty_result_callbacks=on}
|
2004-05-28 15:37:27 +04:00
|
|
|
catch {unset r}
|
2001-10-19 20:44:56 +04:00
|
|
|
set r(*) {}
|
|
|
|
db eval {SELECT * FROM test1 WHERE f1<0} r {}
|
|
|
|
set r(*)
|
|
|
|
} {f1 f2}
|
2005-01-21 06:12:14 +03:00
|
|
|
ifcapable subquery {
|
|
|
|
do_test select1-9.3 {
|
|
|
|
set r(*) {}
|
|
|
|
db eval {SELECT * FROM test1 WHERE f1<(select count(*) from test2)} r {}
|
|
|
|
set r(*)
|
|
|
|
} {f1 f2}
|
|
|
|
}
|
2001-10-19 20:44:56 +04:00
|
|
|
do_test select1-9.4 {
|
|
|
|
set r(*) {}
|
|
|
|
db eval {SELECT * FROM test1 ORDER BY f1} r {}
|
|
|
|
set r(*)
|
|
|
|
} {f1 f2}
|
|
|
|
do_test select1-9.5 {
|
|
|
|
set r(*) {}
|
|
|
|
db eval {SELECT * FROM test1 WHERE f1<0 ORDER BY f1} r {}
|
|
|
|
set r(*)
|
|
|
|
} {f1 f2}
|
|
|
|
unset r
|
|
|
|
|
2002-01-22 06:13:42 +03:00
|
|
|
# Check for ORDER BY clauses that refer to an AS name in the column list
|
|
|
|
#
|
|
|
|
do_test select1-10.1 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1 AS x FROM test1 ORDER BY x
|
|
|
|
}
|
|
|
|
} {11 33}
|
|
|
|
do_test select1-10.2 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1 AS x FROM test1 ORDER BY -x
|
|
|
|
}
|
|
|
|
} {33 11}
|
|
|
|
do_test select1-10.3 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1-23 AS x FROM test1 ORDER BY abs(x)
|
|
|
|
}
|
|
|
|
} {10 -12}
|
|
|
|
do_test select1-10.4 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1-23 AS x FROM test1 ORDER BY -abs(x)
|
|
|
|
}
|
|
|
|
} {-12 10}
|
|
|
|
do_test select1-10.5 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1-22 AS x, f2-22 as y FROM test1
|
|
|
|
}
|
|
|
|
} {-11 0 11 22}
|
|
|
|
do_test select1-10.6 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1-22 AS x, f2-22 as y FROM test1 WHERE x>0 AND y<50
|
|
|
|
}
|
|
|
|
} {11 22}
|
2008-07-10 04:32:42 +04:00
|
|
|
do_test select1-10.7 {
|
|
|
|
execsql {
|
|
|
|
SELECT f1 COLLATE nocase AS x FROM test1 ORDER BY x
|
|
|
|
}
|
|
|
|
} {11 33}
|
2002-01-22 06:13:42 +03:00
|
|
|
|
2002-04-04 06:10:55 +04:00
|
|
|
# Check the ability to specify "TABLE.*" in the result set of a SELECT
|
|
|
|
#
|
|
|
|
do_test select1-11.1 {
|
|
|
|
execsql {
|
|
|
|
DELETE FROM t3;
|
|
|
|
DELETE FROM t4;
|
|
|
|
INSERT INTO t3 VALUES(1,2);
|
|
|
|
INSERT INTO t4 VALUES(3,4);
|
|
|
|
SELECT * FROM t3, t4;
|
|
|
|
}
|
|
|
|
} {1 2 3 4}
|
2005-01-18 19:02:40 +03:00
|
|
|
do_test select1-11.2.1 {
|
|
|
|
execsql {
|
2002-04-04 06:10:55 +04:00
|
|
|
SELECT * FROM t3, t4;
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {1 2 3 4}
|
|
|
|
do_test select1-11.2.2 {
|
2002-04-04 06:10:55 +04:00
|
|
|
execsql2 {
|
2005-01-18 19:02:40 +03:00
|
|
|
SELECT * FROM t3, t4;
|
2002-04-04 06:10:55 +04:00
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {a 3 b 4 a 3 b 4}
|
2004-07-20 05:45:19 +04:00
|
|
|
do_test select1-11.4.1 {
|
2002-04-04 06:10:55 +04:00
|
|
|
execsql {
|
|
|
|
SELECT t3.*, t4.b FROM t3, t4;
|
|
|
|
}
|
|
|
|
} {1 2 4}
|
2004-07-20 05:45:19 +04:00
|
|
|
do_test select1-11.4.2 {
|
|
|
|
execsql {
|
|
|
|
SELECT "t3".*, t4.b FROM t3, t4;
|
|
|
|
}
|
|
|
|
} {1 2 4}
|
2005-01-18 19:02:40 +03:00
|
|
|
do_test select1-11.5.1 {
|
2002-04-04 06:10:55 +04:00
|
|
|
execsql2 {
|
|
|
|
SELECT t3.*, t4.b FROM t3, t4;
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {a 1 b 4 b 4}
|
2002-04-04 06:10:55 +04:00
|
|
|
do_test select1-11.6 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT x.*, y.b FROM t3 AS x, t4 AS y;
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {a 1 b 4 b 4}
|
2002-04-04 06:10:55 +04:00
|
|
|
do_test select1-11.7 {
|
|
|
|
execsql {
|
|
|
|
SELECT t3.b, t4.* FROM t3, t4;
|
|
|
|
}
|
|
|
|
} {2 3 4}
|
|
|
|
do_test select1-11.8 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT t3.b, t4.* FROM t3, t4;
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {b 4 a 3 b 4}
|
2002-04-04 06:10:55 +04:00
|
|
|
do_test select1-11.9 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT x.b, y.* FROM t3 AS x, t4 AS y;
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {b 4 a 3 b 4}
|
2002-04-04 06:10:55 +04:00
|
|
|
do_test select1-11.10 {
|
|
|
|
catchsql {
|
|
|
|
SELECT t5.* FROM t3, t4;
|
|
|
|
}
|
|
|
|
} {1 {no such table: t5}}
|
|
|
|
do_test select1-11.11 {
|
|
|
|
catchsql {
|
|
|
|
SELECT t3.* FROM t3 AS x, t4;
|
|
|
|
}
|
|
|
|
} {1 {no such table: t3}}
|
2005-01-21 06:12:14 +03:00
|
|
|
ifcapable subquery {
|
|
|
|
do_test select1-11.12 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT t3.* FROM t3, (SELECT max(a), max(b) FROM t4)
|
|
|
|
}
|
|
|
|
} {a 1 b 2}
|
|
|
|
do_test select1-11.13 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT t3.* FROM (SELECT max(a), max(b) FROM t4), t3
|
|
|
|
}
|
|
|
|
} {a 1 b 2}
|
|
|
|
do_test select1-11.14 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT * FROM t3, (SELECT max(a), max(b) FROM t4) AS 'tx'
|
|
|
|
}
|
|
|
|
} {a 1 b 2 max(a) 3 max(b) 4}
|
|
|
|
do_test select1-11.15 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT y.*, t3.* FROM t3, (SELECT max(a), max(b) FROM t4) AS y
|
|
|
|
}
|
|
|
|
} {max(a) 3 max(b) 4 a 1 b 2}
|
|
|
|
}
|
2002-05-27 07:25:51 +04:00
|
|
|
do_test select1-11.16 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT y.* FROM t3 as y, t4 as z
|
|
|
|
}
|
2005-01-18 19:02:40 +03:00
|
|
|
} {a 1 b 2}
|
2002-01-22 06:13:42 +03:00
|
|
|
|
2002-04-06 17:57:42 +04:00
|
|
|
# Tests of SELECT statements without a FROM clause.
|
|
|
|
#
|
|
|
|
do_test select1-12.1 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT 1+2+3
|
|
|
|
}
|
|
|
|
} {1+2+3 6}
|
|
|
|
do_test select1-12.2 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT 1,'hello',2
|
|
|
|
}
|
|
|
|
} {1 1 'hello' hello 2 2}
|
|
|
|
do_test select1-12.3 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT 1 AS 'a','hello' AS 'b',2 AS 'c'
|
|
|
|
}
|
|
|
|
} {a 1 b hello c 2}
|
|
|
|
do_test select1-12.4 {
|
|
|
|
execsql {
|
|
|
|
DELETE FROM t3;
|
|
|
|
INSERT INTO t3 VALUES(1,2);
|
2004-11-22 16:35:41 +03:00
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
ifcapable compound {
|
|
|
|
do_test select1-12.5 {
|
|
|
|
execsql {
|
2002-04-06 17:57:42 +04:00
|
|
|
SELECT * FROM t3 UNION SELECT 3 AS 'a', 4 ORDER BY a;
|
|
|
|
}
|
|
|
|
} {1 2 3 4}
|
2004-11-22 16:35:41 +03:00
|
|
|
|
|
|
|
do_test select1-12.6 {
|
2002-04-06 17:57:42 +04:00
|
|
|
execsql {
|
|
|
|
SELECT 3, 4 UNION SELECT * FROM t3;
|
|
|
|
}
|
|
|
|
} {1 2 3 4}
|
2004-11-22 16:35:41 +03:00
|
|
|
} ;# ifcapable compound
|
|
|
|
|
2005-01-21 06:12:14 +03:00
|
|
|
ifcapable subquery {
|
|
|
|
do_test select1-12.7 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t3 WHERE a=(SELECT 1);
|
|
|
|
}
|
|
|
|
} {1 2}
|
|
|
|
do_test select1-12.8 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t3 WHERE a=(SELECT 2);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
}
|
2004-11-22 16:35:41 +03:00
|
|
|
|
2005-01-21 07:25:47 +03:00
|
|
|
ifcapable {compound && subquery} {
|
|
|
|
do_test select1-12.9 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT x FROM (
|
2006-03-26 05:21:22 +04:00
|
|
|
SELECT a AS x, b AS y FROM t3 UNION SELECT a,b FROM t4 ORDER BY a,b
|
2005-01-21 07:25:47 +03:00
|
|
|
) ORDER BY x;
|
|
|
|
}
|
|
|
|
} {x 1 x 3}
|
|
|
|
do_test select1-12.10 {
|
|
|
|
execsql2 {
|
|
|
|
SELECT z.x FROM (
|
2006-03-26 05:21:22 +04:00
|
|
|
SELECT a AS x,b AS y FROM t3 UNION SELECT a, b FROM t4 ORDER BY a,b
|
2005-01-21 07:25:47 +03:00
|
|
|
) AS 'z' ORDER BY x;
|
|
|
|
}
|
|
|
|
} {x 1 x 3}
|
2004-11-22 16:35:41 +03:00
|
|
|
} ;# ifcapable compound
|
2002-05-09 01:46:14 +04:00
|
|
|
|
2005-12-15 13:11:30 +03:00
|
|
|
|
2006-01-13 16:01:19 +03:00
|
|
|
# Check for a VDBE stack growth problem that existed at one point.
|
|
|
|
#
|
2006-01-14 11:02:28 +03:00
|
|
|
ifcapable subquery {
|
|
|
|
do_test select1-13.1 {
|
2006-01-13 16:01:19 +03:00
|
|
|
execsql {
|
2006-01-14 11:02:28 +03:00
|
|
|
BEGIN;
|
|
|
|
create TABLE abc(a, b, c, PRIMARY KEY(a, b));
|
|
|
|
INSERT INTO abc VALUES(1, 1, 1);
|
2006-01-13 16:01:19 +03:00
|
|
|
}
|
2006-01-14 11:02:28 +03:00
|
|
|
for {set i 0} {$i<10} {incr i} {
|
|
|
|
execsql {
|
|
|
|
INSERT INTO abc SELECT a+(select max(a) FROM abc),
|
|
|
|
b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
execsql {COMMIT}
|
|
|
|
|
|
|
|
# This used to seg-fault when the problem existed.
|
|
|
|
execsql {
|
|
|
|
SELECT count(
|
|
|
|
(SELECT a FROM abc WHERE a = NULL AND b >= upper.c)
|
|
|
|
) FROM abc AS upper;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
}
|
2006-01-13 16:01:19 +03:00
|
|
|
|
2009-04-23 18:58:39 +04:00
|
|
|
foreach tab [db eval {SELECT name FROM sqlite_master WHERE type = 'table'}] {
|
|
|
|
db eval "DROP TABLE $tab"
|
|
|
|
}
|
2008-06-23 22:49:43 +04:00
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
2009-04-23 18:58:39 +04:00
|
|
|
|
2008-06-23 22:49:43 +04:00
|
|
|
do_test select1-14.1 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM sqlite_master WHERE rowid>10;
|
|
|
|
SELECT * FROM sqlite_master WHERE rowid=10;
|
|
|
|
SELECT * FROM sqlite_master WHERE rowid<10;
|
|
|
|
SELECT * FROM sqlite_master WHERE rowid<=10;
|
|
|
|
SELECT * FROM sqlite_master WHERE rowid>=10;
|
|
|
|
SELECT * FROM sqlite_master;
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test select1-14.2 {
|
|
|
|
execsql {
|
|
|
|
SELECT 10 IN (SELECT rowid FROM sqlite_master);
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
|
2009-04-10 19:38:42 +04:00
|
|
|
if {[db one {PRAGMA locking_mode}]=="normal"} {
|
|
|
|
# Check that ticket #3771 has been fixed. This test does not
|
|
|
|
# work with locking_mode=EXCLUSIVE so disable in that case.
|
|
|
|
#
|
|
|
|
do_test select1-15.1 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a);
|
|
|
|
CREATE INDEX i1 ON t1(a);
|
|
|
|
INSERT INTO t1 VALUES(1);
|
|
|
|
INSERT INTO t1 VALUES(2);
|
|
|
|
INSERT INTO t1 VALUES(3);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test select1-15.2 {
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
execsql { DROP INDEX i1 } db2
|
|
|
|
db2 close
|
|
|
|
} {}
|
|
|
|
do_test select1-15.3 {
|
|
|
|
execsql { SELECT 2 IN (SELECT a FROM t1) }
|
|
|
|
} {1}
|
|
|
|
}
|
2012-02-23 21:35:28 +04:00
|
|
|
|
|
|
|
# Crash bug reported on the mailing list on 2012-02-23
|
|
|
|
#
|
|
|
|
do_test select1-16.1 {
|
|
|
|
catchsql {SELECT 1 FROM (SELECT *)}
|
|
|
|
} {1 {no tables specified}}
|
2009-04-10 19:38:42 +04:00
|
|
|
|
2000-05-31 21:59:25 +04:00
|
|
|
finish_test
|