/ Check-in [2ca6b8f8]
Login

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

Overview
Comment:Fix a problem with renaming a table within a schema that contains a composite query that uses a column alias as an ORDER BY term.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2ca6b8f84ec07e313aa4e1c0894827401b418dcc4221e9c54c384f1c3893952a
User & Date: dan 2019-01-23 19:50:46
Context
2019-01-23
20:31
Fix an assert() in vdbemem.c that could fire if the database was corrupt. check-in: a70958cd user: dan tags: trunk
19:50
Fix a problem with renaming a table within a schema that contains a composite query that uses a column alias as an ORDER BY term. check-in: 2ca6b8f8 user: dan tags: trunk
19:25
Stricter enforcement of cell sizes when doing balancing operations on the btree, in order to catch file corruption sooner. check-in: 12713f32 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

  1156   1156             }else{
  1157   1157               pDup = sqlite3ExprDup(db, pE, 0);
  1158   1158             }
  1159   1159             if( !db->mallocFailed ){
  1160   1160               assert(pDup);
  1161   1161               iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
  1162   1162             }
  1163         -          if( IN_RENAME_OBJECT ){
  1164         -            if( iCol>0 ){
  1165         -              pItem->done = 1;
  1166         -              continue;
  1167         -            }
  1168         -          }else{
         1163  +          if( !IN_RENAME_OBJECT ){
  1169   1164               sqlite3ExprDelete(db, pDup);
  1170   1165             }
  1171   1166           }
  1172   1167         }
  1173   1168         if( iCol>0 ){
  1174   1169           /* Convert the ORDER BY term into an integer column number iCol,
  1175   1170           ** taking care to preserve the COLLATE clause if it exists */
  1176         -        Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
  1177         -        if( pNew==0 ) return 1;
  1178         -        pNew->flags |= EP_IntValue;
  1179         -        pNew->u.iValue = iCol;
  1180         -        if( pItem->pExpr==pE ){
  1181         -          pItem->pExpr = pNew;
  1182         -        }else{
  1183         -          Expr *pParent = pItem->pExpr;
  1184         -          assert( pParent->op==TK_COLLATE );
  1185         -          while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
  1186         -          assert( pParent->pLeft==pE );
  1187         -          pParent->pLeft = pNew;
         1171  +        if( !IN_RENAME_OBJECT ){
         1172  +          Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
         1173  +          if( pNew==0 ) return 1;
         1174  +          pNew->flags |= EP_IntValue;
         1175  +          pNew->u.iValue = iCol;
         1176  +          if( pItem->pExpr==pE ){
         1177  +            pItem->pExpr = pNew;
         1178  +          }else{
         1179  +            Expr *pParent = pItem->pExpr;
         1180  +            assert( pParent->op==TK_COLLATE );
         1181  +            while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
         1182  +            assert( pParent->pLeft==pE );
         1183  +            pParent->pLeft = pNew;
         1184  +          }
         1185  +          sqlite3ExprDelete(db, pE);
         1186  +          pItem->u.x.iOrderByCol = (u16)iCol;
  1188   1187           }
  1189         -        sqlite3ExprDelete(db, pE);
  1190         -        pItem->u.x.iOrderByCol = (u16)iCol;
  1191   1188           pItem->done = 1;
  1192   1189         }else{
  1193   1190           moreToDo = 1;
  1194   1191         }
  1195   1192       }
  1196   1193       pSelect = pSelect->pNext;
  1197   1194     }

Changes to test/altertab3.test.

    37     37       SELECT sum(b) OVER w FROM t1 WINDOW w AS (ORDER BY aaa);
    38     38     END}}
    39     39   
    40     40   do_execsql_test 1.3 {
    41     41     INSERT INTO t1 VALUES(1, 2);
    42     42   }
    43     43   
           44  +#-------------------------------------------------------------------------
           45  +reset_db
           46  +do_execsql_test 2.0 {
           47  +  CREATE TABLE t1(a,b,c);
           48  +  CREATE TABLE t2(a,b,c);
           49  +  CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
           50  +    SELECT a,b, a name FROM t1 
           51  +      INTERSECT 
           52  +    SELECT a,b,c FROM t1 WHERE b>='d' ORDER BY name;
           53  +    SELECT new.c;
           54  +  END;
           55  +}
    44     56   
           57  +do_execsql_test 2.1 {
           58  +  ALTER TABLE t1 RENAME TO t1x;
           59  +  SELECT sql FROM sqlite_master WHERE name = 'r1';
           60  +} {{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN
           61  +    SELECT a,b, a name FROM "t1x" 
           62  +      INTERSECT 
           63  +    SELECT a,b,c FROM "t1x" WHERE b>='d' ORDER BY name;
           64  +    SELECT new.c;
           65  +  END}}
    45     66   finish_test
    46     67   
    47     68