/ Check-in [ad072a835f]
Login

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

Overview
Comment:Avoid incorrectly replacing tokens that refer to a column being renamed via an alias. For example, do not overwrite "xyz" when "a" is renamed in "CREATE VIEW v1 AS SELECT a AS xyz FROM tbl WHERE xyz=1"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-column
Files: files | file ages | folders
SHA3-256: ad072a835f97ff418f5919d94f547ce8afb4fc7c7b590deba41f1e62136a79ac
User & Date: dan 2018-08-24 16:04:26
Context
2018-08-24
17:55
After modifying and reparsing the schema as part of an ALTER TABLE RENAME COLUMN, check that no new schema errors have been introduced (e.g. ambiguous column names in views) before committing the operation. check-in: a0e06d2c5e user: dan tags: alter-table-rename-column
16:04
Avoid incorrectly replacing tokens that refer to a column being renamed via an alias. For example, do not overwrite "xyz" when "a" is renamed in "CREATE VIEW v1 AS SELECT a AS xyz FROM tbl WHERE xyz=1" check-in: ad072a835f user: dan tags: alter-table-rename-column
2018-08-23
20:09
Add the "atrc" test program to the Makefiles. Fix a typo in the instructions in the header comment of the atrc program. check-in: 2130a407dd user: drh tags: alter-table-rename-column
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   962    962     RenameToken *p;
   963    963     for(p=pParse->pRename; ALWAYS(p); p=p->pNext){
   964    964       if( p->p==pFrom ){
   965    965         p->p = pTo;
   966    966         break;
   967    967       }
   968    968     }
   969         -  assert( p );
          969  +  assert( pTo==0 || p );
   970    970   }
   971    971   
   972    972   /*
   973    973   ** Free the list of RenameToken objects given in the second argument
   974    974   */
   975    975   static void renameTokenFree(sqlite3 *db, RenameToken *pToken){
   976    976     RenameToken *pNext;
................................................................................
   985    985   ** Search the Parse object passed as the first argument for a RenameToken
   986    986   ** object associated with parse tree element pPtr. If found, remove it
   987    987   ** from the Parse object and add it to the list maintained by the
   988    988   ** RenameCtx object passed as the second argument.
   989    989   */
   990    990   static void renameTokenFind(Parse *pParse, struct RenameCtx *pCtx, void *pPtr){
   991    991     RenameToken **pp;
          992  +  assert( pPtr!=0 );
   992    993     for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
   993    994       if( (*pp)->p==pPtr ){
   994    995         RenameToken *pToken = *pp;
   995    996         *pp = pToken->pNext;
   996    997         pToken->pNext = pCtx->pList;
   997    998         pCtx->pList = pToken;
   998    999         pCtx->nList++;

Changes to src/resolve.c.

   432    432               sqlite3ErrorMsg(pParse, "row value misused");
   433    433               return WRC_Abort;
   434    434             }
   435    435             resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
   436    436             cnt = 1;
   437    437             pMatch = 0;
   438    438             assert( zTab==0 && zDb==0 );
          439  +          if( IN_RENAME_COLUMN ){
          440  +            sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
          441  +          }
   439    442             goto lookupname_end;
   440    443           }
   441    444         } 
   442    445       }
   443    446   
   444    447       /* Advance to the next name context.  The loop will exit when either
   445    448       ** we have a match (cnt>0) or when we run out of name contexts.

Changes to test/altercol.test.

   629    629   
   630    630   do_execsql_test 14.2 {
   631    631     SELECT 
   632    632     sqlite_rename_column(sql, type, object, db, tbl, icol, znew, bquote)
   633    633     FROM ddd;
   634    634   } {{} {} {}}
   635    635   
          636  +#-------------------------------------------------------------------------
          637  +#
          638  +reset_db
          639  +do_execsql_test 15.0 {
          640  +  CREATE TABLE xxx(a, b, c);
          641  +  SELECT a AS d FROM xxx WHERE d=0;
          642  +}
          643  +
          644  +do_execsql_test 15.1 {
          645  +  CREATE VIEW vvv AS SELECT a AS d FROM xxx WHERE d=0;
          646  +  ALTER TABLE xxx RENAME a TO xyz;
          647  +}
          648  +
          649  +do_execsql_test 15.2 {
          650  +  SELECT sql FROM sqlite_master WHERE type='view';
          651  +} {{CREATE VIEW vvv AS SELECT xyz AS d FROM xxx WHERE d=0}}
   636    652   
   637    653   finish_test