Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** 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" /* ** This routine is called when a new SQL statement is beginning to @@ -3219,12 +3219,17 @@ assert( pAlias!=0 ); if( pAlias->n ){ 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; } /* ** Add an INDEXED BY or NOT INDEXED clause to the most recently added Index: src/parse.y ================================================================== --- src/parse.y +++ src/parse.y @@ -12,11 +12,11 @@ ** This file contains SQLite's grammar for SQL. Process this file ** using the lemon parser generator to generate C code that runs ** 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_" %token_prefix TK_ @@ -502,13 +502,11 @@ as(Z) on_opt(N) using_opt(U). { A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); } 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; sqlite3SrcListShiftJoinType(F); pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); ADDED test/tkt3935.test Index: test/tkt3935.test ================================================================== --- /dev/null +++ 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