/ Check-in [414f3408]
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:In a 3-fold compound SELECT make sure early code generation of the SELECTs to the right do not dereference non-existant columns in SELECTs on the left. (CVS 6511)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 414f340809c487901fa913026a342b19a2956c0a
User & Date: drh 2009-04-16 00:24:24
Context
2009-04-16
12:58
Make sure the 'unixepoch' converter in the date and time functions rounds to the nearest millisecond rather than truncating downward to the next smaller millisecond. Ticket #3808. (CVS 6512) check-in: e6e036b3 user: drh tags: trunk
00:24
In a 3-fold compound SELECT make sure early code generation of the SELECTs to the right do not dereference non-existant columns in SELECTs on the left. (CVS 6511) check-in: 414f3408 user: drh tags: trunk
2009-04-15
15:16
Fix the group_concat() function so that it inserts the separator string even if the initial content strings are empty. Ticket #3806. (CVS 6510) check-in: b83fbf15 user: drh 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.507 2009/04/02 16:59:47 drh Exp $
           15  +** $Id: select.c,v 1.508 2009/04/16 00:24:24 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
  1390   1390   static CollSeq *multiSelectCollSeq(Parse *pParse, Select *p, int iCol){
  1391   1391     CollSeq *pRet;
  1392   1392     if( p->pPrior ){
  1393   1393       pRet = multiSelectCollSeq(pParse, p->pPrior, iCol);
  1394   1394     }else{
  1395   1395       pRet = 0;
  1396   1396     }
  1397         -  if( pRet==0 ){
         1397  +  assert( iCol>=0 );
         1398  +  if( pRet==0 && iCol<p->pEList->nExpr ){
  1398   1399       pRet = sqlite3ExprCollSeq(pParse, p->pEList->a[iCol].pExpr);
  1399   1400     }
  1400   1401     return pRet;
  1401   1402   }
  1402   1403   #endif /* SQLITE_OMIT_COMPOUND_SELECT */
  1403   1404   
  1404   1405   /* Forward reference */
................................................................................
  2097   2098           pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew, 0);
  2098   2099           pOrderBy->a[nOrderBy++].iCol = (u16)i;
  2099   2100         }
  2100   2101       }
  2101   2102     }
  2102   2103   
  2103   2104     /* Compute the comparison permutation and keyinfo that is used with
  2104         -  ** the permutation in order to comparisons to determine if the next
         2105  +  ** the permutation used to determine if the next
  2105   2106     ** row of results comes from selectA or selectB.  Also add explicit
  2106   2107     ** collations to the ORDER BY clause terms so that when the subqueries
  2107   2108     ** to the right and the left are evaluated, they use the correct
  2108   2109     ** collation.
  2109   2110     */
  2110   2111     aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
  2111   2112     if( aPermute ){

Changes to test/select4.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing UNION, INTERSECT and EXCEPT operators
    13     13   # in SELECT statements.
    14     14   #
    15         -# $Id: select4.test,v 1.29 2008/08/04 03:51:24 danielk1977 Exp $
           15  +# $Id: select4.test,v 1.30 2009/04/16 00:24:24 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Most tests in this file depend on compound-select. But there are a couple
    21     21   # right at the end that test DISTINCT, so we cannot omit the entire file.
    22     22   #
................................................................................
   370    370       SELECT DISTINCT log, n FROM t1
   371    371       UNION ALL
   372    372       SELECT n FROM t1 WHERE log=3
   373    373       ORDER BY log;
   374    374     }} msg]
   375    375     lappend v $msg
   376    376   } {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}
          377  +do_test select4-5.3-3807-1 {
          378  +  catchsql {
          379  +    SELECT 1 UNION SELECT 2, 3 UNION SELECT 4, 5 ORDER BY 1;
          380  +  }
          381  +} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}
   377    382   do_test select4-5.4 {
   378    383     set v [catch {execsql {
   379    384       SELECT log FROM t1 WHERE n=2
   380    385       UNION ALL
   381    386       SELECT log FROM t1 WHERE n=3
   382    387       UNION ALL
   383    388       SELECT log FROM t1 WHERE n=4
................................................................................
   787    792       UNION ALL
   788    793       SELECT x FROM t2
   789    794       EXCEPT
   790    795       SELECT x FROM t2
   791    796     }
   792    797   } {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}
   793    798   
          799  +do_test select4-12.1 {
          800  +  sqlite3 db2 :memory:
          801  +  catchsql {
          802  +    SELECT 1 UNION SELECT 2,3 UNION SELECT 4,5 ORDER BY 1;
          803  +  } db2
          804  +} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}
          805  +
   794    806   } ;# ifcapable compound
   795    807   
   796    808   finish_test