/ Check-in [f2c8179f]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Have the ALTER TABLE code handle the case where an entire expression that includes a sub-select is excluded from a view, trigger or index.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f2c8179f3c0b77f10da3f9b0771db4dec30d0bbf0b7f4751ce439bfb08da8f6f
User & Date: dan 2019-06-11 12:03:10
Context
2019-06-11
16:06
Off-by-one error in the CAST to NUMERIC logic. check-in: 25b89630 user: drh tags: trunk
12:03
Have the ALTER TABLE code handle the case where an entire expression that includes a sub-select is excluded from a view, trigger or index. check-in: f2c8179f user: dan tags: trunk
10:43
Add the new sqlite3ExprUnmapAndDelete() function and use it in place of separate calls to sqlite3RenameExprUnmap() and sqlite3ExprDelete(). check-in: 36ea13e0 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/alter.c.

722
723
724
725
726
727
728














729
730
731
732
733
734
735
736
737

738
739
740
741
742
743
744
** Walker callback used by sqlite3RenameExprUnmap().
*/
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
  Parse *pParse = pWalker->pParse;
  sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
  return WRC_Continue;
}















/*
** Remove all nodes that are part of expression pExpr from the rename list.
*/
void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
  Walker sWalker;
  memset(&sWalker, 0, sizeof(Walker));
  sWalker.pParse = pParse;
  sWalker.xExprCallback = renameUnmapExprCb;

  sqlite3WalkExpr(&sWalker, pExpr);
}

/*
** Remove all nodes that are part of expression-list pEList from the 
** rename list.
*/







>
>
>
>
>
>
>
>
>
>
>
>
>
>









>







722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
** Walker callback used by sqlite3RenameExprUnmap().
*/
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
  Parse *pParse = pWalker->pParse;
  sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
  return WRC_Continue;
}

/*
** Walker callback used by sqlite3RenameExprUnmap().
*/
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
  if( p->pSrc ){
    Parse *pParse = pWalker->pParse;
    int i;
    for(i=0; i<p->pSrc->nSrc; i++){
      sqlite3RenameTokenRemap(pParse, 0, (void*)p->pSrc->a[0].zName);
    }
  }
  return WRC_Continue;
}

/*
** Remove all nodes that are part of expression pExpr from the rename list.
*/
void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
  Walker sWalker;
  memset(&sWalker, 0, sizeof(Walker));
  sWalker.pParse = pParse;
  sWalker.xExprCallback = renameUnmapExprCb;
  sWalker.xSelectCallback = renameUnmapSelectCb;
  sqlite3WalkExpr(&sWalker, pExpr);
}

/*
** Remove all nodes that are part of expression-list pEList from the 
** rename list.
*/

Changes to test/altertab3.test.

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
202
203
204
205
206
207
208












209
210
211
212
213
do_execsql_test 8.1 {
  ALTER TABLE t0 RENAME TO t1;
  SELECT sql FROM sqlite_master;
} {
  {CREATE TABLE "t1"(c0)}
  {CREATE INDEX i0 ON "t1"('1' IN ())}
}

do_execsql_test 8.2.1 {
  CREATE TABLE t2 (c0);
  CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()));
  ALTER TABLE t2 RENAME COLUMN c0 TO c1;
}
do_execsql_test 8.2.2 {
  SELECT sql FROM sqlite_master WHERE tbl_name = 't2';
................................................................................
}
do_test 8.2.3 {
  sqlite3 db2 test.db
  db2 eval { INSERT INTO t2 VALUES (1), (2), (3) }
  db close
} {}















finish_test









<







 







>
>
>
>
>
>
>
>
>
>
>
>





184
185
186
187
188
189
190

191
192
193
194
195
196
197
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
do_execsql_test 8.1 {
  ALTER TABLE t0 RENAME TO t1;
  SELECT sql FROM sqlite_master;
} {
  {CREATE TABLE "t1"(c0)}
  {CREATE INDEX i0 ON "t1"('1' IN ())}
}

do_execsql_test 8.2.1 {
  CREATE TABLE t2 (c0);
  CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()));
  ALTER TABLE t2 RENAME COLUMN c0 TO c1;
}
do_execsql_test 8.2.2 {
  SELECT sql FROM sqlite_master WHERE tbl_name = 't2';
................................................................................
}
do_test 8.2.3 {
  sqlite3 db2 test.db
  db2 eval { INSERT INTO t2 VALUES (1), (2), (3) }
  db close
} {}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 9.1 {
  CREATE TABLE t1(a,b,c);
  CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
    SELECT true WHERE (SELECT a, b FROM (t1)) IN ();
  END;
}

do_execsql_test 9.2 {
  ALTER TABLE t1 RENAME TO t1x;
}


finish_test