/ Check-in [cc6cd753]
Login

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

Overview
Comment:Fix a problem with ALTER TABLE and vector assignments in UPDATE statements within triggers.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cc6cd7531fee39b4c2a9f522f1089c1d79254a9e25acae59468322031f94c25a
User & Date: dan 2019-01-15 20:51:35
Context
2019-01-16
11:38
Fix a memory leak that could occur in fts3 when handling a corrupt database. check-in: 65cebb06 user: dan tags: trunk
2019-01-15
20:51
Fix a problem with ALTER TABLE and vector assignments in UPDATE statements within triggers. check-in: cc6cd753 user: dan tags: trunk
18:14
Handle SQL NULL values without crashing in the fts5 snippet() and highlight() functions. check-in: a5e9cc79 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/expr.c.

   461    461         pRet->iColumn = iField;
   462    462         pRet->pLeft = pVector;
   463    463       }
   464    464       assert( pRet==0 || pRet->iTable==0 );
   465    465     }else{
   466    466       if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
   467    467       pRet = sqlite3ExprDup(pParse->db, pVector, 0);
          468  +    sqlite3RenameTokenRemap(pParse, pRet, pVector);
   468    469     }
   469    470     return pRet;
   470    471   }
   471    472   
   472    473   /*
   473    474   ** If expression pExpr is of type TK_SELECT, generate code to evaluate
   474    475   ** it. Return the register in which the result is stored (or, if the 
................................................................................
  1664   1665   
  1665   1666       /* Remember the size of the LHS in iTable so that we can check that
  1666   1667       ** the RHS and LHS sizes match during code generation. */
  1667   1668       pFirst->iTable = pColumns->nId;
  1668   1669     }
  1669   1670   
  1670   1671   vector_append_error:
         1672  +  if( IN_RENAME_OBJECT ){
         1673  +    sqlite3RenameExprUnmap(pParse, pExpr);
         1674  +  }
  1671   1675     sqlite3ExprDelete(db, pExpr);
  1672   1676     sqlite3IdListDelete(db, pColumns);
  1673   1677     return pList;
  1674   1678   }
  1675   1679   
  1676   1680   /*
  1677   1681   ** Set the sort order for the last element on the given ExprList.

Changes to test/altertab2.test.

   137    137     set expect [string map {col1 newname} $expect]
   138    138   
   139    139     do_execsql_test 3.$tn.4 {
   140    140       ALTER TABLE log_entry RENAME col1 TO newname;
   141    141       SELECT sql FROM sqlite_master;
   142    142     } $expect
   143    143   }
          144  +
          145  +#-------------------------------------------------------------------------
          146  +reset_db
          147  +do_execsql_test 4.0 {
          148  +  CREATE TABLE t1(a,b,c,d,e,f);
          149  +  CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
          150  +    UPDATE t1 SET (c,d)=(a,b);
          151  +  END;
          152  +}
          153  +
          154  +do_execsql_test 4.1 {
          155  +  ALTER TABLE t1 RENAME TO t1x;
          156  +  SELECT sql FROM sqlite_master WHERE type = 'trigger';
          157  +} {
          158  +{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN
          159  +    UPDATE "t1x" SET (c,d)=(a,b);
          160  +  END}
          161  +}
          162  +
          163  +do_execsql_test 4.2 {
          164  +  ALTER TABLE t1x RENAME a TO aaa;
          165  +  SELECT sql FROM sqlite_master WHERE type = 'trigger';
          166  +} {
          167  +{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.aaa NOT NULL BEGIN
          168  +    UPDATE "t1x" SET (c,d)=(aaa,b);
          169  +  END}
          170  +}
          171  +
          172  +do_execsql_test 4.3 {
          173  +  ALTER TABLE t1x RENAME d TO ddd;
          174  +  SELECT sql FROM sqlite_master WHERE type = 'trigger';
          175  +} {
          176  +{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.aaa NOT NULL BEGIN
          177  +    UPDATE "t1x" SET (c,ddd)=(aaa,b);
          178  +  END}
          179  +}
   144    180   
   145    181   finish_test