From: danielk1977 Date: Wed, 1 Jul 2009 14:56:39 +0000 (+0000) Subject: Do not ignore alias "a" in a query of the form "SELECT ... FROM (...) AS a" Fix for... X-Git-Tag: cvs-to-fossil-cutover~141 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9b87d7b90440f744801ba821ca13150eb9acb54c;p=thirdparty%2Fsqlite.git Do not ignore alias "a" in a query of the form "SELECT ... FROM (...) AS a" Fix for #3935. Also expand upon (6751) to fix some similar obscure memory leaks. (CVS 6831) FossilOrigin-Name: 42f9d1e56483a59353bff57d75f09ed67e1d9c3c --- diff --git a/manifest b/manifest index 0667b722b0..a12f4a6aa0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cause\sincremental-blob\sread/write\soperations\slock\sshared-cache\stables\sin\sthe\ssame\sway\sas\snormal\sSQL\sread/writes.\sAdd\scomplex\sassert\sstatements\sto\smake\ssure\stehe\scorrect\sshared-cache\slocks\sare\sheld\swhen\saccessing\sthe\sdatabase.\sEliminate\ssome\sredundant\schecks\sfrom\sbtree.c.\s(CVS\s6830) -D 2009-06-29T06:00:37 +C Do\snot\signore\salias\s"a"\sin\sa\squery\sof\sthe\sform\s"SELECT\s...\sFROM\s(...)\sAS\sa"\sFix\sfor\s#3935.\sAlso\sexpand\supon\s(6751)\sto\sfix\ssome\ssimilar\sobscure\smemory\sleaks.\s(CVS\s6831) +D 2009-07-01T14:56:40 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -109,7 +109,7 @@ F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btree.c 078eb41016d033707f8a94075cdde18249e48f75 F src/btree.h f70b694e8c163227369a66863b01fbff9009f323 F src/btreeInt.h 55346bc14b939ad41b297942e8b1b581e960fb99 -F src/build.c 813f6bdab5e4fb5ff94a5340c199a4930da9d66e +F src/build.c 1906bb2856f7013c9ab5ff1e0eeab033ed1c00ba F src/callback.c cb68b21b0d4ae7d11ae0e487933bce3323784dcf F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0 F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 @@ -148,7 +148,7 @@ F src/os_unix.c b64129c296e480c2827606e206ea51bb30904626 F src/os_win.c 725c38a524d168ce280446ad8761d731bc516405 F src/pager.c 04fdbede529dc9f933637301d789dc7354df6e49 F src/pager.h 5aec418bf99f568b92ae82816a1463400513726d -F src/parse.y b6e99f4208a34eb83c62f20dd67f8d9058e86768 +F src/parse.y c48ce2025d848bbd1995f811e74dced8ab30abe6 F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324 F src/pcache1.c 97e7e8e6e34026fb43b47d08532b0c02e959c26c @@ -656,6 +656,7 @@ F test/tkt3911.test 74cd324f3ba653040cc6d94cc4857b290d12d633 F test/tkt3918.test e6cdf6bfcfe9ba939d86a4238a9dc55d6eec5d42 F test/tkt3922.test 022ace32c049e3964f68492c12eb803e8e4856d8 F test/tkt3929.test 6a4c3baefb4e75127356b7d675b5df42c35c00d1 +F test/tkt3935.test 209a67e511c15adb572d536689a4e02ea4fcbb00 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/trace.test 19ffbc09885c3321d56358a5738feae8587fb377 F test/trans.test d887cb07630dc39879a322d958ad8b006137485c @@ -737,7 +738,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P ff691a6b2a302fe7978459cb8df9d56184892ee0 -R 78ed1dc8020260be15a9afc4441673c9 +P f17ef37897da9bcaf20b5acdce6840522c0a0b16 +R 0a4b75c01f05a0efdc0d38590a4ebf72 U danielk1977 -Z d5676c92a64d0bdadc5400d03f5280e3 +Z aee332d7efb75dc0b087c0e560dcdc1e diff --git a/manifest.uuid b/manifest.uuid index 5713b3af12..d5e0671925 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f17ef37897da9bcaf20b5acdce6840522c0a0b16 \ No newline at end of file +42f9d1e56483a59353bff57d75f09ed67e1d9c3c \ No newline at end of file diff --git a/src/build.c b/src/build.c index 0ec5b7b811..0bee735b7f 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.554 2009/06/25 11:50:21 drh Exp $ +** $Id: build.c,v 1.555 2009/07/01 14:56:40 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -3221,8 +3221,13 @@ SrcList *sqlite3SrcListAppendFromTerm( pItem->zAlias = sqlite3NameFromToken(db, pAlias); } pItem->pSelect = pSubquery; - pItem->pOn = pOn; - pItem->pUsing = pUsing; + if( p->nSrc>1 ){ + pItem->pOn = pOn; + pItem->pUsing = pUsing; + }else{ + sqlite3ExprDelete(db, pOn); + sqlite3IdListDelete(db, pUsing); + } return p; } diff --git a/src/parse.y b/src/parse.y index 613a7f782b..25207cfc38 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.283 2009/06/19 14:06:03 drh Exp $ +** @(#) $Id: parse.y,v 1.284 2009/07/01 14:56:40 danielk1977 Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -504,9 +504,7 @@ seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) usi } seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP as(Z) on_opt(N) using_opt(U). { - if( X==0 ){ - sqlite3ExprDelete(pParse->db, N); - sqlite3IdListDelete(pParse->db, U); + if( X==0 && Z.n==0 && N==0 && U==0 ){ A = F; }else{ Select *pSubquery; diff --git a/test/tkt3935.test b/test/tkt3935.test new file mode 100644 index 0000000000..a392a55c62 --- /dev/null +++ b/test/tkt3935.test @@ -0,0 +1,54 @@ +# 2009 July 1 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to verify that ticket #3935 has been fixed. +# +# $Id: tkt3935.test,v 1.1 2009/07/01 14:56:41 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test tkt3935.1 { + execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + } +} {} + +do_test tkt3935.2 { + execsql { SELECT j1.b FROM ( SELECT * FROM t1 INNER JOIN t2 ON a=c ) AS j1 } +} {} +do_test tkt3935.3 { + execsql { SELECT j1.b FROM (t1 INNER JOIN t2 ON a=c) AS j1 } +} {} + + +do_test tkt3935.4 { + execsql { SELECT a FROM (t1) AS t ON b USING(a) } +} {} +do_test tkt3935.5 { + execsql { SELECT a FROM (t1) AS t ON b } +} {} +do_test tkt3935.6 { + execsql { SELECT a FROM (SELECT * FROM t1) AS t ON b USING(a) } +} {} +do_test tkt3935.7 { + execsql { SELECT a FROM (SELECT * FROM t1) AS t ON b } +} {} +do_test tkt3935.8 { + execsql { SELECT a FROM t1 AS t ON b } +} {} +do_test tkt3935.9 { + execsql { SELECT a FROM t1 AS t ON b USING(a) } +} {} + +finish_test