Add tests for sub-select statements in the FROM clause of a SELECT to e_select.test.
FossilOrigin-Name: 2c6b1ca952be9979b8079431c2abad28419b6256
This commit is contained in:
parent
6d9ab66278
commit
cd7fe243ce
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\sproblem\swith\stest\snames\sin\se_select.test.
|
||||
D 2010-09-08T19:16:49
|
||||
C Add\stests\sfor\ssub-select\sstatements\sin\sthe\sFROM\sclause\sof\sa\sSELECT\sto\se_select.test.
|
||||
D 2010-09-09T10:00:44
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -350,7 +350,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 59c4dd36b2cb22f1c9fcda9e6b3e02aaa2b07d0b
|
||||
F test/e_select.test 1adce7a2fcb698518eedddf3bc729c039e6bbedd
|
||||
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
|
||||
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
|
||||
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
|
||||
@ -857,7 +857,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 727ced6babf8aca87a69632949a7a0ce9bc2be89
|
||||
R 43c601d10fdda05cfc79f09f9a1b17a8
|
||||
P 8fe34faf6b8ddbb8ddd23418163650e846104328
|
||||
R 9bfaedbd899efa5c6570049f959ec78c
|
||||
U dan
|
||||
Z 45c98c48ac5be1716fdcb5e5aefa5d66
|
||||
Z 71f159ae174766adb4ac41d95f0a3515
|
||||
|
@ -1 +1 @@
|
||||
8fe34faf6b8ddbb8ddd23418163650e846104328
|
||||
2c6b1ca952be9979b8079431c2abad28419b6256
|
@ -609,7 +609,7 @@ foreach {tn sql} {
|
||||
# return values.
|
||||
#
|
||||
proc te_read_tbl {db tbl} {
|
||||
te_read_sql $db "SELECT * FROM $tbl"
|
||||
te_read_sql $db "SELECT * FROM '$tbl'"
|
||||
}
|
||||
proc te_read_sql {db sql} {
|
||||
set S [sqlite3_prepare_v2 $db $sql -1 DUMMY]
|
||||
@ -704,6 +704,28 @@ proc te_tbljoin {db t1 t2 args} {
|
||||
te_join [te_read_tbl $db $t1] [te_read_tbl $db $t2] {*}$args
|
||||
}
|
||||
|
||||
proc te_apply_affinity {affinity typevar valvar} {
|
||||
upvar $typevar type
|
||||
upvar $valvar val
|
||||
|
||||
switch -- $affinity {
|
||||
integer {
|
||||
if {[string is double $val]} { set type REAL }
|
||||
if {[string is wideinteger $val]} { set type INTEGER }
|
||||
if {$type == "REAL" && int($val)==$val} {
|
||||
set type INTEGER
|
||||
set val [expr {int($val)}]
|
||||
}
|
||||
}
|
||||
text {
|
||||
set type TEXT
|
||||
}
|
||||
none { }
|
||||
|
||||
default { error "invalid affinity: $affinity" }
|
||||
}
|
||||
}
|
||||
|
||||
#----------
|
||||
# te_equals ?SWITCHES? c1 c2 cols1 row1 cols2 row2
|
||||
#
|
||||
@ -713,12 +735,17 @@ proc te_equals {args} {
|
||||
foreach {c1 c2 cols1 row1 cols2 row2} [lrange $args end-5 end] break
|
||||
|
||||
set nocase 0
|
||||
set affinity none
|
||||
|
||||
foreach a [lrange $args 0 end-6] {
|
||||
for {set i 0} {$i < ([llength $args]-6)} {incr i} {
|
||||
set a [lindex $args $i]
|
||||
switch -- $a {
|
||||
-nocase {
|
||||
set nocase 1
|
||||
}
|
||||
-affinity {
|
||||
set affinity [string tolower [lindex $args [incr i]]]
|
||||
}
|
||||
default {
|
||||
error "invalid arguments to te_equals"
|
||||
}
|
||||
@ -733,10 +760,16 @@ proc te_equals {args} {
|
||||
set v1 [lindex $row1 $idx1 1]
|
||||
set v2 [lindex $row2 $idx2 1]
|
||||
|
||||
te_apply_affinity $affinity t1 v1
|
||||
te_apply_affinity $affinity t2 v2
|
||||
|
||||
if {$t1 == "NULL" || $t2 == "NULL"} { return 0 }
|
||||
if {$nocase && $t1 == "TEXT"} { set v1 [string tolower $v1] }
|
||||
if {$nocase && $t2 == "TEXT"} { set v2 [string tolower $v2] }
|
||||
return [expr {$t1 == $t2 && $v1 == $v2}]
|
||||
|
||||
|
||||
set res [expr {$t1 == $t2 && [string equal $v1 $v2]}]
|
||||
return $res
|
||||
}
|
||||
|
||||
proc te_false {args} { return 0 }
|
||||
@ -802,10 +835,10 @@ do_execsql_test e_select-2.0 {
|
||||
} {}
|
||||
|
||||
foreach {tn indexes} {
|
||||
e_select-2.1 { }
|
||||
e_select-2.2 { CREATE INDEX i1 ON t1(a) }
|
||||
e_select-2.3 { CREATE INDEX i1 ON t2(a) }
|
||||
e_select-2.4 { CREATE INDEX i1 ON t3(b) }
|
||||
e_select-2.1.1 { }
|
||||
e_select-2.1.2 { CREATE INDEX i1 ON t1(a) }
|
||||
e_select-2.1.3 { CREATE INDEX i1 ON t2(a) }
|
||||
e_select-2.1.4 { CREATE INDEX i1 ON t3(b) }
|
||||
} {
|
||||
|
||||
catchsql { DROP INDEX i1 }
|
||||
@ -965,20 +998,86 @@ foreach {tn indexes} {
|
||||
]
|
||||
}
|
||||
|
||||
# XXXEVIDENCE-OF: R-55824-40976 A sub-select specified in the join-source
|
||||
do_execsql_test e_select-2.2.0 {
|
||||
CREATE TABLE t4(x TEXT COLLATE nocase);
|
||||
CREATE TABLE t5(y INTEGER, z TEXT COLLATE binary);
|
||||
|
||||
INSERT INTO t4 VALUES('2.0');
|
||||
INSERT INTO t4 VALUES('TWO');
|
||||
INSERT INTO t5 VALUES(2, 'two');
|
||||
} {}
|
||||
|
||||
# EVIDENCE-OF: R-55824-40976 A sub-select specified in the join-source
|
||||
# following the FROM clause in a simple SELECT statement is handled as
|
||||
# if it was a table containing the data returned by executing the
|
||||
# sub-select statement.
|
||||
#
|
||||
foreach {tn subselect select script} {
|
||||
1 "SELECT * FROM t2" "SELECT * FROM t1 JOIN (%ss%)"
|
||||
{t1 %ss%}
|
||||
} {
|
||||
execsql "CREATE TEMP TABLE sstemp AS $subselect"
|
||||
set ssdata [te_read_tbl db sstemp]
|
||||
execsql "DROP TABLE sstemp"
|
||||
# EVIDENCE-OF: R-42612-06757 Each column of the sub-select dataset
|
||||
# inherits the collation sequence and affinity of the corresponding
|
||||
# expression in the sub-select statement.
|
||||
#
|
||||
foreach {tn subselect select spec} {
|
||||
1 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss%"
|
||||
{t1 %ss%}
|
||||
|
||||
|
||||
2 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss% AS x ON (t1.a=x.a)"
|
||||
{t1 %ss% -on {te_equals 0 0}}
|
||||
|
||||
3 "SELECT * FROM t2" "SELECT * FROM %ss% AS x JOIN t1 ON (t1.a=x.a)"
|
||||
{%ss% t1 -on {te_equals 0 0}}
|
||||
|
||||
4 "SELECT * FROM t1, t2" "SELECT * FROM %ss% AS x JOIN t3"
|
||||
{%ss% t3}
|
||||
|
||||
5 "SELECT * FROM t1, t2" "SELECT * FROM %ss% NATURAL JOIN t3"
|
||||
{%ss% t3 -using b -on {te_equals 1 0}}
|
||||
|
||||
6 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL JOIN %ss%"
|
||||
{t3 %ss% -using b -on {te_equals -nocase 0 1}}
|
||||
|
||||
7 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL LEFT JOIN %ss%"
|
||||
{t3 %ss% -left -using b -on {te_equals -nocase 0 1}}
|
||||
|
||||
8 "SELECT count(*) AS y FROM t4" "SELECT * FROM t5, %ss% USING (y)"
|
||||
{t5 %ss% -using y -on {te_equals -affinity text 0 0}}
|
||||
|
||||
9 "SELECT count(*) AS y FROM t4" "SELECT * FROM %ss%, t5 USING (y)"
|
||||
{%ss% t5 -using y -on {te_equals -affinity text 0 0}}
|
||||
|
||||
10 "SELECT x AS y FROM t4" "SELECT * FROM %ss% JOIN t5 USING (y)"
|
||||
{%ss% t5 -using y -on {te_equals -nocase -affinity integer 0 0}}
|
||||
|
||||
11 "SELECT x AS y FROM t4" "SELECT * FROM t5 JOIN %ss% USING (y)"
|
||||
{t5 %ss% -using y -on {te_equals -nocase -affinity integer 0 0}}
|
||||
|
||||
12 "SELECT y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)"
|
||||
{%ss% t4 -using x -on {te_equals -nocase -affinity integer 0 0}}
|
||||
|
||||
13 "SELECT y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)"
|
||||
{t4 %ss% -using x -on {te_equals -nocase -affinity integer 0 0}}
|
||||
|
||||
14 "SELECT +y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)"
|
||||
{%ss% t4 -using x -on {te_equals -nocase -affinity text 0 0}}
|
||||
|
||||
15 "SELECT +y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)"
|
||||
{t4 %ss% -using x -on {te_equals -nocase -affinity text 0 0}}
|
||||
} {
|
||||
|
||||
# Create a temporary table named %ss% containing the data returned by
|
||||
# the sub-select. Then have the [te_tbljoin] proc use this table to
|
||||
# compute the expected results of the $select query. Drop the temporary
|
||||
# table before continuing.
|
||||
#
|
||||
execsql "CREATE TEMP TABLE '%ss%' AS $subselect"
|
||||
set te [eval te_tbljoin db $spec]
|
||||
execsql "DROP TABLE '%ss%'"
|
||||
|
||||
# Check that the actual data returned by the $select query is the same
|
||||
# as the expected data calculated using [te_tbljoin] above.
|
||||
#
|
||||
te_dataset_eq_unordered e_select-2.2.1.$tn [
|
||||
te_read_sql db [string map [list %ss% "($subselect)"] $select]
|
||||
] $te
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user