/ Check-in [5dec3a39]
Login

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

Overview
Comment:Fix for ticket #1582 (Double delete of invalid LIMIT clause Expr* applied to a UNION ALL query). (CVS 2861)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5dec3a392ba3c249bbca899c12e99c26cc1b8cdb
User & Date: danielk1977 2006-01-05 14:22:34
Context
2006-01-05
15:50
Move TCL interface for sqlite3_release_memory() and sqlite3_soft_heap_limit() out of tclsqlite.c and into test1.c. Update the TCL interface documention to describe the "exists" method. (CVS 2862) check-in: 98194a45 user: drh tags: trunk
14:22
Fix for ticket #1582 (Double delete of invalid LIMIT clause Expr* applied to a UNION ALL query). (CVS 2861) check-in: 5dec3a39 user: danielk1977 tags: trunk
13:48
Disable automatic invocation of sqlite3_release_memory() when a malloc() fails in those cases where the global mutex is held. (CVS 2860) check-in: 6fdbb8b7 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.284 2006/01/05 11:34:34 danielk1977 Exp $
           15  +** $Id: select.c,v 1.285 2006/01/05 14:22:34 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
  1544   1544       case TK_ALL: {
  1545   1545         if( pOrderBy==0 ){
  1546   1546           int addr = 0;
  1547   1547           assert( !pPrior->pLimit );
  1548   1548           pPrior->pLimit = p->pLimit;
  1549   1549           pPrior->pOffset = p->pOffset;
  1550   1550           rc = sqlite3Select(pParse, pPrior, eDest, iParm, 0, 0, 0, aff);
         1551  +        p->pLimit = 0;
         1552  +        p->pOffset = 0;
  1551   1553           if( rc ){
  1552   1554             goto multi_select_end;
  1553   1555           }
  1554   1556           p->pPrior = 0;
  1555   1557           p->iLimit = pPrior->iLimit;
  1556   1558           p->iOffset = pPrior->iOffset;
  1557         -        p->pLimit = 0;
  1558         -        p->pOffset = 0;
  1559   1559           if( p->iLimit>=0 ){
  1560   1560             addr = sqlite3VdbeAddOp(v, OP_IfMemZero, p->iLimit, 0);
  1561   1561             VdbeComment((v, "# Jump ahead if LIMIT reached"));
  1562   1562           }
  1563   1563           rc = sqlite3Select(pParse, p, eDest, iParm, 0, 0, 0, aff);
  1564   1564           p->pPrior = pPrior;
  1565   1565           if( rc ){

Changes to test/misc5.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc5.test,v 1.7 2005/11/14 22:29:06 drh Exp $
           16  +# $Id: misc5.test,v 1.8 2006/01/05 14:22:34 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Build records using the MakeRecord opcode such that the size of the 
    22     22   # header is at the transition point in the size of a varint.
    23     23   #
................................................................................
   498    498   do_test misc5-5.3 {
   499    499     execsql {SELECT 3.e0 }
   500    500   } 3.0
   501    501   do_test misc5-5.4 {
   502    502     execsql {SELECT .4e+1}
   503    503   } 4.0
   504    504   
          505  +# Ticket #1582.  Ensure that an unknown table in a LIMIT clause applied to
          506  +# a UNION ALL query causes an error, not a crash.
          507  +#
          508  +db close
          509  +file delete -force test.db
          510  +sqlite3 db test.db
          511  +ifcapable subquery {
          512  +  do_test misc5-6.1 {
          513  +    catchsql {
          514  +      SELECT * FROM sqlite_master 
          515  +      UNION ALL 
          516  +      SELECT * FROM sqlite_master
          517  +      LIMIT (SELECT count(*) FROM blah);
          518  +    }
          519  +  } {1 {no such table: blah}}
          520  +  do_test misc5-6.2 {
          521  +    execsql {
          522  +      CREATE TABLE logs(msg TEXT, timestamp INTEGER, dbtime TEXT);
          523  +    }
          524  +    catchsql {
          525  +      SELECT * FROM logs WHERE logs.id >= (SELECT head FROM logs_base) 
          526  +      UNION ALL 
          527  +      SELECT * FROM logs 
          528  +      LIMIT (SELECT lmt FROM logs_base) ;
          529  +    }
          530  +  } {1 {no such column: logs.id}}
          531  +}
   505    532   
   506    533   finish_test