Adjust the test suite to account for recent changes related to #2822. Most changes are related to English language error messages only. (CVS 4622)
FossilOrigin-Name: 2f88b9b3e3c9abc3ae4a5dcef82707dd74f8aace
This commit is contained in:
+112
-54
@@ -13,90 +13,148 @@
|
||||
# ORDER BY clauses on compound SELECT statements raised by ticket
|
||||
# #2822 have been dealt with.
|
||||
#
|
||||
# $Id: tkt2822.test,v 1.2 2007/12/12 04:38:27 danielk1977 Exp $
|
||||
# $Id: tkt2822.test,v 1.3 2007/12/13 07:58:51 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# The ORDER BY matching algorithm is three steps:
|
||||
#
|
||||
# (1) If the ORDER BY term is an integer constant i, then
|
||||
# sort by the i-th column of the result set.
|
||||
#
|
||||
# (2) If the ORDER BY term is an identifier (not x.y or x.y.z
|
||||
# but simply x) then look for a column alias with the same
|
||||
# name. If found, then sort by that column.
|
||||
#
|
||||
# (3) Evaluate the term as an expression and sort by the
|
||||
# value of the expression.
|
||||
#
|
||||
# For a compound SELECT the rules are modified slightly.
|
||||
# In the third rule, the expression must exactly match one
|
||||
# of the result columns. The sequences of three rules is
|
||||
# attempted first on the left-most SELECT. If that doesn't
|
||||
# work, we move to the right, one by one. This is not standard
|
||||
# SQL, it is an SQLite extension.
|
||||
#
|
||||
|
||||
|
||||
# Test plan:
|
||||
#
|
||||
# tkt2822-1.* - Simple identifier as ORDER BY expression.
|
||||
# tkt2822-2.* - More complex ORDER BY expressions.
|
||||
|
||||
do_test tkt2822-1.1 {
|
||||
do_test tkt2822-0.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
CREATE TABLE t2(c, b, a);
|
||||
CREATE TABLE t2(a, b, c);
|
||||
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t2 VALUES(3, 2, 1);
|
||||
INSERT INTO t1 VALUES(1, 3, 9);
|
||||
INSERT INTO t1 VALUES(3, 9, 27);
|
||||
INSERT INTO t1 VALUES(5, 15, 45);
|
||||
|
||||
INSERT INTO t2 VALUES(2, 6, 18);
|
||||
INSERT INTO t2 VALUES(4, 12, 36);
|
||||
INSERT INTO t2 VALUES(6, 18, 54);
|
||||
}
|
||||
} {}
|
||||
|
||||
# If an ORDER BY expression matches two different columns, it is an error.
|
||||
# Test the "ORDER BY <integer>" syntax.
|
||||
#
|
||||
do_test tkt2822-1.1 {
|
||||
execsql {
|
||||
SELECT a, b, c FROM t1 UNION ALL SELECT a, b, c FROM t2 ORDER BY 1;
|
||||
}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
do_test tkt2822-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 tkt2822-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 tkt2822-1.4 {
|
||||
execsql {
|
||||
SELECT a, b, c FROM t2 UNION ALL SELECT a, b, c FROM t1 ORDER BY a;
|
||||
SELECT a, CAST (b AS TEXT), c FROM t1
|
||||
UNION ALL
|
||||
SELECT a, b, c FROM t2
|
||||
ORDER BY 2;
|
||||
}
|
||||
} {1 2 3 1 2 3}
|
||||
} {2 6 18 4 12 36 6 18 54 5 15 45 1 3 9 3 9 27}
|
||||
|
||||
do_test tkt2822-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.
|
||||
# Test the "ORDER BY <identifier>" syntax.
|
||||
#
|
||||
do_test tkt2822-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 tkt2822-2.1 {
|
||||
execsql {
|
||||
SELECT a+1, b+1 FROM t1 UNION ALL SELECT a, c FROM t2 ORDER BY a+1;
|
||||
SELECT a, b, c FROM t1 UNION ALL SELECT a, b, c FROM t2 ORDER BY a;
|
||||
}
|
||||
} {1 3 2 3}
|
||||
do_test tkt2822-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 tkt2822-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}}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
|
||||
do_test tkt2822-2.4 {
|
||||
do_test tkt2822-2.2 {
|
||||
execsql {
|
||||
SELECT t1.a, b+1 FROM t1 UNION ALL SELECT c, a+1 FROM t2 ORDER BY a;
|
||||
SELECT a, CAST (b AS TEXT) AS x, c FROM t1
|
||||
UNION ALL
|
||||
SELECT a, b, c FROM t2
|
||||
ORDER BY x;
|
||||
}
|
||||
} {1 3 3 2}
|
||||
do_test tkt2822-2.5 {
|
||||
} {2 6 18 4 12 36 6 18 54 5 15 45 1 3 9 3 9 27}
|
||||
do_test tkt2822-2.3 {
|
||||
execsql {
|
||||
SELECT t1.a, b+1 FROM t1 UNION ALL SELECT c, a+1 FROM t2 ORDER BY t1.a;
|
||||
SELECT t1.a, b, c FROM t1 UNION ALL SELECT t2.a, b, c FROM t2 ORDER BY a;
|
||||
}
|
||||
} {1 3 3 2}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
|
||||
# Test the "ORDER BY <expression>" syntax.
|
||||
#
|
||||
do_test tkt2822-3.1 {
|
||||
execsql {
|
||||
SELECT a, CAST (b AS TEXT) AS x, c FROM t1
|
||||
UNION ALL
|
||||
SELECT a, b, c FROM t2
|
||||
ORDER BY CAST (b AS TEXT);
|
||||
}
|
||||
} {2 6 18 4 12 36 6 18 54 5 15 45 1 3 9 3 9 27}
|
||||
do_test tkt2822-3.2 {
|
||||
execsql {
|
||||
SELECT t1.a, b, c FROM t1 UNION ALL SELECT t2.a, b, c FROM t2 ORDER BY t1.a;
|
||||
}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
|
||||
# Test that if a match cannot be found in the leftmost SELECT, an
|
||||
# attempt is made to find a match in subsequent SELECT statements.
|
||||
#
|
||||
do_test tkt2822-3.1 {
|
||||
execsql {
|
||||
SELECT a, b, c FROM t1 UNION ALL SELECT a AS x, b, c FROM t2 ORDER BY x;
|
||||
}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
do_test tkt2822-3.2 {
|
||||
# But the leftmost SELECT takes precedence.
|
||||
execsql {
|
||||
SELECT a AS b, CAST (b AS TEXT) AS a, c FROM t1
|
||||
UNION ALL
|
||||
SELECT a, b, c FROM t2
|
||||
ORDER BY a;
|
||||
}
|
||||
} {2 6 18 4 12 36 6 18 54 5 15 45 1 3 9 3 9 27}
|
||||
do_test tkt2822-3.3 {
|
||||
execsql {
|
||||
SELECT a, b, c FROM t2
|
||||
UNION ALL
|
||||
SELECT a AS b, CAST (b AS TEXT) AS a, c FROM t1
|
||||
ORDER BY a;
|
||||
}
|
||||
} {1 3 9 2 6 18 3 9 27 4 12 36 5 15 45 6 18 54}
|
||||
|
||||
# Test some error conditions (ORDER BY clauses that match no column).
|
||||
#
|
||||
do_test tkt2822-4.1 {
|
||||
catchsql {
|
||||
SELECT a, b, c FROM t1 UNION ALL SELECT a, b, c FROM t2 ORDER BY x
|
||||
}
|
||||
} {1 {1st ORDER BY term does not match any column in the result set}}
|
||||
do_test tkt2822-4.2 {
|
||||
catchsql {
|
||||
SELECT a, CAST (b AS TEXT) AS x, c FROM t1
|
||||
UNION ALL
|
||||
SELECT a, b, c FROM t2
|
||||
ORDER BY CAST (b AS INTEGER);
|
||||
}
|
||||
} {1 {1st ORDER BY term does not match any column in the result set}}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user