-C :-)\s(CVS\s76)
-D 2000-06-08T00:28:52
+C :-)\s(CVS\s77)
+D 2000-06-08T01:55:30
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
F Makefile.in 17ba1ccf8d2d40c627796bba8f72952365d6d644
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
F src/insert.c ac4edfff474589c00b2490f206317dc5822122e5
F src/main.c e3297835b8e38ca726ac73f2c2bdb7cf08103197
F src/parse.y bb2126c8313c111184b89af8675911dcb57f1dca
-F src/select.c 5d97d2542abe4675d31d24df7ec2b04f78d89a7f
+F src/select.c 561f34a8586ea6f459db58c72cdca5ab1b860eb4
F src/shell.c 3f4afc39a36e4824e8aa262623fd03568874799e
F src/sqlite.h 58da0a8590133777b741f9836beaef3d58f40268
F src/sqliteInt.h 816c491f9896090dde03804fd3f60346456b99df
F test/select1.test 64703852af34c85bb31b0a74bd73b340e8267f42
F test/select2.test 3cd3c0f9d67e98b1b54af5853679b4a111224410
F test/select3.test 73ae8c7b80c4e03a9c29d12f2ea1782e28b8e61f
-F test/select4.test c9b4b4ab9fefee41859b05f42d1237e2c4080612
+F test/select4.test 5d6aa52fde345c51784202159bf9695cd9cc68b7
F test/sort.test d582086c4bb7df3fbf50aa72e69d7e235e9f8e31
F test/subselect.test bf8b251a92fb091973c1c469ce499dc9648a41d5
F test/table.test 85d6f410d127ec508c6640f02d7c40d218414e81
F www/changes.tcl 04e66b4257589ff78a7e1de93e9dda4725fb03d6
F www/index.tcl 52e29a4eeda8d59e91af43c61fef177c5f2ffd53
F www/sqlite.tcl 2f933ce18cffd34a0a020a82435ab937137970fd
-P c47d552e7e275dcc03a687e2a874e8e6e1eeb109
-R 26d7a98ed8d3a0f1eb183339f6803dc3
+P 19029233082e319d4bfd94b22a694c917d8f0296
+R b1183616f00c47fc9f7cd8d8d2c10c1d
U drh
-Z aff0389b3f704be27fd43dfadeac47e1
+Z cce8eb07b73528634ac6a71a0e43523e
** This file contains C code routines that are called by the parser
** to handle SELECT statements.
**
-** $Id: select.c,v 1.18 2000/06/08 00:28:52 drh Exp $
+** $Id: select.c,v 1.19 2000/06/08 01:55:30 drh Exp $
*/
#include "sqliteInt.h"
return 1;
}
if( pSelect->pPrior ){
- matchOrderbyToColumn(pParse, pSelect->pPrior, pOrderBy, iTable, 0);
+ if( matchOrderbyToColumn(pParse, pSelect->pPrior, pOrderBy, iTable, 0) ){
+ return 1;
+ }
}
pEList = pSelect->pEList;
for(i=0; i<pOrderBy->nExpr; i++){
Expr *pE = pOrderBy->a[i].pExpr;
+ int match = 0;
if( pOrderBy->a[i].done ) continue;
for(j=0; j<pEList->nExpr; j++){
- int match = 0;
if( pEList->a[i].zName && (pE->op==TK_ID || pE->op==TK_STRING) ){
char *zName = pEList->a[i].zName;
char *zLabel = 0;
- sqliteSetString(&zLabel, pE->token.z, pE->token.n, 0);
+ sqliteSetNString(&zLabel, pE->token.z, pE->token.n, 0);
sqliteDequote(zLabel);
if( sqliteStrICmp(zName, zLabel)==0 ){
match = 1;
break;
}
}
- if( mustComplete ){
+ if( !match && mustComplete ){
char zBuf[30];
sprintf(zBuf,"%d",i+1);
sqliteSetString(&pParse->zErrMsg, "ORDER BY term number ", zBuf,
# 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}
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
#
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
#
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
#
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