/ Check-in [3cd2b772]
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. Cherrypick of [718d5d0eab04].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-3.8.6
Files: files | file ages | folders
SHA1: 3cd2b7722186ad2b2a581b7f7e7782c59536e523
User & Date: dan 2015-05-20 20:27:00
Context
2015-05-20
20:30
Ensure that tables names are dequoted exactly once by the trigger and FK logic. Cherrypick of [59e92bd9521f] and [9d887b92f808]. check-in: bd357739 user: dan tags: branch-3.8.6
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: 3cd2b772 user: dan tags: branch-3.8.6
20:24
Fix a potential NULL pointer deference on a corrupt database schema. Cherrypick of [dc61b292d8ea]. check-in: 7f3943fb user: dan tags: branch-3.8.6
2015-04-21
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: 718d5d0e user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

  2524   2524       ** starting at pDest->iSdst.  Then the co-routine yields.
  2525   2525       */
  2526   2526       case SRT_Coroutine: {
  2527   2527         if( pDest->iSdst==0 ){
  2528   2528           pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
  2529   2529           pDest->nSdst = pIn->nSdst;
  2530   2530         }
  2531         -      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst);
         2531  +      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
  2532   2532         sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
  2533   2533         break;
  2534   2534       }
  2535   2535   
  2536   2536       /* If none of the above, then the result destination must be
  2537   2537       ** SRT_Output.  This routine is never called with any other
  2538   2538       ** destination other than the ones handled above or SRT_Output.

Changes to test/insert2.test.

    12     12   # focus of this file is testing the INSERT statement that takes is
    13     13   # result from a SELECT.
    14     14   #
    15     15   # $Id: insert2.test,v 1.19 2008/01/16 18:20:42 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
           19  +set testprefix insert2
    19     20   
    20     21   # Create some tables with data that we can select against
    21     22   #
    22     23   do_test insert2-1.0 {
    23     24     execsql {CREATE TABLE d1(n int, log int);}
    24     25     for {set i 1} {$i<=20} {incr i} {
    25     26       for {set j 0} {(1<<$j)<$i} {incr j} {}
................................................................................
   270    271     do_test insert2-5.2 {
   271    272       execsql {
   272    273         INSERT INTO t2 SELECT (SELECT a FROM t2), 4;
   273    274         SELECT * FROM t2;
   274    275       }
   275    276     } {1 2 1 3 1 4}
   276    277   }
          278  +
          279  +do_execsql_test 6.0 { 
          280  +  CREATE TABLE t5(a, b, c DEFAULT 'c', d);
          281  +}
          282  +do_execsql_test 6.1 {
          283  +  INSERT INTO t5(a) SELECT 456 UNION ALL SELECT 123 ORDER BY 1;
          284  +  SELECT * FROM t5 ORDER BY rowid;
          285  +} {123 {} c {}   456 {} c {}}
          286  +
          287  +ifcapable fts3 {
          288  +  do_execsql_test 6.2 {
          289  +    CREATE VIRTUAL TABLE t0 USING fts4(a);
          290  +  }
          291  +  do_execsql_test 6.3 {
          292  +    INSERT INTO t0 SELECT 0 UNION SELECT 0 AS 'x' ORDER BY x;
          293  +    SELECT * FROM t0;
          294  +  } {0}
          295  +}
          296  +
   277    297   
   278    298   finish_test