/ Check-in [6595c8811f]
Login

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

Overview
Comment:Fix a bug causing ALTER TABLE RENAME COLUMN to fail when renaming an IPK column that is used in a CHECK constraint.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-column
Files: files | file ages | folders
SHA3-256: 6595c8811f13719d0aed8041abc7e1cade41c57427bcbf3503e2e42408eaa03b
User & Date: dan 2018-08-11 17:49:23
Context
2018-08-11
18:34
Avoid an assert() sometimes triggered by ALTER TABLE RENAME COLUMN in non-debug builds. check-in: 520c1c75da user: dan tags: alter-table-rename-column
17:49
Fix a bug causing ALTER TABLE RENAME COLUMN to fail when renaming an IPK column that is used in a CHECK constraint. check-in: 6595c8811f user: dan tags: alter-table-rename-column
17:34
Fix a bug causing all ALTER TABLE RENAME COLUMN commands to fail if ANALYZE had been run on the database. Also prevent the user from renaming the columns of system tables. check-in: ca644a2877 user: dan tags: alter-table-rename-column
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

  1019   1019       int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName);
  1020   1020       FKey *pFKey;
  1021   1021       if( bFKOnly==0 ){
  1022   1022         sCtx.pList = renameTokenFind(
  1023   1023             &sParse, (void*)sParse.pNewTable->aCol[sCtx.iCol].zName
  1024   1024         );
  1025   1025         sCtx.nList = 1;
         1026  +      assert( sCtx.iCol>=0 );
         1027  +      if( sParse.pNewTable->iPKey==sCtx.iCol ){
         1028  +        sCtx.iCol = -1;
         1029  +      }
  1026   1030         sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck);
  1027   1031         for(pIdx=sParse.pNewTable->pIndex; pIdx; pIdx=pIdx->pNext){
  1028   1032           sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
  1029   1033         }
  1030   1034       }
  1031   1035   
  1032   1036       for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){

Changes to test/altercol.test.

   178    178     ALTER TABLE t5 RENAME b TO big;
   179    179     SELECT big FROM t5;
   180    180   } {2 5}
   181    181   
   182    182   do_catchsql_test 6.1 {
   183    183     ALTER TABLE sqlite_stat1 RENAME tbl TO thetable;
   184    184   } {1 {table sqlite_stat1 may not be altered}}
          185  +
          186  +#-------------------------------------------------------------------------
          187  +do_execsql_test 6.0 {
          188  +  CREATE TABLE blob(
          189  +    rid INTEGER PRIMARY KEY,
          190  +    rcvid INTEGER,
          191  +    size INTEGER,
          192  +    uuid TEXT UNIQUE NOT NULL,
          193  +    content BLOB,
          194  +    CHECK( length(uuid)>=40 AND rid>0 )
          195  +  );
          196  +}
          197  +
          198  +breakpoint
          199  +do_execsql_test 6.1 {
          200  +  ALTER TABLE "blob" RENAME COLUMN "rid" TO "a1";
          201  +}
   185    202   
   186    203   finish_test
   187    204