/ Check-in [414f3408]
Login

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 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
....
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404
....
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
**    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.507 2009/04/02 16:59:47 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
static CollSeq *multiSelectCollSeq(Parse *pParse, Select *p, int iCol){
  CollSeq *pRet;
  if( p->pPrior ){
    pRet = multiSelectCollSeq(pParse, p->pPrior, iCol);
  }else{
    pRet = 0;
  }

  if( pRet==0 ){
    pRet = sqlite3ExprCollSeq(pParse, p->pEList->a[iCol].pExpr);
  }
  return pRet;
}
#endif /* SQLITE_OMIT_COMPOUND_SELECT */

/* Forward reference */
................................................................................
        pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew, 0);
        pOrderBy->a[nOrderBy++].iCol = (u16)i;
      }
    }
  }

  /* Compute the comparison permutation and keyinfo that is used with
  ** the permutation in order to comparisons to determine if the next
  ** row of results comes from selectA or selectB.  Also add explicit
  ** collations to the ORDER BY clause terms so that when the subqueries
  ** to the right and the left are evaluated, they use the correct
  ** collation.
  */
  aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
  if( aPermute ){







|







 







>
|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
....
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
**    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.508 2009/04/16 00:24:24 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
static CollSeq *multiSelectCollSeq(Parse *pParse, Select *p, int iCol){
  CollSeq *pRet;
  if( p->pPrior ){
    pRet = multiSelectCollSeq(pParse, p->pPrior, iCol);
  }else{
    pRet = 0;
  }
  assert( iCol>=0 );
  if( pRet==0 && iCol<p->pEList->nExpr ){
    pRet = sqlite3ExprCollSeq(pParse, p->pEList->a[iCol].pExpr);
  }
  return pRet;
}
#endif /* SQLITE_OMIT_COMPOUND_SELECT */

/* Forward reference */
................................................................................
        pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew, 0);
        pOrderBy->a[nOrderBy++].iCol = (u16)i;
      }
    }
  }

  /* Compute the comparison permutation and keyinfo that is used with
  ** the permutation used to determine if the next
  ** row of results comes from selectA or selectB.  Also add explicit
  ** collations to the ORDER BY clause terms so that when the subqueries
  ** to the right and the left are evaluated, they use the correct
  ** collation.
  */
  aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
  if( aPermute ){

Changes to test/select4.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
370
371
372
373
374
375
376





377
378
379
380
381
382
383
...
787
788
789
790
791
792
793







794
795
796
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing UNION, INTERSECT and EXCEPT operators
# in SELECT statements.
#
# $Id: select4.test,v 1.29 2008/08/04 03:51:24 danielk1977 Exp $

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

# Most tests in this file depend on compound-select. But there are a couple
# right at the end that test DISTINCT, so we cannot omit the entire file.
#
................................................................................
    SELECT DISTINCT log, n FROM t1
    UNION ALL
    SELECT n FROM t1 WHERE log=3
    ORDER BY log;
  }} msg]
  lappend v $msg
} {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}





do_test select4-5.4 {
  set v [catch {execsql {
    SELECT log FROM t1 WHERE n=2
    UNION ALL
    SELECT log FROM t1 WHERE n=3
    UNION ALL
    SELECT log FROM t1 WHERE n=4
................................................................................
    UNION ALL
    SELECT x FROM t2
    EXCEPT
    SELECT x FROM t2
  }
} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}








} ;# ifcapable compound

finish_test







|







 







>
>
>
>
>







 







>
>
>
>
>
>
>



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing UNION, INTERSECT and EXCEPT operators
# in SELECT statements.
#
# $Id: select4.test,v 1.30 2009/04/16 00:24:24 drh Exp $

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

# Most tests in this file depend on compound-select. But there are a couple
# right at the end that test DISTINCT, so we cannot omit the entire file.
#
................................................................................
    SELECT DISTINCT log, n FROM t1
    UNION ALL
    SELECT n FROM t1 WHERE log=3
    ORDER BY log;
  }} msg]
  lappend v $msg
} {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}
do_test select4-5.3-3807-1 {
  catchsql {
    SELECT 1 UNION SELECT 2, 3 UNION SELECT 4, 5 ORDER BY 1;
  }
} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}
do_test select4-5.4 {
  set v [catch {execsql {
    SELECT log FROM t1 WHERE n=2
    UNION ALL
    SELECT log FROM t1 WHERE n=3
    UNION ALL
    SELECT log FROM t1 WHERE n=4
................................................................................
    UNION ALL
    SELECT x FROM t2
    EXCEPT
    SELECT x FROM t2
  }
} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}

do_test select4-12.1 {
  sqlite3 db2 :memory:
  catchsql {
    SELECT 1 UNION SELECT 2,3 UNION SELECT 4,5 ORDER BY 1;
  } db2
} {1 {SELECTs to the left and right of UNION do not have the same number of result columns}}

} ;# ifcapable compound

finish_test