Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | 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. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
e1d8ec85546caeca3bb7a05ad962a2ae |
User & Date: | drh 2016-02-09 16:09:22.275 |
References
2016-07-14
| ||
18:46 | • New ticket [f68bf68513] ALTER TABLE corrupts DESC indexes. (artifact: 2db52790f1 user: drh) | |
Context
2016-02-09
| ||
17:12 | Fix the top-level makefiles to always include SQLITE_ENABLE_EXPLAIN_COMMENTS when building the shell. Still need to fix main.mk and the amalgamation tarball. (check-in: 992282399c user: drh tags: trunk) | |
16:09 | 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. (check-in: e1d8ec8554 user: drh tags: trunk) | |
02:12 | Make sure every co-routines has its own set of temporary registers and does not share temporaries, since a co-routine might expect the content of a temporary register to be preserved across an OP_Yield. Proposed fix for ticket [d06a25c84454a]. (check-in: ca72be8618 user: drh tags: trunk) | |
Changes
Changes to src/alter.c.
︙ | ︙ | |||
584 585 586 587 588 589 590 | exit_rename_table: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zName); db->flags = savedDbFlags; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < > > | 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | exit_rename_table: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zName); db->flags = savedDbFlags; } /* ** This function is called after an "ALTER TABLE ... ADD" statement ** has been parsed. Argument pColDef contains the text of the new ** column definition. ** ** The Table structure pParse->pNewTable was extended to include ** the new column during parsing. */ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ Table *pNew; /* Copy of pParse->pNewTable */ Table *pTab; /* Table being altered */ int iDb; /* Database number */ const char *zDb; /* Database name */ const char *zTab; /* Table name */ char *zCol; /* Null-terminated column definition */ 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 ); assert( sqlite3BtreeHoldsAllMutexes(db) ); iDb = sqlite3SchemaToIndex(db, pNew->pSchema); zDb = db->aDb[iDb].zName; zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */ |
︙ | ︙ | |||
721 722 723 724 725 726 727 | zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1, zTab ); sqlite3DbFree(db, zCol); db->flags = savedDbFlags; } | | | > > > > | > | 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1, zTab ); sqlite3DbFree(db, zCol); db->flags = savedDbFlags; } /* 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 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. */ sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, SQLITE_MAX_FILE_FORMAT); /* Reload the schema of the modified table. */ reloadTableSchema(pParse, pTab, pTab->zName); } /* ** This function is called by the parser after the table-name in |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
3760 3761 3762 3763 3764 3765 3766 | int sqlite3FindDb(sqlite3*, Token*); int sqlite3FindDbName(sqlite3 *, const char *); int sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DeleteIndexSamples(sqlite3*,Index*); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); | < | 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 | int sqlite3FindDb(sqlite3*, Token*); int sqlite3FindDbName(sqlite3 *, const char *); int sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DeleteIndexSamples(sqlite3*,Index*); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); void sqlite3SchemaClear(void *); Schema *sqlite3SchemaGet(sqlite3 *, Btree *); int sqlite3SchemaToIndex(sqlite3 *db, Schema *); KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); void sqlite3KeyInfoUnref(KeyInfo*); KeyInfo *sqlite3KeyInfoRef(KeyInfo*); KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); |
︙ | ︙ |
Changes to test/alter3.test.
︙ | ︙ | |||
180 181 182 183 184 185 186 | ALTER TABLE t1 ADD c; SELECT * FROM t1; } } {1 100 {} 2 300 {}} if {!$has_codec} { do_test alter3-3.3 { get_file_format | | | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | ALTER TABLE t1 ADD c; SELECT * FROM t1; } } {1 100 {} 2 300 {}} if {!$has_codec} { do_test alter3-3.3 { get_file_format } {4} } ifcapable schema_version { do_test alter3-3.4 { execsql { PRAGMA schema_version; } } {11} |
︙ | ︙ | |||
216 217 218 219 220 221 222 | ALTER TABLE t1 ADD c DEFAULT 'hello world'; SELECT * FROM t1; } } {1 100 {hello world} 2 300 {hello world}} if {!$has_codec} { do_test alter3-4.3 { get_file_format | | | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | ALTER TABLE t1 ADD c DEFAULT 'hello world'; SELECT * FROM t1; } } {1 100 {hello world} 2 300 {hello world}} if {!$has_codec} { do_test alter3-4.3 { get_file_format } {4} } ifcapable schema_version { do_test alter3-4.4 { execsql { PRAGMA schema_version; } } {21} |
︙ | ︙ | |||
266 267 268 269 270 271 272 | PRAGMA aux.schema_version; } } {31} } if {!$has_codec} { do_test alter3-5.5 { list [get_file_format test2.db] [get_file_format] | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | PRAGMA aux.schema_version; } } {31} } if {!$has_codec} { do_test alter3-5.5 { list [get_file_format test2.db] [get_file_format] } {4 4} } do_test alter3-5.6 { execsql { ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000; SELECT sql FROM aux.sqlite_master; } } {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}} |
︙ | ︙ | |||
343 344 345 346 347 348 349 | } {1} do_test alter3-7.2 { execsql { CREATE TABLE abc(a, b, c); ALTER TABLE abc ADD d DEFAULT NULL; } get_file_format | | | | | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | } {1} do_test alter3-7.2 { execsql { CREATE TABLE abc(a, b, c); ALTER TABLE abc ADD d DEFAULT NULL; } get_file_format } {4} do_test alter3-7.3 { execsql { ALTER TABLE abc ADD e DEFAULT 10; } get_file_format } {4} do_test alter3-7.4 { execsql { ALTER TABLE abc ADD f DEFAULT NULL; } get_file_format } {4} do_test alter3-7.5 { execsql { VACUUM; } get_file_format } {1} } |
︙ | ︙ |