Add a few extra tests to select9.test. (CVS 5296)

FossilOrigin-Name: 37b084fd7d7ad7f13fc9454fc25ca5aed48d4a31
This commit is contained in:
danielk1977
2008-06-24 15:39:43 +00:00
parent f6e369a119
commit 6fb6444c3e
3 changed files with 93 additions and 15 deletions
+85 -7
View File
@@ -10,7 +10,7 @@
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: select9.test,v 1.1 2008/06/24 11:21:21 danielk1977 Exp $
# $Id: select9.test,v 1.2 2008/06/24 15:39:44 danielk1977 Exp $
# The tests in this file are focused on test compound SELECT statements
# that have any or all of an ORDER BY, LIMIT or OFFSET clauses. As of
@@ -25,6 +25,8 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
#set ISQUICK 1
#-------------------------------------------------------------------------
# test_compound_select TESTNAME SELECT RESULT
#
@@ -59,13 +61,17 @@ proc test_compound_select {testname sql result} {
#return
set iLimitIncr 1
set iLimitEnd [expr $nRow+1]
set iOffsetIncr 1
set iOffsetEnd $nRow
if {[info exists ::ISQUICK] && $::ISQUICK && $nRow>=5} {
set iOffsetIncr [expr $nRow / 5]
set iLimitIncr [expr $nRow / 5]
}
for {set iOffset 0} {$iOffset <= $iOffsetEnd} {incr iOffset $iOffsetIncr} {
for {set iLimit 0} {$iLimit <= ($nRow+1)} {incr iLimit} {
set iLimitEnd [expr $nRow+$iLimitIncr]
set iOffsetEnd [expr $nRow+$iOffsetIncr]
for {set iOffset 0} {$iOffset < $iOffsetEnd} {incr iOffset $iOffsetIncr} {
for {set iLimit 0} {$iLimit < $iLimitEnd} {incr iLimit} {
set ::compound_sql "$sql LIMIT $iLimit"
if {$iOffset != 0} {
@@ -250,5 +256,77 @@ foreach indexes [list {
incr iOuterLoop
}
finish_test
do_test select9-2.0 {
execsql {
DROP INDEX i1;
DROP INDEX i2;
DROP INDEX i3;
DROP INDEX i4;
}
} {}
proc reverse {lhs rhs} {
return [string compare $rhs $lhs]
}
db collate reverse reverse
# This loop is similar to the previous one (test cases select9-1.*)
# except that the simple select statements have WHERE clauses attached
# to them. Sometimes the WHERE clause may be satisfied using the same
# index used for ORDER BY, sometimes not.
#
set iOuterLoop 1
foreach indexes [list {
/* Do not create any indexes. */
} {
CREATE INDEX i1 ON t1(a)
} {
DROP INDEX i1;
CREATE INDEX i1 ON t1(b, a)
} {
CREATE INDEX i2 ON t2(d DESC, e COLLATE REVERSE ASC);
} {
CREATE INDEX i3 ON t1(a DESC);
}] {
do_test select9-2.$iOuterLoop.1 {
execsql $indexes
} {}
test_compound_select_flippable select9-2.$iOuterLoop.2 {
SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 ORDER BY 1
} {1 one I 2 two II 3 {} {} 4 four IV 5 ten XX 6 {} {} 7 fourteen XXVIII 8 sixteen XXXII 9 {} {} 10 twenty XL}
test_compound_select_flippable select9-2.$iOuterLoop.2 {
SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 ORDER BY 2, 1
} {3 {} {} 6 {} {} 9 {} {} 4 four IV 7 fourteen XXVIII 1 one I 8 sixteen XXXII 5 ten XX 10 twenty XL 2 two II}
test_compound_select_flippable select9-2.$iOuterLoop.3 {
SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5
ORDER BY 2 COLLATE reverse, 1
} {3 {} {} 6 {} {} 9 {} {} 2 two II 10 twenty XL 5 ten XX 8 sixteen XXXII 1 one I 7 fourteen XXVIII 4 four IV}
test_compound_select_flippable select9-2.$iOuterLoop.4 {
SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5 ORDER BY 1
} {1 one I 2 two II 3 {} {} 4 four IV 5 ten XX 6 {} {} 7 fourteen XXVIII 8 sixteen XXXII 9 {} {} 10 twenty XL}
test_compound_select_flippable select9-2.$iOuterLoop.5 {
SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5 ORDER BY 2, 1
} {3 {} {} 6 {} {} 9 {} {} 4 four IV 7 fourteen XXVIII 1 one I 8 sixteen XXXII 5 ten XX 10 twenty XL 2 two II}
test_compound_select_flippable select9-2.$iOuterLoop.6 {
SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5
ORDER BY 2 COLLATE reverse, 1
} {3 {} {} 6 {} {} 9 {} {} 2 two II 10 twenty XL 5 ten XX 8 sixteen XXXII 1 one I 7 fourteen XXVIII 4 four IV}
test_compound_select select9-2.$iOuterLoop.4 {
SELECT a FROM t1 WHERE a<8 EXCEPT SELECT d FROM t2 WHERE d<=3 ORDER BY 1
} {4 5 6 7}
test_compound_select select9-2.$iOuterLoop.4 {
SELECT a FROM t1 WHERE a<8 INTERSECT SELECT d FROM t2 WHERE d<=3 ORDER BY 1
} {1 2 3}
}
finish_test