/ Check-in [f2a9ee72]
Login

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

Overview
Comment:Remove an ALWAYS macro around an expression that is sometimes false.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f2a9ee722c568e73f2a08fb6a2886719850f2923
User & Date: dan 2009-09-10 10:15:59
Context
2009-09-10
16:14
Fix a problem with the sqlite3VdbeMayAbort() assert failing following an OOM. check-in: b3027863 user: dan tags: trunk
10:15
Remove an ALWAYS macro around an expression that is sometimes false. check-in: f2a9ee72 user: dan tags: trunk
02:54
Reduce default SQLITE_MAX_TRIGGER_DEPTH when SQLITE_SMALL_STACK is defined. check-in: 913fb70e user: shane tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

   880    880         ** database table or a subquery.
   881    881         */
   882    882         Table *pTab = 0;            /* Table structure column is extracted from */
   883    883         Select *pS = 0;             /* Select the column is extracted from */
   884    884         int iCol = pExpr->iColumn;  /* Index of column in pTab */
   885    885         testcase( pExpr->op==TK_AGG_COLUMN );
   886    886         testcase( pExpr->op==TK_COLUMN );
   887         -      while( ALWAYS(pNC) && !pTab ){
          887  +      while( pNC && !pTab ){
   888    888           SrcList *pTabList = pNC->pSrcList;
   889    889           for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
   890    890           if( j<pTabList->nSrc ){
   891    891             pTab = pTabList->a[j].pTab;
   892    892             pS = pTabList->a[j].pSelect;
   893    893           }else{
   894    894             pNC = pNC->pNext;
   895    895           }
   896    896         }
   897    897   
   898         -      if( NEVER(pTab==0) ){
          898  +      if( pTab==0 ){
   899    899           /* At one time, code such as "SELECT new.x" within a trigger would
   900    900           ** cause this condition to run.  Since then, we have restructured how
   901    901           ** trigger code is generated and so this condition is no longer 
   902         -        ** possible.  But it seems prudent to keep the test in place in
   903         -        ** case something else changes.
   904         -        */
   905         -        zType = "TEXT";
          902  +        ** possible. However, it can still be true for statements like
          903  +        ** the following:
          904  +        **
          905  +        **   CREATE TABLE t1(col INTEGER);
          906  +        **   SELECT (SELECT t1.col) FROM FROM t1;
          907  +        **
          908  +        ** when columnType() is called on the expression "t1.col" in the 
          909  +        ** sub-select. In this case, set the column type to NULL, even
          910  +        ** though it should really be "INTEGER".
          911  +        **
          912  +        ** This is not a problem, as the column type of "t1.col" is never
          913  +        ** used. When columnType() is called on the expression 
          914  +        ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
          915  +        ** branch below.  */
   906    916           break;
   907    917         }
   908    918   
   909         -      assert( pTab );
          919  +      assert( pTab && pExpr->pTab==pTab );
   910    920         if( pS ){
   911    921           /* The "table" is actually a sub-select or a view in the FROM clause
   912    922           ** of the SELECT statement. Return the declaration type and origin
   913    923           ** data for the result-set column of the sub-select.
   914    924           */
   915    925           if( ALWAYS(iCol>=0 && iCol<pS->pEList->nExpr) ){
   916    926             /* If iCol is less than zero, then the expression requests the
   917    927             ** rowid of the sub-select or view. This expression is legal (see 
   918    928             ** test case misc2.2.2) - it always evaluates to NULL.
   919    929             */
   920    930             NameContext sNC;
   921    931             Expr *p = pS->pEList->a[iCol].pExpr;
   922    932             sNC.pSrcList = pS->pSrc;
   923         -          sNC.pNext = 0;
          933  +          sNC.pNext = pNC;
   924    934             sNC.pParse = pNC->pParse;
   925    935             zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); 
   926    936           }
   927    937         }else if( ALWAYS(pTab->pSchema) ){
   928    938           /* A real table */
   929    939           assert( !pS );
   930    940           if( iCol<0 ) iCol = pTab->iPKey;

Changes to test/capi3c.test.

  1316   1316     } {one}
  1317   1317     do_test capi3c-23.6 {
  1318   1318       sqlite3_column_text16 $STMT 2
  1319   1319       sqlite3_column_text $STMT 3
  1320   1320     } {one}
  1321   1321     sqlite3_finalize $STMT
  1322   1322   }
         1323  +
         1324  +# Test decltype on some SELECT statements that contain sub-selects.
         1325  +#
         1326  +proc decltype {zSql} {
         1327  +  set ret [list]
         1328  +  set STMT [sqlite3_prepare_v2 db $zSql -1 TAIL]
         1329  +  for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} {
         1330  +    lappend ret [sqlite3_column_decltype $STMT $i]
         1331  +  }
         1332  +  sqlite3_finalize $STMT
         1333  +  return $ret
         1334  +}
         1335  +do_test capi3c-24.1 {
         1336  +  execsql { CREATE TABLE t5(a INTEGER, b STRING, c DATETIME) }
         1337  +  decltype {SELECT * FROM t5}
         1338  +} {INTEGER STRING DATETIME}
         1339  +do_test capi3c-24.2 {
         1340  +  decltype {SELECT (SELECT c) FROM t5}
         1341  +} {DATETIME}
         1342  +do_test capi3c-24.3 {
         1343  +  decltype {SELECT (SELECT * FROM (SELECT c)) FROM t5}
         1344  +} {DATETIME}
         1345  +do_test capi3c-24.4 {
         1346  +  decltype {SELECT * FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b}
         1347  +} {INTEGER STRING DATETIME}
         1348  +do_test capi3c-24.5 {
         1349  +  decltype {
         1350  +    SELECT (SELECT x FROM (SELECT c AS x)) 
         1351  +    FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b
         1352  +  }
         1353  +} {DATETIME}
         1354  +do_test capi3c-24.3 {
         1355  +  decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5}
         1356  +} {INTEGER}
  1323   1357   
  1324   1358   finish_test