/ Check-in [0b28dd5c]
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:Fix issues with ALTER TABLE RENAME COLUMN associated with OOM errors.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-column
Files: files | file ages | folders
SHA3-256: 0b28dd5c2e4908d5e49eaedd359492e46de8af3bf84120f4683b3ea906882fbf
User & Date: drh 2018-08-13 13:43:11
Context
2018-08-13
15:09
Fix legacy comments on Token. Begin commenting the new ALTER TABLE RENAME COLUMN code. Fix a memory leak in the sqlite_rename_column() SQL function. check-in: 32edc892 user: drh tags: alter-table-rename-column
13:43
Fix issues with ALTER TABLE RENAME COLUMN associated with OOM errors. check-in: 0b28dd5c user: drh tags: alter-table-rename-column
2018-08-11
20:46
Add the "atrc" test program. "Atrc" is short for "ALTER TABLE RENAME COLUMN". See the header comment on the program itself for further information. check-in: ed64a55a user: drh tags: alter-table-rename-column
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/alter.c.

   966    966   
   967    967     memset(&sParse, 0, sizeof(sParse));
   968    968     sParse.eParseMode = PARSE_MODE_RENAME_COLUMN;
   969    969     sParse.db = db;
   970    970     sParse.nQueryLoop = 1;
   971    971     rc = sqlite3RunParser(&sParse, zSql, &zErr);
   972    972     assert( sParse.pNewTable==0 || sParse.pNewIndex==0 );
          973  +  if( db->mallocFailed ) rc = SQLITE_NOMEM;
   973    974     if( rc==SQLITE_OK && sParse.pNewTable==0 && sParse.pNewIndex==0 ){
   974    975       rc = SQLITE_CORRUPT_BKPT;
   975    976     }
   976    977   
   977    978     if( rc==SQLITE_OK ){
   978    979       zQuot = sqlite3_mprintf("\"%w\"", zNew);
   979    980       if( zQuot==0 ){
................................................................................
   986    987     if( rc!=SQLITE_OK ){
   987    988       if( zErr ){
   988    989         sqlite3_result_error(context, zErr, -1);
   989    990       }else{
   990    991         sqlite3_result_error_code(context, rc);
   991    992       }
   992    993       sqlite3DbFree(db, zErr);
   993         -    sqlite3_free(zQuot);
   994         -    return;
          994  +    goto renameColumnFunc_done;
   995    995     }
   996    996   
   997    997     if( bQuote ){
   998    998       zNew = zQuot;
   999    999       nNew = nQuot;
  1000   1000     }
  1001   1001   
................................................................................
  1090   1090         sqlite3DbFree(db, pBest);
  1091   1091       }
  1092   1092   
  1093   1093       sqlite3_result_text(context, zOut, -1, SQLITE_TRANSIENT);
  1094   1094       sqlite3DbFree(db, zOut);
  1095   1095     }
  1096   1096   
         1097  +renameColumnFunc_done:
  1097   1098     if( sParse.pVdbe ){
  1098   1099       sqlite3VdbeFinalize(sParse.pVdbe);
  1099   1100     }
  1100   1101     sqlite3DeleteTable(db, sParse.pNewTable);
  1101   1102     if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  1102   1103     renameTokenFree(db, sParse.pRename);
  1103   1104     sqlite3ParserReset(&sParse);

Changes to src/parse.y.

  1307   1307       if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
  1308   1308           && pParse->db->init.busy==0
  1309   1309       ){
  1310   1310         sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
  1311   1311                            pIdToken->n, pIdToken->z);
  1312   1312       }
  1313   1313       sqlite3ExprListSetName(pParse, p, pIdToken, 1);
  1314         -    if( IN_RENAME_COLUMN ){
         1314  +    if( IN_RENAME_COLUMN && p ){
  1315   1315         sqlite3RenameToken(pParse, (void*)(p->a[p->nExpr-1].zName), pIdToken);
  1316   1316       }
  1317   1317       return p;
  1318   1318     }
  1319   1319   } // end %include
  1320   1320   
  1321   1321   eidlist_opt(A) ::= .                         {A = 0;}