/ Check-in [3f9f81e9]
Login

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

Overview
Comment:Do not segfault after a parse error in a sub-select in a statement of the form "DELETE WHERE ... IN(sub-select)". Ticket #2991. (CVS 4854)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3f9f81e908aad6cdc0a16ec52f4ec46d89fd78bc
User & Date: danielk1977 2008-03-12 10:39:00
Context
2008-03-13
04:53
Eliminate a race condition from lock4.test. (CVS 4855) check-in: 85585f11 user: danielk1977 tags: trunk
2008-03-12
10:39
Do not segfault after a parse error in a sub-select in a statement of the form "DELETE WHERE ... IN(sub-select)". Ticket #2991. (CVS 4854) check-in: 3f9f81e9 user: danielk1977 tags: trunk
2008-03-11
18:03
If tclsh is not found, don't default to building the amalgamation (CVS 4853) check-in: cbc01675 user: mlcreech tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.353 2008/03/10 14:12:53 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
  ** If this is the case, it may be possible to use an existing table
  ** or index instead of generating an epheremal table.
  */
  if( sqlite3_enable_in_opt
   && (p=pX->pSelect)!=0 && !p->pPrior
   && !p->isDistinct && !p->isAgg && !p->pGroupBy
   && p->pSrc && p->pSrc->nSrc==1 && !p->pSrc->a[0].pSelect
   && !p->pSrc->a[0].pTab->pSelect                                  
   && p->pEList->nExpr==1 && p->pEList->a[0].pExpr->op==TK_COLUMN
   && !p->pLimit && !p->pOffset && !p->pWhere
  ){
    sqlite3 *db = pParse->db;
    Index *pIdx;
    Expr *pExpr = p->pEList->a[0].pExpr;
    int iCol = pExpr->iColumn;







|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.354 2008/03/12 10:39:00 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
  ** If this is the case, it may be possible to use an existing table
  ** or index instead of generating an epheremal table.
  */
  if( sqlite3_enable_in_opt
   && (p=pX->pSelect)!=0 && !p->pPrior
   && !p->isDistinct && !p->isAgg && !p->pGroupBy
   && p->pSrc && p->pSrc->nSrc==1 && !p->pSrc->a[0].pSelect
   && p->pSrc->a[0].pTab && !p->pSrc->a[0].pTab->pSelect
   && p->pEList->nExpr==1 && p->pEList->a[0].pExpr->op==TK_COLUMN
   && !p->pLimit && !p->pOffset && !p->pWhere
  ){
    sqlite3 *db = pParse->db;
    Index *pIdx;
    Expr *pExpr = p->pEList->a[0].pExpr;
    int iCol = pExpr->iColumn;

Changes to test/in3.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
260
261
262
263
264
265
266
267



















268
#
#***********************************************************************
# This file tests the optimisations made in November 2007 of expressions 
# of the following form:
#
#     <value> IN (SELECT <column> FROM <table>)
#
# $Id: in3.test,v 1.3 2008/01/17 16:22:16 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test
  return
................................................................................
do_test in3-4.5 {
  execsql { CREATE UNIQUE INDEX t3_i2 ON t3(b) }
  exec_neph { SELECT b FROM t3 WHERE b IN (SELECT b FROM t3) }
} {0 none numeric real text}
do_test in3-4.6 {
  execsql { DROP INDEX t3_i2 }
} {}




















finish_test







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#
#***********************************************************************
# This file tests the optimisations made in November 2007 of expressions 
# of the following form:
#
#     <value> IN (SELECT <column> FROM <table>)
#
# $Id: in3.test,v 1.4 2008/03/12 10:39:00 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test
  return
................................................................................
do_test in3-4.5 {
  execsql { CREATE UNIQUE INDEX t3_i2 ON t3(b) }
  exec_neph { SELECT b FROM t3 WHERE b IN (SELECT b FROM t3) }
} {0 none numeric real text}
do_test in3-4.6 {
  execsql { DROP INDEX t3_i2 }
} {}

# The following two test cases verify that ticket #2991 has been fixed.
#
do_test in3-5.1 {
  execsql {
    CREATE TABLE Folders(
      folderid INTEGER PRIMARY KEY, 
      parentid INTEGER, 
      rootid INTEGER, 
      path VARCHAR(255)
    );
  }
} {}
do_test in3-5.2 {
  catchsql {
    DELETE FROM Folders WHERE folderid IN
    (SELECT folderid FROM Folder WHERE path LIKE 'C:\MP3\Albums\' || '%');
  }
} {1 {no such table: Folder}}

finish_test