Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | :-) (CVS 77) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
b3fb15ccde399318bde8c87362ecaa3a |
User & Date: | drh 2000-06-08 01:55:30.000 |
Context
2000-06-08
| ||
11:13 | :-) (CVS 78) (check-in: 923c14fe12 user: drh tags: trunk) | |
01:55 | :-) (CVS 77) (check-in: b3fb15ccde user: drh tags: trunk) | |
00:28 | :-) (CVS 76) (check-in: 1902923308 user: drh tags: trunk) | |
Changes
Changes to src/select.c.
︙ | ︙ | |||
20 21 22 23 24 25 26 | ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements. ** | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements. ** ** $Id: select.c,v 1.19 2000/06/08 01:55:30 drh Exp $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. */ |
︙ | ︙ | |||
362 363 364 365 366 367 368 | if( mustComplete ){ for(i=0; i<pOrderBy->nExpr; i++){ pOrderBy->a[i].done = 0; } } if( fillInColumnList(pParse, pSelect) ){ return 1; } if( pSelect->pPrior ){ | | > > > < | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | if( mustComplete ){ for(i=0; i<pOrderBy->nExpr; i++){ pOrderBy->a[i].done = 0; } } if( fillInColumnList(pParse, pSelect) ){ return 1; } if( pSelect->pPrior ){ 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++){ if( pEList->a[i].zName && (pE->op==TK_ID || pE->op==TK_STRING) ){ char *zName = pEList->a[i].zName; char *zLabel = 0; sqliteSetNString(&zLabel, pE->token.z, pE->token.n, 0); sqliteDequote(zLabel); if( sqliteStrICmp(zName, zLabel)==0 ){ match = 1; } } if( match==0 && sqliteExprCompare(pE, pEList->a[i].pExpr) ){ match = 1; } if( match ){ pE->op = TK_FIELD; pE->iField = j; pE->iTable = iTable; pOrderBy->a[i].done = 1; break; } } if( !match && mustComplete ){ char zBuf[30]; sprintf(zBuf,"%d",i+1); sqliteSetString(&pParse->zErrMsg, "ORDER BY term number ", zBuf, " does not match any result column", 0); pParse->nErr++; nErr++; break; |
︙ | ︙ |
Changes to test/select4.test.
︙ | ︙ | |||
20 21 22 23 24 25 26 | # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing UNION, INTERSECT and EXCEPT operators # in SELECT statements. # | | < | | | | | | | | | | | > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing UNION, INTERSECT and EXCEPT operators # in SELECT statements. # # $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 { execsql {SELECT DISTINCT log FROM t1 ORDER BY log} } {0 1 2 3 4 5} # Union All operator # do_test select4-1.1a { lsort [execsql {SELECT DISTINCT log FROM t1}] |
︙ | ︙ | |||
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 UNION ALL SELECT n FROM t1 WHERE log=3) ORDER BY log; } } {0 1 2 2 3 3 3 3} # Union operator # do_test select4-2.1 { execsql { SELECT DISTINCT log FROM t1 UNION SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {0 1 2 3 4 5 6 7 8} do_test select4-2.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 UNION SELECT n FROM t1 WHERE log=3) ORDER BY log; } } {0 1 2 2 3 3 3 3} # Except operator # do_test select4-3.1 { execsql { SELECT DISTINCT log FROM t1 EXCEPT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {0 1 2 3 4} do_test select4-3.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 EXCEPT SELECT n FROM t1 WHERE log=3) ORDER BY log; } } {0 1 2 2} # Intersect operator # do_test select4-4.1 { execsql { SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {5} do_test select4-4.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3) ORDER BY log; } } {3} finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 UNION ALL SELECT n FROM t1 WHERE log=3) 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 # do_test select4-2.1 { execsql { SELECT DISTINCT log FROM t1 UNION SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {0 1 2 3 4 5 6 7 8} do_test select4-2.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 UNION SELECT n FROM t1 WHERE log=3) 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 # do_test select4-3.1 { execsql { SELECT DISTINCT log FROM t1 EXCEPT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {0 1 2 3 4} do_test select4-3.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 EXCEPT SELECT n FROM t1 WHERE log=3) 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 # do_test select4-4.1 { execsql { SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3 ORDER BY log; } } {5} do_test select4-4.2 { execsql { SELECT log FROM t1 WHERE n IN (SELECT DISTINCT log FROM t1 INTERSECT SELECT n FROM t1 WHERE log=3) 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 |