/ Check-in [dd665eac]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Take care to free the memory for the ORDER BY clause on SELECT statements containing errors and contained within triggers. Ticket #3863. (CVS 6644)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dd665eac8c04259e44a95827ebd1f037460fe1b2
User & Date: drh 2009-05-17 15:26:21
Context
2009-05-17
15:29
Remove debugging code accidently left in check-in (6642). Ticket #3862. (CVS 6645) check-in: 0d974613 user: drh tags: trunk
15:26
Take care to free the memory for the ORDER BY clause on SELECT statements containing errors and contained within triggers. Ticket #3863. (CVS 6644) check-in: dd665eac user: drh tags: trunk
12:07
Fix a typo in the sqlite3_blob_open() documentation. (CVS 6643) check-in: 92866482 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
3571
3572
3573
3574
3575
3576
3577

3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.514 2009/05/17 02:06:15 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
    ** results, so remove it if it were specified.
    */
    assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union || 
           pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard);
    p->selFlags &= ~SF_Distinct;
  }
  sqlite3SelectPrep(pParse, p, 0);

  pTabList = p->pSrc;
  pEList = p->pEList;
  if( pParse->nErr || db->mallocFailed ){
    goto select_end;
  }
  p->pOrderBy = pOrderBy;
  isAgg = (p->selFlags & SF_Aggregate)!=0;
  if( pEList==0 ) goto select_end;

  /* 
  ** Do not even attempt to generate any code if we have already seen
  ** errors before this routine starts.
  */







|







 







>





<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583

3584
3585
3586
3587
3588
3589
3590
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.515 2009/05/17 15:26:21 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
    ** results, so remove it if it were specified.
    */
    assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union || 
           pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard);
    p->selFlags &= ~SF_Distinct;
  }
  sqlite3SelectPrep(pParse, p, 0);
  p->pOrderBy = pOrderBy;
  pTabList = p->pSrc;
  pEList = p->pEList;
  if( pParse->nErr || db->mallocFailed ){
    goto select_end;
  }

  isAgg = (p->selFlags & SF_Aggregate)!=0;
  if( pEList==0 ) goto select_end;

  /* 
  ** Do not even attempt to generate any code if we have already seen
  ** errors before this routine starts.
  */

Changes to test/selectC.test.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
144
145
146
147
148
149
150
151















152
#    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. 
#
# $Id: selectC.test,v 1.4 2009/03/02 01:22:40 drh Exp $

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

# Ticket #
do_test selectC-1.1 {
  execsql {
................................................................................
do_test selectC-1.14.2 {
  execsql {
    SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
      FROM t1
     ORDER BY x DESC
  }
} {CCC AAA AAA}
















finish_test







|







 








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

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#    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. 
#
# $Id: selectC.test,v 1.5 2009/05/17 15:26:21 drh Exp $

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

# Ticket #
do_test selectC-1.1 {
  execsql {
................................................................................
do_test selectC-1.14.2 {
  execsql {
    SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
      FROM t1
     ORDER BY x DESC
  }
} {CCC AAA AAA}

# The following query used to leak memory.  Verify that has been fixed.
#
do_test selectC-2.1 {
  catchsql {
    CREATE TABLE t21a(a,b);
    INSERT INTO t21a VALUES(1,2);
    CREATE TABLE t21b(n);
    CREATE TRIGGER r21 AFTER INSERT ON t21b BEGIN
      SELECT a FROM t21a WHERE a>new.x UNION ALL
      SELECT b FROM t21a WHERE b>new.x ORDER BY 1 LIMIT 2;
    END;
    INSERT INTO t21b VALUES(6);
  }
} {1 {no such column: new.x}}

finish_test