From: drh Date: Thu, 15 Jan 2004 03:30:24 +0000 (+0000) Subject: Allow " IN " as a shorthand for X-Git-Tag: version-3.6.10~4888 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=23b2db23b4068fe57791fcfc84cd6bf862bfcc70;p=thirdparty%2Fsqlite.git Allow " IN
" as a shorthand for " IN (SELECT * FROM
)" (CVS 1180) FossilOrigin-Name: 01874d252ac44861e927dea3f5534f67e19b1fa8 --- diff --git a/manifest b/manifest index d6a201bf78..f08f144701 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reinsert\sthe\sexperimental\ssqlite_commit_hook()\sAPI.\s(CVS\s1179) -D 2004-01-15T02:44:03 +C Allow\s"\sIN\s
"\sas\sa\sshorthand\sfor\n"\sIN\s(SELECT\s*\sFROM\s
)"\s(CVS\s1180) +D 2004-01-15T03:30:25 F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -42,7 +42,7 @@ F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c F src/os.h 257c9aef1567bb20c8b767fc27fe3ee7d89104e0 F src/pager.c 289328d8efba620eae99f6c2f6062710838a3eb4 F src/pager.h 5da62c83443f26b1792cfd72c96c422f91aadd31 -F src/parse.y c65aa6c5508763806ac9734b0589b93480ec7e7a +F src/parse.y e41722d11148f34f034716652c1668ffb0ef2905 F src/pragma.c deec7342741e371f3042adaee53fcc324c5dd1d4 F src/printf.c 292a7bfc5a815cb6465e32b2d5c9fe9bd43b27f0 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe @@ -89,7 +89,7 @@ F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7 F test/format3.test 149cc166c97923fa60def047e90dd3fb32bba916 F test/func.test 000515779001ac6899eec4b54e65c6e2501279d4 F test/hook.test 1a67ce0cd64a6455d016962542f2822458dccc49 -F test/in.test 22de8a3eb27265aab723adc513bea0e76bef70c6 +F test/in.test 0de39b02ceeca90993b096822fb5a884661c5b47 F test/index.test 9295deefbdb6dedbe01be8905f0c448fe5bd4079 F test/insert.test a17b7f7017097afb2727aa5b67ceeb7ab0a120a1 F test/insert2.test c288375a64dad3295044714f0dfed4a193cf067f @@ -180,7 +180,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 -P c9ac3db8e08403398ec344757385334601a59374 -R 18a9d4e8ef4c6ab1b9d09a62e3e37863 +P 72bc84f2f18f6eeb279a4ad670310e85d154f663 +R 2bc9ea54c7ac36ba81835b3e442ee3bc U drh -Z 26c0ac18c73114906997f5ad3548f7ae +Z 123afbc81ac483920b37bfd6b69d6479 diff --git a/manifest.uuid b/manifest.uuid index da91e07dd3..22eb6ee030 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72bc84f2f18f6eeb279a4ad670310e85d154f663 \ No newline at end of file +01874d252ac44861e927dea3f5534f67e19b1fa8 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index dd52cb2455..05f9dff8d5 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.105 2003/12/06 21:43:56 drh Exp $ +** @(#) $Id: parse.y,v 1.106 2004/01/15 03:30:25 drh Exp $ */ %token_prefix TK_ %token_type {Token} @@ -664,6 +664,22 @@ expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). { A = sqliteExpr(TK_NOT, A, 0, 0); sqliteExprSpan(A,&X->span,&E); } +expr(A) ::= expr(X) IN nm(Y) dbnm(D). { + SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D); + ExprList *pList = sqliteExprListAppend(0, sqliteExpr(TK_ALL,0,0,0), 0); + A = sqliteExpr(TK_IN, X, 0, 0); + if( A ) A->pSelect = sqliteSelectNew(pList,pSrc,0,0,0,0,0,-1,0); + sqliteExprSpan(A,&X->span,D.z?&D:&Y); +} +expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). { + SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D); + ExprList *pList = sqliteExprListAppend(0, sqliteExpr(TK_ALL,0,0,0), 0); + A = sqliteExpr(TK_IN, X, 0, 0); + if( A ) A->pSelect = sqliteSelectNew(pList,pSrc,0,0,0,0,0,-1,0); + A = sqliteExpr(TK_NOT, A, 0, 0); + sqliteExprSpan(A,&X->span,D.z?&D:&Y); +} + /* CASE expressions */ expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { diff --git a/test/in.test b/test/in.test index 18409166df..9fb8adf0e5 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.10 2003/04/19 17:27:25 drh Exp $ +# $Id: in.test,v 1.11 2004/01/15 03:30:25 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -276,6 +276,28 @@ do_test in-8.2 { } } {world} - +# Test constructs of the form: expr IN tablename +# +do_test in-9.1 { + execsql { + CREATE TABLE t4 AS SELECT a FROM tb; + SELECT * FROM t4; + } +} {1 2 3 5 7 9 11} +do_test in-9.2 { + execsql { + SELECT b FROM t1 WHERE a IN t4; + } +} {32 128} +do_test in-9.3 { + execsql { + SELECT b FROM t1 WHERE a NOT IN t4; + } +} {64 256 world} +do_test in-9.4 { + catchsql { + SELECT b FROM t1 WHERE a NOT IN tb; + } +} {1 {only a single result allowed for a SELECT that is part of an expression}} finish_test