/ Check-in [42f9d1e5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 42f9d1e56483a59353bff57d75f09ed67e1d9c3c
User & Date: danielk1977 2009-07-01 14:56:40
Context
2009-07-01
16:12
Report an error if a USING or ON clause is specified following a from-list element that is not to the right of a join operator. Fix for #3846. (CVS 6832) check-in: 29b48972 user: danielk1977 tags: trunk
14:56
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) check-in: 42f9d1e5 user: danielk1977 tags: trunk
2009-06-29
06:00
Cause incremental-blob read/write operations lock shared-cache tables in the same way as normal SQL read/writes. Add complex assert statements to make sure tehe correct shared-cache locks are held when accessing the database. Eliminate some redundant checks from btree.c. (CVS 6830) check-in: f17ef378 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.554 2009/06/25 11:50:21 drh Exp $
           25  +** $Id: build.c,v 1.555 2009/07/01 14:56:40 danielk1977 Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   
    29     29   /*
    30     30   ** This routine is called when a new SQL statement is beginning to
    31     31   ** be parsed.  Initialize the pParse structure as needed.
    32     32   */
................................................................................
  3217   3217     }
  3218   3218     pItem = &p->a[p->nSrc-1];
  3219   3219     assert( pAlias!=0 );
  3220   3220     if( pAlias->n ){
  3221   3221       pItem->zAlias = sqlite3NameFromToken(db, pAlias);
  3222   3222     }
  3223   3223     pItem->pSelect = pSubquery;
  3224         -  pItem->pOn = pOn;
  3225         -  pItem->pUsing = pUsing;
         3224  +  if( p->nSrc>1 ){
         3225  +    pItem->pOn = pOn;
         3226  +    pItem->pUsing = pUsing;
         3227  +  }else{
         3228  +    sqlite3ExprDelete(db, pOn);
         3229  +    sqlite3IdListDelete(db, pUsing);
         3230  +  }
  3226   3231     return p;
  3227   3232   }
  3228   3233   
  3229   3234   /*
  3230   3235   ** Add an INDEXED BY or NOT INDEXED clause to the most recently added 
  3231   3236   ** element of the source-list passed as the second argument.
  3232   3237   */

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.283 2009/06/19 14:06:03 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.284 2009/07/01 14:56:40 danielk1977 Exp $
    18     18   */
    19     19   
    20     20   // All token codes are small integers with #defines that begin with "TK_"
    21     21   %token_prefix TK_
    22     22   
    23     23   // The type of the data attached to each token is Token.  This is also the
    24     24   // default type for non-terminals.
................................................................................
   500    500   %ifndef SQLITE_OMIT_SUBQUERY
   501    501     seltablist(A) ::= stl_prefix(X) LP select(S) RP
   502    502                       as(Z) on_opt(N) using_opt(U). {
   503    503       A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U);
   504    504     }
   505    505     seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP
   506    506                       as(Z) on_opt(N) using_opt(U). {
   507         -    if( X==0 ){
   508         -      sqlite3ExprDelete(pParse->db, N);
   509         -      sqlite3IdListDelete(pParse->db, U);
          507  +    if( X==0 && Z.n==0 && N==0 && U==0 ){
   510    508         A = F;
   511    509       }else{
   512    510         Select *pSubquery;
   513    511         sqlite3SrcListShiftJoinType(F);
   514    512         pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0);
   515    513         A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U);
   516    514       }

Added test/tkt3935.test.

            1  +# 2009 July 1
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests to verify that ticket #3935 has been fixed.
           14  +#
           15  +# $Id: tkt3935.test,v 1.1 2009/07/01 14:56:41 danielk1977 Exp $
           16  +
           17  +set testdir [file dirname $argv0]
           18  +source $testdir/tester.tcl
           19  +
           20  +do_test tkt3935.1 {
           21  +  execsql {
           22  +    CREATE TABLE t1(a, b);
           23  +    CREATE TABLE t2(c, d);
           24  +  }
           25  +} {}
           26  +
           27  +do_test tkt3935.2 {
           28  +  execsql { SELECT j1.b FROM ( SELECT * FROM t1 INNER JOIN t2 ON a=c ) AS j1 }
           29  +} {}
           30  +do_test tkt3935.3 {
           31  +  execsql { SELECT j1.b FROM (t1 INNER JOIN t2 ON a=c) AS j1 }
           32  +} {}
           33  +
           34  +
           35  +do_test tkt3935.4 {
           36  +  execsql { SELECT a FROM (t1) AS t ON b USING(a) }
           37  +} {}
           38  +do_test tkt3935.5 {
           39  +  execsql { SELECT a FROM (t1) AS t ON b }
           40  +} {}
           41  +do_test tkt3935.6 {
           42  +  execsql { SELECT a FROM (SELECT * FROM t1) AS t ON b USING(a) }
           43  +} {}
           44  +do_test tkt3935.7 {
           45  +  execsql { SELECT a FROM (SELECT * FROM t1) AS t ON b }
           46  +} {}
           47  +do_test tkt3935.8 {
           48  +  execsql { SELECT a FROM t1 AS t ON b }
           49  +} {}
           50  +do_test tkt3935.9 {
           51  +  execsql { SELECT a FROM t1 AS t ON b USING(a) }
           52  +} {}
           53  +
           54  +finish_test