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.262 2008/10/23 05:45:07 danielk1977 Exp $ +** @(#) $Id: parse.y,v 1.263 2008/12/03 23:23:41 drh Exp $ */ // All token codes are small integers with #defines that begin with "TK_" %token_prefix TK_ @@ -442,11 +442,11 @@ %destructor from {sqlite3SrcListDelete(pParse->db, $$);} // A complete FROM clause. // from(A) ::= . {A = sqlite3DbMallocZero(pParse->db, sizeof(*A));} -from(A) ::= FROM seltablist(X). { +from(A) ::= FROM seltablist(X). { A = X; sqlite3SrcListShiftJoinType(A); } // "seltablist" is a "Select Table List" - the content of the FROM clause @@ -460,26 +460,37 @@ seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) using_opt(U). { A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); sqlite3SrcListIndexedBy(pParse, A, &I); } %ifndef SQLITE_OMIT_SUBQUERY - seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP + seltablist(A) ::= stl_prefix(X) LP select(S) RP 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 && 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); + A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U); + } } // A seltablist_paren nonterminal represents anything in a FROM that // is contained inside parentheses. This can be either a subquery or // a grouping of table and subqueries. // - %type seltablist_paren {Select*} - %destructor seltablist_paren {sqlite3SelectDelete(pParse->db, $$);} - seltablist_paren(A) ::= select(S). {A = S;} - seltablist_paren(A) ::= seltablist(F). { - sqlite3SrcListShiftJoinType(F); - A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); - } +// %type seltablist_paren {Select*} +// %destructor seltablist_paren {sqlite3SelectDelete(pParse->db, $$);} +// seltablist_paren(A) ::= select(S). {A = S;} +// seltablist_paren(A) ::= seltablist(F). { +// sqlite3SrcListShiftJoinType(F); +// A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); +// } %endif SQLITE_OMIT_SUBQUERY %type dbnm {Token} dbnm(A) ::= . {A.z=0; A.n=0;} dbnm(A) ::= DOT nm(X). {A = X;}