From: drh Date: Fri, 31 Jan 2003 17:16:36 +0000 (+0000) Subject: Allow double-quoted strings as string constants in the IN operator. As a X-Git-Tag: version-3.6.10~5217 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88eee38afda94f0ac0371626455dc875767e1263;p=thirdparty%2Fsqlite.git Allow double-quoted strings as string constants in the IN operator. As a side-efffect, allow the GROUP BY clause to refer to columns by their integer column number. Ticket #237. (CVS 856) FossilOrigin-Name: 187d9c405891e543fc706f8ddb41f3966a842214 --- diff --git a/manifest b/manifest index e9a033cb93..3e9f116a07 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\stesting\sand\sbug\sfixing\swith\sthe\snon-callback\sAPI.\s\sUpdated\sthe\nC/C++\sinterface\sdocument\sto\sdescribe\sthe\snon-callback\sAPI.\s(CVS\s855) -D 2003-01-29T22:58:26 +C Allow\sdouble-quoted\sstrings\sas\sstring\sconstants\sin\sthe\sIN\soperator.\s\sAs\sa\nside-efffect,\sallow\sthe\sGROUP\sBY\sclause\sto\srefer\sto\scolumns\sby\stheir\sinteger\ncolumn\snumber.\s\sTicket\s#237.\s(CVS\s856) +D 2003-01-31T17:16:37 F Makefile.in 6606854b1512f185b8e8c779b8d7fc2750463d64 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -24,7 +24,7 @@ F src/btree.h 17710339f7a8f46e3c7d6d0d4648ef19c584ffda F src/build.c 6e0310086b8e2deef74f0d4fb3297c4e8fcf6222 F src/delete.c cbd499f3f9297504c42e328af89bef1a2113d04c F src/encode.c faf03741efe921755ec371cf4a6984536de00042 -F src/expr.c 359ae28321ce78d20ef38f4fd6ee7429b100186f +F src/expr.c bd690b3a6174e97a0f16800e78c8aeae749a4e71 F src/func.c 90c583f0b91220f7cd411a2407deaf9327245d63 F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8 @@ -38,7 +38,7 @@ F src/pager.h 540833e8cb826b80ce2e39aa917deee5e12db626 F src/parse.y cdaed5009423d851708848bd279147c268e6022e F src/printf.c f8fd911a8738f9b2eb07aca2870473d34707055d F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe -F src/select.c 13b8e5ea8aacaf204468518aed7b054a583f2f25 +F src/select.c 77018f471976a80648dfb3996de52c2ddf5b8f9e F src/shell.c cbb29252f0bd7b144d1e3126e64e17e5a314f2fd F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e F src/sqlite.h.in 6f648803f2ffb9beb35cb1cfa42b323d55519171 @@ -72,7 +72,7 @@ F test/expr.test 290e2617b89b5c5e3bf71f19367d285102128be4 F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7 F test/format3.test 64ab6c4db132b28a645996d413530f7b2a462cc2 F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4 -F test/in.test 15428c85d141edda7543bfc3f9a32ce65193717b +F test/in.test 3171a2b3170a8223665c1a4f26be5f3eda36cc4b F test/index.test 2a5a1b654f50ca0768fb10ae44b72e6a776b1f18 F test/insert.test a122afb86911e77c181d912348866a5b1a61eeab F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f @@ -97,7 +97,7 @@ F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d F test/rowid.test 4c55943300cddf73dd0f88d40a268cab14c83274 F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150 F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4 -F test/select3.test ba35d6611e8bfe526a89355da39dde482d4ecd41 +F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76 F test/select4.test 10ba54f24ef6ca7958a7045b001079378db2370c F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac F test/select6.test efb8d0c07a440441db87db2c4ade6904e1407e85 @@ -155,7 +155,7 @@ F www/speed.tcl 4d463e2aea41f688ed320a937f93ff885be918c3 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P ccc82f1ab4539a60ee5cc2625743c5389f9ccd8e -R 71f3061b9977afdcd191ea15858b4f86 +P af1e9299468aa70d7d91e7a5445ba391ccc8ff8b +R abe368a1e78797105f7fab70a2918394 U drh -Z da2509caf930012c96a4743c5b339fae +Z cccb4416844848dad1dd0c24ba4f2710 diff --git a/manifest.uuid b/manifest.uuid index 1534f006ef..c836ed0f7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -af1e9299468aa70d7d91e7a5445ba391ccc8ff8b \ No newline at end of file +187d9c405891e543fc706f8ddb41f3966a842214 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 6b431a6da6..8ee9802d5d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.87 2003/01/29 18:46:52 drh Exp $ +** $Id: expr.c,v 1.88 2003/01/31 17:16:37 drh Exp $ */ #include "sqliteInt.h" #include @@ -301,7 +301,6 @@ int sqliteExprIsConstant(Expr *p){ case TK_DOT: return 0; case TK_STRING: - return p->token.z[0]=='\''; case TK_INTEGER: case TK_FLOAT: return 1; diff --git a/src/select.c b/src/select.c index 4998a53520..cf93a9a13f 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.124 2003/01/29 14:06:09 drh Exp $ +** $Id: select.c,v 1.125 2003/01/31 17:16:37 drh Exp $ */ #include "sqliteInt.h" @@ -2034,9 +2034,19 @@ int sqliteSelect( } if( pOrderBy ){ for(i=0; inExpr; i++){ + int iCol; Expr *pE = pOrderBy->a[i].pExpr; + if( sqliteExprIsInteger(pE, &iCol) && iCol>0 && iCol<=pEList->nExpr ){ + sqliteExprDelete(pE); + pE = pOrderBy->a[i].pExpr = sqliteExprDup(pEList->a[iCol-1].pExpr); + } + if( sqliteExprResolveIds(pParse, base, pTabList, pEList, pE) ){ + goto select_end; + } + if( sqliteExprCheck(pParse, pE, isAgg, 0) ){ + goto select_end; + } if( sqliteExprIsConstant(pE) ){ - int iCol; if( sqliteExprIsInteger(pE, &iCol)==0 ){ sqliteSetString(&pParse->zErrMsg, "ORDER BY terms must not be non-integer constants", 0); @@ -2050,25 +2060,16 @@ int sqliteSelect( pParse->nErr++; goto select_end; } - sqliteExprDelete(pE); - pE = pOrderBy->a[i].pExpr = sqliteExprDup(pEList->a[iCol-1].pExpr); - } - if( sqliteExprResolveIds(pParse, base, pTabList, pEList, pE) ){ - goto select_end; - } - if( sqliteExprCheck(pParse, pE, isAgg, 0) ){ - goto select_end; } } } if( pGroupBy ){ for(i=0; inExpr; i++){ + int iCol; Expr *pE = pGroupBy->a[i].pExpr; - if( sqliteExprIsConstant(pE) ){ - sqliteSetString(&pParse->zErrMsg, - "GROUP BY expressions should not be constant", 0); - pParse->nErr++; - goto select_end; + if( sqliteExprIsInteger(pE, &iCol) && iCol>0 && iCol<=pEList->nExpr ){ + sqliteExprDelete(pE); + pE = pGroupBy->a[i].pExpr = sqliteExprDup(pEList->a[iCol-1].pExpr); } if( sqliteExprResolveIds(pParse, base, pTabList, pEList, pE) ){ goto select_end; @@ -2076,6 +2077,21 @@ int sqliteSelect( if( sqliteExprCheck(pParse, pE, isAgg, 0) ){ goto select_end; } + if( sqliteExprIsConstant(pE) ){ + if( sqliteExprIsInteger(pE, &iCol)==0 ){ + sqliteSetString(&pParse->zErrMsg, + "GROUP BY terms must not be non-integer constants", 0); + pParse->nErr++; + goto select_end; + }else if( iCol<=0 || iCol>pEList->nExpr ){ + char zBuf[2000]; + sprintf(zBuf,"GROUP BY column number %d out of range - should be " + "between 1 and %d", iCol, pEList->nExpr); + sqliteSetString(&pParse->zErrMsg, zBuf, 0); + pParse->nErr++; + goto select_end; + } + } } } diff --git a/test/in.test b/test/in.test index 4cbff3750d..4d53bf3a15 100644 --- a/test/in.test +++ b/test/in.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the IN and BETWEEN operator. # -# $Id: in.test,v 1.8 2002/10/30 22:42:59 drh Exp $ +# $Id: in.test,v 1.9 2003/01/31 17:16:37 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -265,5 +265,17 @@ do_test in-7.7 { } } {1 2 3 4 6 8 10} +do_test in-8.1 { + execsql { + SELECT b FROM t1 WHERE a IN ('hello','there') + } +} {world} +do_test in-8.2 { + execsql { + SELECT b FROM t1 WHERE a IN ("hello",'there') + } +} {world} + + finish_test diff --git a/test/select3.test b/test/select3.test index af050f60ab..5286f513e6 100644 --- a/test/select3.test +++ b/test/select3.test @@ -12,7 +12,7 @@ # focus of this file is testing aggregate functions and the # GROUP BY and HAVING clauses of SELECT statements. # -# $Id: select3.test,v 1.7 2002/12/03 02:34:50 drh Exp $ +# $Id: select3.test,v 1.8 2003/01/31 17:16:37 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -86,9 +86,34 @@ do_test select3-2.8 { } {11 15 9 8 7 4 5 2 3 1 1 1} do_test select3-2.9 { catchsql { - SELECT log, count(*) FROM t1 GROUP BY 8 ORDER BY log; + SELECT log, count(*) FROM t1 GROUP BY 'x' ORDER BY log; } -} {1 {GROUP BY expressions should not be constant}} +} {1 {GROUP BY terms must not be non-integer constants}} +do_test select3-2.10 { + catchsql { + SELECT log, count(*) FROM t1 GROUP BY 0 ORDER BY log; + } +} {1 {GROUP BY column number 0 out of range - should be between 1 and 2}} +do_test select3-2.11 { + catchsql { + SELECT log, count(*) FROM t1 GROUP BY 3 ORDER BY log; + } +} {1 {GROUP BY column number 3 out of range - should be between 1 and 2}} +do_test select3-2.12 { + catchsql { + SELECT log, count(*) FROM t1 GROUP BY 1 ORDER BY log; + } +} {0 {0 1 1 1 2 2 3 4 4 8 5 15}} +#do_test select3-2.13 { +# catchsql { +# SELECT log, count(*) FROM t1 GROUP BY 2 ORDER BY log; +# } +#} {0 {0 1 1 1 2 2 3 4 4 8 5 15}} +#do_test select3-2.14 { +# catchsql { +# SELECT log, count(*) FROM t1 GROUP BY count(*) ORDER BY log; +# } +#} {0 {0 1 1 1 2 2 3 4 4 8 5 15}} # Cannot have a HAVING without a GROUP BY #