mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
:-) (CVS 77)
FossilOrigin-Name: b3fb15ccde399318bde8c87362ecaa3a744f0680
This commit is contained in:
@ -24,25 +24,26 @@
|
||||
# focus of this file is testing UNION, INTERSECT and EXCEPT operators
|
||||
# in SELECT statements.
|
||||
#
|
||||
# $Id: select4.test,v 1.1 2000/06/08 00:28:52 drh Exp $
|
||||
# $Id: select4.test,v 1.2 2000/06/08 01:55:31 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Build some test data
|
||||
#
|
||||
set fd [open data1.txt w]
|
||||
for {set i 1} {$i<32} {incr i} {
|
||||
for {set j 0} {pow(2,$j)<$i} {incr j} {}
|
||||
puts $fd "$i\t$j"
|
||||
}
|
||||
close $fd
|
||||
execsql {
|
||||
CREATE TABLE t1(n int, log int);
|
||||
COPY t1 FROM 'data1.txt'
|
||||
}
|
||||
file delete data1.txt
|
||||
|
||||
do_test select4-1.0 {
|
||||
set fd [open data1.txt w]
|
||||
for {set i 1} {$i<32} {incr i} {
|
||||
for {set j 0} {pow(2,$j)<$i} {incr j} {}
|
||||
puts $fd "$i\t$j"
|
||||
}
|
||||
close $fd
|
||||
execsql {
|
||||
CREATE TABLE t1(n int, log int);
|
||||
COPY t1 FROM 'data1.txt'
|
||||
}
|
||||
file delete data1.txt
|
||||
execsql {SELECT DISTINCT log FROM t1 ORDER BY log}
|
||||
} {0 1 2 3 4 5}
|
||||
|
||||
@ -70,6 +71,15 @@ do_test select4-1.2 {
|
||||
ORDER BY log;
|
||||
}
|
||||
} {0 1 2 2 3 3 3 3}
|
||||
do_test select4-1.3 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1 ORDER BY log
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY clause should come after UNION ALL not before}}
|
||||
|
||||
# Union operator
|
||||
#
|
||||
@ -89,6 +99,15 @@ do_test select4-2.2 {
|
||||
ORDER BY log;
|
||||
}
|
||||
} {0 1 2 2 3 3 3 3}
|
||||
do_test select4-2.3 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1 ORDER BY log
|
||||
UNION
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY clause should come after UNION not before}}
|
||||
|
||||
# Except operator
|
||||
#
|
||||
@ -108,6 +127,15 @@ do_test select4-3.2 {
|
||||
ORDER BY log;
|
||||
}
|
||||
} {0 1 2 2}
|
||||
do_test select4-3.3 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1 ORDER BY log
|
||||
EXCEPT
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY clause should come after EXCEPT not before}}
|
||||
|
||||
# Intersect operator
|
||||
#
|
||||
@ -127,5 +155,93 @@ do_test select4-4.2 {
|
||||
ORDER BY log;
|
||||
}
|
||||
} {3}
|
||||
do_test select4-4.3 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1 ORDER BY log
|
||||
INTERSECT
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY clause should come after INTERSECT not before}}
|
||||
|
||||
# Various error messages while processing UNION or INTERSECT
|
||||
#
|
||||
do_test select4-5.1 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t2
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {no such table: t2}}
|
||||
do_test select4-5.2 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log AS "xyzzy" FROM t1
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY xyzzy;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {0 1 2 3 4 5 5 6 7 8}}
|
||||
do_test select4-5.2b {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log xyzzy FROM t1
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY 'xyzzy';
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {0 1 2 3 4 5 5 6 7 8}}
|
||||
do_test select4-5.2c {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY 'xyzzy';
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY term number 1 does not match any result column}}
|
||||
do_test select4-5.2d {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1
|
||||
INTERSECT
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY 'xyzzy';
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {ORDER BY term number 1 does not match any result column}}
|
||||
do_test select4-5.2e {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log FROM t1
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY n;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {0 1 2 3 4 5 5 6 7 8}}
|
||||
do_test select4-5.3 {
|
||||
set v [catch {execsql {
|
||||
SELECT DISTINCT log, n FROM t1
|
||||
UNION ALL
|
||||
SELECT n FROM t1 WHERE log=3
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}
|
||||
do_test select4-5.4 {
|
||||
set v [catch {execsql {
|
||||
SELECT log FROM t1 WHERE n=2
|
||||
UNION ALL
|
||||
SELECT log FROM t1 WHERE n=3
|
||||
UNION ALL
|
||||
SELECT log FROM t1 WHERE n=4
|
||||
UNION ALL
|
||||
SELECT log FROM t1 WHERE n=5
|
||||
ORDER BY log;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {1 2 2 3}}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user