1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix the LIMIT clause so that it applies to the entire query in a compound

query.  Prior to this change LIMITs on compound queries did not work at
all.  Ticket #393. (CVS 1058)

FossilOrigin-Name: 543479e3aed77976a0c689cf40811bf88353f706
This commit is contained in:
drh
2003-07-20 01:16:46 +00:00
parent e5f50722b4
commit 7b58daeafe
7 changed files with 198 additions and 63 deletions

View File

@ -12,7 +12,7 @@
# focus of this file is testing the LIMIT ... OFFSET ... clause
# of SELECT statements.
#
# $Id: limit.test,v 1.9 2003/07/16 11:51:36 drh Exp $
# $Id: limit.test,v 1.10 2003/07/20 01:16:48 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -213,4 +213,84 @@ do_test limit-6.8 {
}
} {}
# Make sure LIMIT works well with compound SELECT statements.
# Ticket #393
#
do_test limit-7.1.1 {
catchsql {
SELECT x FROM t2 LIMIT 5 UNION ALL SELECT a FROM t6;
}
} {1 {LIMIT clause should come after UNION ALL not before}}
do_test limit-7.1.2 {
catchsql {
SELECT x FROM t2 LIMIT 5 UNION SELECT a FROM t6;
}
} {1 {LIMIT clause should come after UNION not before}}
do_test limit-7.1.3 {
catchsql {
SELECT x FROM t2 LIMIT 5 EXCEPT SELECT a FROM t6 LIMIT 3;
}
} {1 {LIMIT clause should come after EXCEPT not before}}
do_test limit-7.1.4 {
catchsql {
SELECT x FROM t2 LIMIT 0,5 INTERSECT SELECT a FROM t6;
}
} {1 {LIMIT clause should come after INTERSECT not before}}
do_test limit-7.2 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 5;
}
} {31 30 1 2 3}
do_test limit-7.3 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 3 OFFSET 1;
}
} {30 1 2}
do_test limit-7.4 {
execsql {
SELECT x FROM t2 UNION ALL SELECT a FROM t6 ORDER BY 1 LIMIT 3 OFFSET 1;
}
} {2 3 4}
do_test limit-7.5 {
execsql {
SELECT x FROM t2 UNION SELECT x+2 FROM t2 LIMIT 2 OFFSET 1;
}
} {31 32}
do_test limit-7.6 {
execsql {
SELECT x FROM t2 UNION SELECT x+2 FROM t2 ORDER BY 1 DESC LIMIT 2 OFFSET 1;
}
} {32 31}
do_test limit-7.7 {
execsql {
SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 LIMIT 2;
}
} {11 12}
do_test limit-7.8 {
execsql {
SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 ORDER BY 1 DESC LIMIT 2;
}
} {13 12}
do_test limit-7.9 {
execsql {
SELECT a+26 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
}
} {30}
do_test limit-7.10 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
}
} {30}
do_test limit-7.11 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1 OFFSET 1;
}
} {31}
do_test limit-7.12 {
execsql {
SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2
ORDER BY 1 DESC LIMIT 1 OFFSET 1;
}
} {30}
finish_test