/ Check-in [7b72b2360a]
Login

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

Overview
Comment:Allow an ALTER TABLE RENAME COLUMN to proceed even if the schema contains a virtual table for which the module is unavailable.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | edit-trigger-wrapper
Files: files | file ages | folders
SHA3-256: 7b72b2360a70eb1f788b3c4d745967dfedb2c80af6b2e146ba940a3741fd51a1
User & Date: dan 2018-08-17 18:08:28
Context
2018-08-18
17:35
Improvements to error handling in ALTER TABLE RENAME COLUMN. Closed-Leaf check-in: 7fa1faeaff user: dan tags: edit-trigger-wrapper
2018-08-17
18:08
Allow an ALTER TABLE RENAME COLUMN to proceed even if the schema contains a virtual table for which the module is unavailable. check-in: 7b72b2360a user: dan tags: edit-trigger-wrapper
17:18
Ensure that CREATE VIEW, TRIGGER or INDEX statements can be edited by ALTER TABLE RENAME COLUMN even if they use collation-sequences or user-defined-functions that are not available. check-in: 540014efd6 user: dan tags: edit-trigger-wrapper
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   841    841     zNew = sqlite3NameFromToken(db, pNew);
   842    842     if( !zNew ) goto exit_rename_column;
   843    843     assert( pNew->n>0 );
   844    844     bQuote = sqlite3Isquote(pNew->z[0]);
   845    845     sqlite3NestedParse(pParse, 
   846    846         "UPDATE \"%w\".%s SET "
   847    847         "sql = sqlite_rename_column(sql, %Q, %Q, %d, %Q, %d) "
   848         -      "WHERE name NOT LIKE 'sqlite_%%' AND (type != 'index' OR tbl_name = %Q)",
          848  +      "WHERE name NOT LIKE 'sqlite_%%' AND (type != 'index' OR tbl_name = %Q)"
          849  +      " AND sql NOT LIKE 'create virtual%%'",
   849    850         zDb, MASTER_NAME, 
   850    851         zDb, pTab->zName, iCol, zNew, bQuote,
   851    852         pTab->zName
   852    853     );
   853    854   
   854    855     /* Drop and reload the database schema. */
   855    856     if( pParse->pVdbe ){

Changes to test/altercol.test.

   330    330     SELECT sql FROM sqlite_master WHERE name = 'zzz'
   331    331   } {{CREATE VIEW zzz AS SELECT george, ringo FROM b1}}
   332    332   
   333    333   #-------------------------------------------------------------------------
   334    334   # More triggers.
   335    335   #
   336    336   proc do_rename_column_test {tn old new lSchema} {
   337         -  reset_db
   338         -  set lSorted [list]
   339         -  foreach sql $lSchema { 
   340         -    execsql $sql 
   341         -    lappend lSorted [string trim $sql]
   342         -  }
   343         -  set lSorted [lsort $lSorted]
   344    337   
   345         -  do_execsql_test $tn.1 {
   346         -    SELECT sql FROM sqlite_master WHERE sql!='' ORDER BY 1
   347         -  } $lSorted
          338  +  for {set i 0} {$i < 2} {incr i} {
          339  +    # DROP all tables and views in database.
          340  +    set sql "SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1"
          341  +    foreach nm [db eval $sql] { db eval "DROP TABLE $nm" }
          342  +    set sql "SELECT name FROM sqlite_master WHERE type='view' ORDER BY 1"
          343  +    foreach nm [db eval $sql] { db eval "DROP VIEW $nm" }
          344  +
          345  +    set lSorted [list]
          346  +    foreach sql $lSchema { 
          347  +      execsql $sql 
          348  +      lappend lSorted [string trim $sql]
          349  +    }
          350  +    set lSorted [lsort $lSorted]
          351  +
          352  +    do_execsql_test $tn.$i.1 {
          353  +      SELECT sql FROM sqlite_master WHERE sql!='' ORDER BY 1
          354  +    } $lSorted
          355  +
          356  +    if {0 && $i==1} {
          357  +      db close
          358  +      sqlite3 db test.db
          359  +    }
          360  +
          361  +    do_execsql_test $tn.$i.2 "ALTER TABLE t1 RENAME $old TO $new"
   348    362   
   349         -  do_execsql_test $tn.2 "ALTER TABLE t1 RENAME $old TO $new"
   350         -
   351         -  do_execsql_test $tn.3 {
   352         -    SELECT sql FROM sqlite_master ORDER BY 1
   353         -  } [string map [list $old $new] $lSorted]
          363  +    do_execsql_test $tn.$i.3 {
          364  +      SELECT sql FROM sqlite_master ORDER BY 1
          365  +    } [string map [list $old $new] $lSorted]
          366  +  }
   354    367   }
   355    368   
   356    369   foreach {tn old new lSchema} {
   357    370     1 _x_ _xxx_ {
   358    371       { CREATE TABLE t1(a, b, _x_) }
   359    372       { CREATE TRIGGER AFTER INSERT ON t1 BEGIN
   360    373           SELECT _x_ FROM t1;
................................................................................
   393    406   # sequences or user defined functions.
   394    407   #
   395    408   reset_db
   396    409   
   397    410   foreach {tn old new lSchema} {
   398    411     1 _x_ _xxx_ {
   399    412       { CREATE TABLE t1(a, b, _x_) }
   400         -    { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE _x_='abc' COLLATE xyz }
          413  +    { CREATE VIEW s1 AS SELECT a, b, _x_ FROM t1 WHERE _x_='abc' COLLATE xyz }
   401    414     }
   402    415   
   403    416     2 _x_ _xxx_ {
   404    417       { CREATE TABLE t1(a, b, _x_) }
   405    418       { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE scalar(_x_) }
   406    419     }
   407    420   
   408    421     3 _x_ _xxx_ {
   409    422       { CREATE TABLE t1(a, b, _x_) }
   410    423       { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE _x_ = unicode(1, 2, 3) }
   411    424     }
          425  +
          426  +  4 _x_ _xxx_ {
          427  +    { CREATE TABLE t1(a, b, _x_) }
          428  +    { CREATE VIRTUAL TABLE e1 USING echo(t1) }
          429  +  }
   412    430   } {
          431  +  register_echo_module db
   413    432     do_rename_column_test 10.$tn $old $new $lSchema
   414    433   }
   415    434   
   416    435   
   417    436   finish_test