SQLite

Check-in [718d5d0eab]
Login

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

Overview
Comment:Fix an obscure problem with "INSERT INTO tbl(cols) SELECT" statements where the SELECT is a compound with an ORDER BY and "cols" is a strict subset of tbl's columns.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 718d5d0eab045a874107e078a857226a80ab912d
User & Date: dan 2015-04-21 15:49:04.252
References
2015-05-20
20:27
Fix an obscure problem with "INSERT INTO tbl(cols) SELECT" statements where the SELECT is a compound with an ORDER BY and "cols" is a strict subset of tbl's columns. Cherrypick of [718d5d0eab04]. (check-in: 3cd2b77221 user: dan tags: branch-3.8.6)
Context
2015-05-20
20:27
Fix an obscure problem with "INSERT INTO tbl(cols) SELECT" statements where the SELECT is a compound with an ORDER BY and "cols" is a strict subset of tbl's columns. Cherrypick of [718d5d0eab04]. (check-in: 3cd2b77221 user: dan tags: branch-3.8.6)
2015-04-21
16:09
Fix a memory leak in the SELECT code generator tracing logic (code that is omitted in non-debugging builds). (check-in: b623ebd859 user: drh tags: trunk)
15:49
Fix an obscure problem with "INSERT INTO tbl(cols) SELECT" statements where the SELECT is a compound with an ORDER BY and "cols" is a strict subset of tbl's columns. (check-in: 718d5d0eab user: dan tags: trunk)
15:16
Change an assert() in the aggregate query code generator into a testcase(). (check-in: d1e6bc918b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/select.c.
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
    ** starting at pDest->iSdst.  Then the co-routine yields.
    */
    case SRT_Coroutine: {
      if( pDest->iSdst==0 ){
        pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
        pDest->nSdst = pIn->nSdst;
      }
      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
      sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      break;
    }

    /* If none of the above, then the result destination must be
    ** SRT_Output.  This routine is never called with any other
    ** destination other than the ones handled above or SRT_Output.







|







2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
    ** starting at pDest->iSdst.  Then the co-routine yields.
    */
    case SRT_Coroutine: {
      if( pDest->iSdst==0 ){
        pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
        pDest->nSdst = pIn->nSdst;
      }
      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
      sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      break;
    }

    /* If none of the above, then the result destination must be
    ** SRT_Output.  This routine is never called with any other
    ** destination other than the ones handled above or SRT_Output.
Changes to test/insert2.test.
12
13
14
15
16
17
18

19
20
21
22
23
24
25
# focus of this file is testing the INSERT statement that takes is
# result from a SELECT.
#
# $Id: insert2.test,v 1.19 2008/01/16 18:20:42 danielk1977 Exp $

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


# Create some tables with data that we can select against
#
do_test insert2-1.0 {
  execsql {CREATE TABLE d1(n int, log int);}
  for {set i 1} {$i<=20} {incr i} {
    for {set j 0} {(1<<$j)<$i} {incr j} {}







>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# focus of this file is testing the INSERT statement that takes is
# result from a SELECT.
#
# $Id: insert2.test,v 1.19 2008/01/16 18:20:42 danielk1977 Exp $

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

# Create some tables with data that we can select against
#
do_test insert2-1.0 {
  execsql {CREATE TABLE d1(n int, log int);}
  for {set i 1} {$i<=20} {incr i} {
    for {set j 0} {(1<<$j)<$i} {incr j} {}
270
271
272
273
274
275
276
277



















278
  do_test insert2-5.2 {
    execsql {
      INSERT INTO t2 SELECT (SELECT a FROM t2), 4;
      SELECT * FROM t2;
    }
  } {1 2 1 3 1 4}
}




















finish_test








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

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  do_test insert2-5.2 {
    execsql {
      INSERT INTO t2 SELECT (SELECT a FROM t2), 4;
      SELECT * FROM t2;
    }
  } {1 2 1 3 1 4}
}

do_execsql_test 6.0 { 
  CREATE TABLE t5(a, b, c DEFAULT 'c', d);
}
do_execsql_test 6.1 {
  INSERT INTO t5(a) SELECT 456 UNION ALL SELECT 123 ORDER BY 1;
  SELECT * FROM t5 ORDER BY rowid;
} {123 {} c {}   456 {} c {}}

ifcapable fts3 {
  do_execsql_test 6.2 {
    CREATE VIRTUAL TABLE t0 USING fts4(a);
  }
  do_execsql_test 6.3 {
    INSERT INTO t0 SELECT 0 UNION SELECT 0 AS 'x' ORDER BY x;
    SELECT * FROM t0;
  } {0}
}


finish_test