1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Code simplification: ALTER TABLE ADD COLUMN always upgrades the file_format

to 4 if is not there already.  No need to upgrade to only 2 or 3 since format
4 has now been supported for over 10 years.

FossilOrigin-Name: e1d8ec85546caeca3bb7a05ad962a2aed91194ce
This commit is contained in:
drh
2016-02-09 16:09:22 +00:00
parent 2fade2f791
commit bbde018230
5 changed files with 25 additions and 46 deletions

View File

@@ -588,33 +588,6 @@ exit_rename_table:
db->flags = savedDbFlags;
}
/*
** Generate code to make sure the file format number is at least minFormat.
** The generated code will increase the file format number if necessary.
*/
void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){
Vdbe *v;
v = sqlite3GetVdbe(pParse);
/* The VDBE should have been allocated before this routine is called.
** If that allocation failed, we would have quit before reaching this
** point */
if( ALWAYS(v) ){
int r1 = sqlite3GetTempReg(pParse);
int r2 = sqlite3GetTempReg(pParse);
int addr1;
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
sqlite3VdbeUsesBtree(v, iDb);
sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, minFormat);
sqlite3VdbeJumpHere(v, addr1);
sqlite3ReleaseTempReg(pParse, r1);
sqlite3ReleaseTempReg(pParse, r2);
}
}
/*
** This function is called after an "ALTER TABLE ... ADD" statement
** has been parsed. Argument pColDef contains the text of the new
@@ -633,9 +606,11 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
Column *pCol; /* The new column */
Expr *pDflt; /* Default value for the new column */
sqlite3 *db; /* The database connection; */
Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
db = pParse->db;
if( pParse->nErr || db->mallocFailed ) return;
assert( v!=0 );
pNew = pParse->pNewTable;
assert( pNew );
@@ -725,11 +700,16 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
db->flags = savedDbFlags;
}
/* If the default value of the new column is NULL, then set the file
/* If the default value of the new column is NULL, then the file
** format to 2. If the default value of the new column is not NULL,
** the file format becomes 3.
** the file format be 3. Back when this feature was first added
** in 2006, we went to the trouble to upgrade the file format to the
** minimum support values. But 10-years on, we can assume that all
** extent versions of SQLite support file-format 4, so we always and
** unconditionally upgrade to 4.
*/
sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT,
SQLITE_MAX_FILE_FORMAT);
/* Reload the schema of the modified table. */
reloadTableSchema(pParse, pTab, pTab->zName);