Add test file e_select.test.

FossilOrigin-Name: 8b9d8c226e5d95584c1e61a796dc23b780a300cb
This commit is contained in:
dan 2010-09-04 18:52:30 +00:00
parent ee9ff672da
commit 4ce7488075
3 changed files with 192 additions and 17 deletions

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Documentation\senhancements\sfor\ssqlite3_db_status().\s\sEvidence\smarks\son\nthe\sSQL\sfunction\scall\sintrface.
D 2010-09-03T18:50:49
C Add\stest\sfile\se_select.test.
D 2010-09-04T18:52:30
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -352,6 +349,7 @@ F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
F test/e_expr.test 164e87c1d7b40ceb47c57c3bffa384c81d009aa7
F test/e_fkey.test 6721a741c6499b3ab7e5385923233343c8f1ad05
F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
F test/e_select.test f2469d2c2081610c3f85f2b85dda9026d343393f
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
@ -856,14 +854,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 0593373d4bf4f3451b41810513fd12cd8ebd0395
R 32cd5b7a1b387673472bd5f9ae3eecc2
U drh
Z 08ba64448263f8fb86ddcfbd2162f09d
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMgUOMoxKgR168RlERAk7zAKCKyhwR1lNBXcJvJNOoNtnJk7FfEQCfdcYb
YWj0MhV07vpCPxDnCO5bB1M=
=1z53
-----END PGP SIGNATURE-----
P f06c7b1973d64a6a1a1db2b44df2a4eb0ece0077
R ff12553912aafce92749cd560cb5ebc9
U dan
Z a3043953a2e784f32d9ae6b144aa3d3f

View File

@ -1 +1 @@
f06c7b1973d64a6a1a1db2b44df2a4eb0ece0077
8b9d8c226e5d95584c1e61a796dc23b780a300cb

184
test/e_select.test Normal file
View File

