/ Check-in [22e785aa2b]
Login

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

Overview
Comment:Merge fixes from the alter-table-rename-column branch that occurred after this branch separated from that one.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-table
Files: files | file ages | folders
SHA3-256: 22e785aa2bbce4ae0852bc3d127d4b12222a192eb6e3ee874bf8e5c8582d05f3
User & Date: drh 2018-09-01 15:55:44
Context
2018-09-01
16:05
Have "ALTER TABLE ADD COLUMN" reload the entire db schema, as "RENAME COLUMN" and "RENAME TABLE" do. Closed-Leaf check-in: 8d89ddc1a6 user: dan tags: alter-table-rename-table
15:55
Merge fixes from the alter-table-rename-column branch that occurred after this branch separated from that one. check-in: 22e785aa2b user: drh tags: alter-table-rename-table
15:49
Merge fixes and enhancements from trunk. check-in: 589186c083 user: drh tags: alter-table-rename-table
2018-08-25
16:22
Fix a minor issue in the altercol.test script so that it runs on Windows. check-in: 62089c6daf user: drh tags: alter-table-rename-column
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   641    641     if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ) goto exit_rename_column;
   642    642     if( SQLITE_OK!=isRealTable(pParse, pTab) ) goto exit_rename_column;
   643    643   
   644    644     /* Which schema holds the table to be altered */  
   645    645     iSchema = sqlite3SchemaToIndex(db, pTab->pSchema);
   646    646     assert( iSchema>=0 );
   647    647     zDb = db->aDb[iSchema].zDbSName;
          648  +
          649  +#ifndef SQLITE_OMIT_AUTHORIZATION
          650  +  /* Invoke the authorization callback. */
          651  +  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
          652  +    goto exit_rename_column;
          653  +  }
          654  +#endif
   648    655   
   649    656     /* Make sure the old name really is a column name in the table to be
   650    657     ** altered.  Set iCol to be the index of the column being renamed */
   651    658     zOld = sqlite3NameFromToken(db, pOld);
   652    659     if( !zOld ) goto exit_rename_column;
   653    660     for(iCol=0; iCol<pTab->nCol; iCol++){
   654    661       if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break;

Changes to test/altercol.test.

   242    242   do_execsql_test 6.3 {
   243    243     SELECT "where" FROM blob;
   244    244   } {}
   245    245   
   246    246   #-------------------------------------------------------------------------
   247    247   # Triggers.
   248    248   #
          249  +db close
          250  +db2 close
   249    251   reset_db
   250    252   do_execsql_test 7.0 {
   251    253     CREATE TABLE c(x);
   252    254     INSERT INTO c VALUES(0);
   253    255     CREATE TABLE t6("col a", "col b", "col c");
   254    256     CREATE TRIGGER zzz AFTER UPDATE OF "col a", "col c" ON t6 BEGIN
   255    257       UPDATE c SET x=x+1;

Changes to test/auth.test.

  2128   2128     } {0 {1 2 3 4 5 6}}
  2129   2129     do_catchsql_test auth-1.314 {
  2130   2130       WITH RECURSIVE
  2131   2131          auth1314(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1314 WHERE x<5)
  2132   2132       SELECT * FROM t1 LEFT JOIN auth1314;
  2133   2133     } {1 {not authorized}}
  2134   2134   } ;# ifcapable cte
         2135  +
         2136  +#
         2137  +# db eval {SELECT sql FROM temp.sqlite_master} {puts "TEMP: $sql;"}
         2138  +# db eval {SELECT sql FROM main.sqlite_master} {puts "MAIN: $sql;"}
         2139  +#
         2140  +#    MAIN: CREATE TABLE "t2"(a,b,c);
         2141  +#    MAIN: CREATE TABLE t4(a,b,c);
         2142  +#    MAIN: CREATE INDEX t4i1 ON t4(a);
         2143  +#    MAIN: CREATE INDEX t4i2 ON t4(b,a,c);
         2144  +#    MAIN: CREATE TABLE sqlite_stat1(tbl,idx,stat);
         2145  +#    MAIN: CREATE TABLE t1(a,b);
         2146  +#
         2147  +ifcapable altertable {
         2148  +  do_test 1.350 {
         2149  +    proc auth {code arg1 arg2 arg3 arg4 args} {
         2150  +      if {$code=="SQLITE_ALTER_TABLE"} {
         2151  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         2152  +        return SQLITE_OK
         2153  +      }
         2154  +      return SQLITE_OK
         2155  +    }
         2156  +    catchsql {
         2157  +      ALTER TABLE t1 RENAME COLUMN b TO bcdefg;
         2158  +    }
         2159  +  } {0 {}}
         2160  +  do_execsql_test auth-1.351 {
         2161  +    SELECT name FROM pragma_table_info('t1') ORDER BY cid;
         2162  +  } {a bcdefg}
         2163  +  do_test auth-1.352 {
         2164  +    set authargs
         2165  +  } {main t1 {} {}}
         2166  +  do_test 1.353 {
         2167  +    proc auth {code arg1 arg2 arg3 arg4 args} {
         2168  +      if {$code=="SQLITE_ALTER_TABLE"} {
         2169  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         2170  +        return SQLITE_IGNORE
         2171  +      }
         2172  +      return SQLITE_OK
         2173  +    }
         2174  +    catchsql {
         2175  +      ALTER TABLE t1 RENAME COLUMN bcdefg TO b;
         2176  +    }
         2177  +  } {0 {}}
         2178  +  do_execsql_test auth-1.354 {
         2179  +    SELECT name FROM pragma_table_info('t1') ORDER BY cid;
         2180  +  } {a bcdefg}
         2181  +  do_test auth-1.355 {
         2182  +    set authargs
         2183  +  } {main t1 {} {}}
         2184  +  do_test 1.356 {
         2185  +    proc auth {code arg1 arg2 arg3 arg4 args} {
         2186  +      if {$code=="SQLITE_ALTER_TABLE"} {
         2187  +        set ::authargs [list $arg1 $arg2 $arg3 $arg4]
         2188  +        return SQLITE_DENY
         2189  +      }
         2190  +      return SQLITE_OK
         2191  +    }
         2192  +    catchsql {
         2193  +      ALTER TABLE t1 RENAME COLUMN bcdefg TO b;
         2194  +    }
         2195  +  } {1 {not authorized}}
         2196  +  do_execsql_test auth-1.356 {
         2197  +    SELECT name FROM pragma_table_info('t1') ORDER BY cid;
         2198  +  } {a bcdefg}
         2199  +  do_test auth-1.357 {
         2200  +    set authargs
         2201  +  } {main t1 {} {}}
         2202  +}
         2203  +
  2135   2204   
  2136   2205   do_test auth-2.1 {
  2137   2206     proc auth {code arg1 arg2 arg3 arg4 args} {
  2138   2207       if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
  2139   2208         return SQLITE_DENY
  2140   2209       }
  2141   2210       return SQLITE_OK