mirror of https://github.com/sqlite/sqlite
103 lines
2.6 KiB
Plaintext
103 lines
2.6 KiB
Plaintext
|
# 2007 Dec 4
|
||
|
#
|
||
|
# The author disclaims copyright to this source code. In place of
|
||
|
# a legal notice, here is a blessing:
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
|
#***********************************************************************
|
||
|
#
|
||
|
# This file is to test that the issues surrounding expressions in
|
||
|
# ORDER BY clauses on compound SELECT statements raised by ticket
|
||
|
# #2822 have been dealt with.
|
||
|
#
|
||
|
# $Id: tkt2822.test,v 1.1 2007/12/10 18:51:48 danielk1977 Exp $
|
||
|
#
|
||
|
|
||
|
set testdir [file dirname $argv0]
|
||
|
source $testdir/tester.tcl
|
||
|
|
||
|
# Test plan:
|
||
|
#
|
||
|
# tkt2820-1.* - Simple identifier as ORDER BY expression.
|
||
|
# tkt2820-2.* - More complex ORDER BY expressions.
|
||
|
|
||
|
do_test tkt2820-1.1 {
|
||
|
execsql {
|
||
|
CREATE TABLE t1(a, b, c);
|
||
|
CREATE TABLE t2(c, b, a);
|
||
|
|
||
|
INSERT INTO t1 VALUES(1, 2, 3);
|
||
|
INSERT INTO t2 VALUES(3, 2, 1);
|
||
|
}
|
||
|
} {}
|
||
|
|
||
|
# If an ORDER BY expression matches two different columns, it is an error.
|
||
|
#
|
||
|
do_test tkt2820-1.2 {
|
||
|
catchsql {
|
||
|
SELECT a, b FROM t1 UNION ALL SELECT b, a FROM t2 ORDER BY a;
|
||
|
}
|
||
|
} {1 {ORDER BY term number 1 is ambiguous}}
|
||
|
do_test tkt2820-1.3 {
|
||
|
catchsql {
|
||
|
SELECT a, b, c FROM t2 UNION ALL SELECT c, b, a FROM t1 ORDER BY a;
|
||
|
}
|
||
|
} {1 {ORDER BY term number 1 is ambiguous}}
|
||
|
|
||
|
# But not if it matches the same column in two or more of the
|
||
|
# compounded SELECT statements.
|
||
|
#
|
||
|
do_test tkt2820-1.4 {
|
||
|
execsql {
|
||
|
SELECT a, b, c FROM t2 UNION ALL SELECT a, b, c FROM t1 ORDER BY a;
|
||
|
}
|
||
|
} {1 2 3 1 2 3}
|
||
|
|
||
|
do_test tkt2820-1.5 {
|
||
|
execsql {
|
||
|
SELECT a, b FROM t2 UNION ALL SELECT c, b FROM t1 ORDER BY c;
|
||
|
}
|
||
|
} {1 2 3 2}
|
||
|
|
||
|
# If a match cannot be found in any SELECT, return an error.
|
||
|
#
|
||
|
do_test tkt2820-1.6 {
|
||
|
catchsql {
|
||
|
SELECT * FROM t2 UNION ALL SELECT * FROM t1 ORDER BY d;
|
||
|
}
|
||
|
} {1 {ORDER BY term number 1 does not match any result column}}
|
||
|
|
||
|
|
||
|
do_test tkt2820-2.1 {
|
||
|
execsql {
|
||
|
SELECT a+1, b+1 FROM t1 UNION ALL SELECT a, c FROM t2 ORDER BY a+1;
|
||
|
}
|
||
|
} {1 3 2 3}
|
||
|
do_test tkt2820-2.2 {
|
||
|
catchsql {
|
||
|
SELECT a+1, b+1 FROM t1 UNION ALL SELECT a, c FROM t2 ORDER BY a+2;
|
||
|
}
|
||
|
} {1 {ORDER BY term number 1 does not match any result column}}
|
||
|
do_test tkt2820-2.3 {
|
||
|
catchsql {
|
||
|
SELECT a+1, b+1 FROM t1 UNION ALL SELECT c, a+1 FROM t2 ORDER BY a+1;
|
||
|
}
|
||
|
} {1 {ORDER BY term number 1 is ambiguous}}
|
||
|
|
||
|
do_test tkt2820-2.4 {
|
||
|
execsql {
|
||
|
SELECT t1.a, b+1 FROM t1 UNION ALL SELECT c, a+1 FROM t2 ORDER BY a;
|
||
|
}
|
||
|
} {1 3 3 2}
|
||
|
do_test tkt2820-2.5 {
|
||
|
execsql {
|
||
|
SELECT t1.a, b+1 FROM t1 UNION ALL SELECT c, a+1 FROM t2 ORDER BY t1.a;
|
||
|
}
|
||
|
} {1 3 3 2}
|
||
|
|
||
|
finish_test
|
||
|
|