@ -0,0 +1,184 @@
# 2010 July 16
#
# 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 implements tests to verify that the "testable statements" in
# the lang_select.html document are correct.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_execsql_test e_select-1.0 {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES('a', 'one');
INSERT INTO t1 VALUES('b', 'two');
INSERT INTO t1 VALUES('c', 'three');
CREATE TABLE t2(a, b);
INSERT INTO t2 VALUES('a', 'I');
INSERT INTO t2 VALUES('b', 'II');
INSERT INTO t2 VALUES('c', 'III');
CREATE TABLE t3(a, c);
INSERT INTO t3 VALUES('a', 1);
INSERT INTO t3 VALUES('b', 2);
CREATE TABLE t4(a, c);
INSERT INTO t4 VALUES('a', NULL);
INSERT INTO t4 VALUES('b', 2);
} {}
set t1_cross_t2 [list \
a one a I a one b II \
a one c III b two a I \
b two b II b two c III \
c three a I c three b II \
c three c III \
]
set t1_cross_t1 [list \
a one a one a one b two \
a one c three b two a one \
b two b two b two c three \
c three a one c three b two \
c three c three \
]
#-------------------------------------------------------------------------
# The following tests focus on FROM clause (join) processing.
#
# EVIDENCE-OF: R-26491-65072 If the join-op is a comma (","), then the
# composite dataset is the cartesian product of the sets of records from
# the left and right sides of the join-op.
#
do_execsql_test e_select-1.1.2 { SELECT * FROM t1, t2 } $t1_cross_t2
do_execsql_test e_select-1.1.3 { SELECT * FROM t1 AS x, t1 AS y} $t1_cross_t1
# EVIDENCE-OF: R-22228-15000 If the join-op is a "CROSS JOIN" or "INNER
# JOIN", then the composite dataset is created in the same way as for
# the comma join-op.
#
foreach {tn select res} [list \
1 { SELECT * FROM t1 CROSS JOIN t2 } $t1_cross_t2 \
2 { SELECT * FROM t1 AS y CROSS JOIN t1 AS x } $t1_cross_t1 \
3 { SELECT * FROM t1 INNER JOIN t2 } $t1_cross_t2 \
4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \
] {
do_execsql_test e_select-1.2.$tn $select $res
}
# EVIDENCE-OF: R-00387-12725 If there is an ON clause specified, then
# the ON expression is evaluated for each row of the cartesian product
# and the result cast to a numeric value as if by a CAST expression. All
# rows for which the expression evaluates to NULL or zero (integer value
# 0 or real value 0.0) are excluded from the composite dataset.
#
# Each of the SELECT statements below is executed three times - once with
# the string %JOIN% replaced with a comma, once with "CROSS JOIN" and once
# with "INNER JOIN". The test shows that the results of the query are the
# same in each case.
#
foreach {tn select res} [list \
1 { SELECT * FROM t1 %JOIN% t2 ON (1) } $t1_cross_t2 \
2 { SELECT * FROM t1 %JOIN% t2 ON (0) } [list] \
3 { SELECT * FROM t1 %JOIN% t2 ON (NULL) } [list] \
4 { SELECT * FROM t1 %JOIN% t2 ON ('abc') } [list] \
5 { SELECT * FROM t1 %JOIN% t2 ON ('1ab') } $t1_cross_t2 \
6 { SELECT * FROM t1 %JOIN% t2 ON (0.9) } $t1_cross_t2 \
7 { SELECT * FROM t1 %JOIN% t2 ON ('0.9') } $t1_cross_t2 \
8 { SELECT * FROM t1 %JOIN% t2 ON (0.0) } [list] \
\
9 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = t2.a) } \
{one I two II three III} \
10 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = 'a') } \
{one I one II one III} \
11 { SELECT t1.b, t2.b
FROM t1 %JOIN% t2 ON (CASE WHEN t1.a = 'a' THEN NULL ELSE 1 END) } \
{two I two II two III three I three II three III} \
] {
foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] {
set S [string map [list %JOIN% $joinop] $select]
do_execsql_test e_select-1.3.$tn.$tn2 $S $res
}
}
# EVIDENCE-OF: R-63358-54862 If there is a USING clause specified as
# part of the join-constraint, then each of the column names specified
# must exist in the datasets to both the left and right of the join-op.
#
foreach {tn select col} {
1 { SELECT * FROM t1, t3 USING (b) } "b"
2 { SELECT * FROM t3, t1 USING (c) } "c"
3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a"
} {
set err "cannot join using column $col - column not present in both tables"
do_catchsql_test e_select-1.4.$tn $select [list 1 $err]
}
# EVIDENCE-OF: R-42568-37000 For each pair of namesake columns, the
# expression "lhs.X = rhs.X" is evaluated for each row of the cartesian
# product and the result cast to a numeric value. All rows for which one
# or more of the expressions evaluates to NULL or zero are excluded from
# the result set.
#
foreach {tn select res} {
1 { SELECT * FROM t1, t3 USING (a) } {a one 1 b two 2}
2 { SELECT * FROM t3, t4 USING (a,c) } {b 2}
} {
do_execsql_test e_select-1.5.$tn $select $res
}
# EVIDENCE-OF: R-54046-48600 When comparing values as a result of a
# USING clause, the normal rules for handling affinities, collation
# sequences and NULL values in comparisons apply.
#
# EVIDENCE-OF: R-35466-18578 The column from the dataset on the
# left-hand side of the join operator is considered to be on the
# left-hand side of the comparison operator (=) for the purposes of
# collation sequence and affinity precedence.
#
do_execsql_test e_select-1.6.0 {
CREATE TABLE t5(a COLLATE nocase, b COLLATE binary);
INSERT INTO t5 VALUES('AA', 'cc');
INSERT INTO t5 VALUES('BB', 'dd');
INSERT INTO t5 VALUES(NULL, NULL);
CREATE TABLE t6(a COLLATE binary, b COLLATE nocase);
INSERT INTO t6 VALUES('aa', 'cc');
INSERT INTO t6 VALUES('bb', 'DD');
INSERT INTO t6 VALUES(NULL, NULL);
} {}
foreach {tn select res} {
1 { SELECT * FROM t5 %JOIN% t6 USING (a) } {AA cc cc BB dd DD}
2 { SELECT * FROM t6 %JOIN% t5 USING (a) } {}
3 { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) %JOIN% t5 USING (a) }
{aa cc cc bb DD dd}
4 { SELECT * FROM t5 %JOIN% t6 USING (a,b) } {AA cc}
5 { SELECT * FROM t6 %JOIN% t5 USING (a,b) } {}
} {
foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] {
set S [string map [list %JOIN% $joinop] $select]
do_execsql_test e_select-1.6.$tn.$tn2 $S $res
}
}
finish_test