/ Check-in [d45bee36]
Login

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

Overview
Comment:Avoid a dangling pointer comparison when renaming a table that has a trigger that itself contains a window function with an (illegal) column reference in a FOLLOWING expression.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d45bee36f2c1091a2d32c16ca8921bf4e7c9e40c46d0a36fbcb179ecfafcfbf0
User & Date: dan 2019-01-16 12:05:22
Context
2019-01-16
14:58
Fix a problem with renaming a column that is used as part of an ORDER BY on a compound SELECT within a database view or trigger. check-in: b4b57413 user: dan tags: trunk
12:05
Avoid a dangling pointer comparison when renaming a table that has a trigger that itself contains a window function with an (illegal) column reference in a FOLLOWING expression. check-in: d45bee36 user: dan tags: trunk
11:38
Fix a memory leak that could occur in fts3 when handling a corrupt database. check-in: 65cebb06 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/window.c.

   877    877   ** value should be a non-negative integer.  If the value is not a
   878    878   ** constant, change it to NULL.  The fact that it is then a non-negative
   879    879   ** integer will be caught later.  But it is important not to leave
   880    880   ** variable values in the expression tree.
   881    881   */
   882    882   static Expr *sqlite3WindowOffsetExpr(Parse *pParse, Expr *pExpr){
   883    883     if( 0==sqlite3ExprIsConstant(pExpr) ){
          884  +    if( IN_RENAME_OBJECT ) sqlite3RenameExprUnmap(pParse, pExpr);
   884    885       sqlite3ExprDelete(pParse->db, pExpr);
   885    886       pExpr = sqlite3ExprAlloc(pParse->db, TK_NULL, 0, 0);
   886    887     }
   887    888     return pExpr;
   888    889   }
   889    890   
   890    891   /*

Changes to test/altertab2.test.

   173    173     ALTER TABLE t1x RENAME d TO ddd;
   174    174     SELECT sql FROM sqlite_master WHERE type = 'trigger';
   175    175   } {
   176    176   {CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.aaa NOT NULL BEGIN
   177    177       UPDATE "t1x" SET (c,ddd)=(aaa,b);
   178    178     END}
   179    179   }
          180  +
          181  +#-------------------------------------------------------------------------
          182  +do_execsql_test 5.0 {
          183  +  CREATE TABLE t2(a);
          184  +  CREATE TRIGGER r2 AFTER INSERT ON t2 WHEN new.a NOT NULL BEGIN
          185  +    SELECT a, rank() OVER w1 FROM t2
          186  +      WINDOW w1 AS (
          187  +        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          188  +      ),
          189  +      w2 AS (
          190  +        PARTITION BY b 
          191  +        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          192  +      );
          193  +  END;
          194  +} {}
          195  +
          196  +do_catchsql_test 5.0.1 {
          197  +  INSERT INTO t2 VALUES(1);
          198  +} {1 {no such column: b}}
          199  +
          200  +do_execsql_test 5.1 {
          201  +  ALTER TABLE t2 RENAME TO t2x;
          202  +  SELECT sql FROM sqlite_master WHERE name = 'r2';
          203  +} {
          204  +  {CREATE TRIGGER r2 AFTER INSERT ON "t2x" WHEN new.a NOT NULL BEGIN
          205  +    SELECT a, rank() OVER w1 FROM "t2x"
          206  +      WINDOW w1 AS (
          207  +        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          208  +      ),
          209  +      w2 AS (
          210  +        PARTITION BY b 
          211  +        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          212  +      );
          213  +  END}
          214  +}
          215  +
          216  +do_execsql_test 5.2 {
          217  +  ALTER TABLE t2x RENAME a TO aaaa;
          218  +  SELECT sql FROM sqlite_master WHERE name = 'r2';
          219  +} {
          220  +  {CREATE TRIGGER r2 AFTER INSERT ON "t2x" WHEN new.aaaa NOT NULL BEGIN
          221  +    SELECT aaaa, rank() OVER w1 FROM "t2x"
          222  +      WINDOW w1 AS (
          223  +        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          224  +      ),
          225  +      w2 AS (
          226  +        PARTITION BY b 
          227  +        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          228  +      );
          229  +  END}
          230  +}
          231  +
          232  +do_catchsql_test 5.3 {
          233  +  INSERT INTO t2x VALUES(1);
          234  +} {1 {no such column: b}}
   180    235   
   181    236   finish_test