/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/alter.c.

966
967
968
969
970
971
972

973
974
975
976
977
978
979
...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
....
1090
1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103

  memset(&sParse, 0, sizeof(sParse));
  sParse.eParseMode = PARSE_MODE_RENAME_COLUMN;
  sParse.db = db;
  sParse.nQueryLoop = 1;
  rc = sqlite3RunParser(&sParse, zSql, &zErr);
  assert( sParse.pNewTable==0 || sParse.pNewIndex==0 );

  if( rc==SQLITE_OK && sParse.pNewTable==0 && sParse.pNewIndex==0 ){
    rc = SQLITE_CORRUPT_BKPT;
  }

  if( rc==SQLITE_OK ){
    zQuot = sqlite3_mprintf("\"%w\"", zNew);
    if( zQuot==0 ){
................................................................................
  if( rc!=SQLITE_OK ){
    if( zErr ){
      sqlite3_result_error(context, zErr, -1);
    }else{
      sqlite3_result_error_code(context, rc);
    }
    sqlite3DbFree(db, zErr);
    sqlite3_free(zQuot);
    return;
  }

  if( bQuote ){
    zNew = zQuot;
    nNew = nQuot;
  }

................................................................................
      sqlite3DbFree(db, pBest);
    }

    sqlite3_result_text(context, zOut, -1, SQLITE_TRANSIENT);
    sqlite3DbFree(db, zOut);
  }


  if( sParse.pVdbe ){
    sqlite3VdbeFinalize(sParse.pVdbe);
  }
  sqlite3DeleteTable(db, sParse.pNewTable);
  if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  renameTokenFree(db, sParse.pRename);
  sqlite3ParserReset(&sParse);







>







 







|
<







 







>







966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
...
987
988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
....
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

  memset(&sParse, 0, sizeof(sParse));
  sParse.eParseMode = PARSE_MODE_RENAME_COLUMN;
  sParse.db = db;
  sParse.nQueryLoop = 1;
  rc = sqlite3RunParser(&sParse, zSql, &zErr);
  assert( sParse.pNewTable==0 || sParse.pNewIndex==0 );
  if( db->mallocFailed ) rc = SQLITE_NOMEM;
  if( rc==SQLITE_OK && sParse.pNewTable==0 && sParse.pNewIndex==0 ){
    rc = SQLITE_CORRUPT_BKPT;
  }

  if( rc==SQLITE_OK ){
    zQuot = sqlite3_mprintf("\"%w\"", zNew);
    if( zQuot==0 ){
................................................................................
  if( rc!=SQLITE_OK ){
    if( zErr ){
      sqlite3_result_error(context, zErr, -1);
    }else{
      sqlite3_result_error_code(context, rc);
    }
    sqlite3DbFree(db, zErr);
    goto renameColumnFunc_done;

  }

  if( bQuote ){
    zNew = zQuot;
    nNew = nQuot;
  }

................................................................................
      sqlite3DbFree(db, pBest);
    }

    sqlite3_result_text(context, zOut, -1, SQLITE_TRANSIENT);
    sqlite3DbFree(db, zOut);
  }

renameColumnFunc_done:
  if( sParse.pVdbe ){
    sqlite3VdbeFinalize(sParse.pVdbe);
  }
  sqlite3DeleteTable(db, sParse.pNewTable);
  if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  renameTokenFree(db, sParse.pRename);
  sqlite3ParserReset(&sParse);

Changes to src/parse.y.

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

eidlist_opt(A) ::= .                         {A = 0;}







|







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

eidlist_opt(A) ::= .                         {A = 0;}