From 86396219a31261a0cc1a69a6cded57073040661d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 14 Jul 2016 19:13:11 +0000 Subject: [PATCH 1/2] Fix ALTER TABLE so that it does not promote the schema version past 3, as that will cause DESC indexes to go corrupt. Ticket [f68bf68513a1c]. FossilOrigin-Name: a7db6e45ad45be9b3003f61d4163f543498a7c9d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/alter.c | 21 ++++++++++++--------- test/alter3.test | 12 ++++++------ test/alter4.test | 19 +++++++++++++++++++ 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index c9585f19cd..966b26fc0e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sshell.c\sfor\sNetBSD. -D 2016-07-13T13:05:13.449 +C Fix\sALTER\sTABLE\sso\sthat\sit\sdoes\snot\spromote\sthe\sschema\sversion\spast\s3,\sas\nthat\swill\scause\sDESC\sindexes\sto\sgo\scorrupt.\nTicket\s[f68bf68513a1c]. +D 2016-07-14T19:13:11.812 F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a @@ -320,7 +320,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b +F src/alter.c cc28ab933ae615b22add0d609794ffb6596b42ea F src/analyze.c 37fedc80ac966ce1745811746e68e4d8fa64c7fe F src/attach.c 771153bd1f4ab0b97a44a13dde2c7e5e1efeba22 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 @@ -475,8 +475,8 @@ F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 6ff7b43c2b4b905c74dc4a813d201d0fa64c5783 F test/alter.test 2facdddf08d0d48e75dc6cc312cd2b030f4835dd F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060 -F test/alter3.test b3568d11c38c4599c92f24242eda34144d78dc10 -F test/alter4.test c461150723ac957f3b2214aa0b11552cd72023ec +F test/alter3.test 4d79934d812eaeacc6f22781a080f8cfe012fdc3 +F test/alter4.test 0c33c542247ba5aee4f4a0133ac44bcf8f97e5e0 F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f F test/analyze.test 3eb35a4af972f98422e5dc0586501b17d103d321 @@ -1505,7 +1505,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 021d0fb8d85e44839d2b4fdb90b15f0e1f2442e6 -R f2c7097376b33c065f9732879605d098 +P 824b39e54fb9ba562be4d92cc9a54aee1cdf84cb +R 7d842c7254944c448483c1d7ddff9ad6 U drh -Z e160e6d632f23e86ebc551e9950cc211 +Z f6a6c237e43006b812e6af2a3e69c586 diff --git a/manifest.uuid b/manifest.uuid index 6b7a74bfc9..1fc14b81a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -824b39e54fb9ba562be4d92cc9a54aee1cdf84cb \ No newline at end of file +a7db6e45ad45be9b3003f61d4163f543498a7c9d \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 642c1fb677..806ed49172 100644 --- a/src/alter.c +++ b/src/alter.c @@ -601,6 +601,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ Expr *pDflt; /* Default value for the new column */ sqlite3 *db; /* The database connection; */ Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */ + int r1; /* Temporary registers */ db = pParse->db; if( pParse->nErr || db->mallocFailed ) return; @@ -695,16 +696,18 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ 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. + /* Make sure the schema version is at least 3. But do not upgrade + ** from less than 3 to 4, as that will corrupt any preexisting DESC + ** index. */ - sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, - SQLITE_MAX_FILE_FORMAT); + r1 = sqlite3GetTempReg(pParse); + sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); + sqlite3VdbeUsesBtree(v, iDb); + sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2); + sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2); + VdbeCoverage(v); + sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3); + sqlite3ReleaseTempReg(pParse, r1); /* Reload the schema of the modified table. */ reloadTableSchema(pParse, pTab, pTab->zName); diff --git a/test/alter3.test b/test/alter3.test index f8ebe056f2..44b31c9833 100644 --- a/test/alter3.test +++ b/test/alter3.test @@ -184,7 +184,7 @@ do_test alter3-3.2 { if {!$has_codec} { do_test alter3-3.3 { get_file_format - } {4} + } {3} } ifcapable schema_version { do_test alter3-3.4 { @@ -220,7 +220,7 @@ do_test alter3-4.2 { if {!$has_codec} { do_test alter3-4.3 { get_file_format - } {4} + } {3} } ifcapable schema_version { do_test alter3-4.4 { @@ -270,7 +270,7 @@ ifcapable attach { if {!$has_codec} { do_test alter3-5.5 { list [get_file_format test2.db] [get_file_format] - } {4 4} + } {3 3} } do_test alter3-5.6 { execsql { @@ -347,19 +347,19 @@ if {!$has_codec} { ALTER TABLE abc ADD d DEFAULT NULL; } get_file_format - } {4} + } {3} do_test alter3-7.3 { execsql { ALTER TABLE abc ADD e DEFAULT 10; } get_file_format - } {4} + } {3} do_test alter3-7.4 { execsql { ALTER TABLE abc ADD f DEFAULT NULL; } get_file_format - } {4} + } {3} do_test alter3-7.5 { execsql { VACUUM; diff --git a/test/alter4.test b/test/alter4.test index ac39d614a5..2cd78777a2 100644 --- a/test/alter4.test +++ b/test/alter4.test @@ -355,4 +355,23 @@ do_execsql_test alter4-9.3 { SELECT typeof(c), c FROM t5; } {real 9.22337203685478e+18} +# Confirm that doing an ALTER TABLE on a legacy format database +# does not corrupt DESC indexes. +# +# Ticket https://www.sqlite.org/src/tktview/f68bf68513a1c +# +do_test alter4-10.1 { + db close + sqlite3 db :memory: + db eval { + PRAGMA legacy_file_format=on; + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a DESC); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(2,3,4); + ALTER TABLE t1 ADD COLUMN d; + PRAGMA integrity_check; + } +} {ok} + finish_test From eb5a549ecfb1fb67c66b1061f5db95bae46f4c47 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 15 Jul 2016 02:50:18 +0000 Subject: [PATCH 2/2] Disable the CSV extension when virtual tables are disabled. FossilOrigin-Name: ec7180892ac737f0731cf61f2d095a5c1d18ad93 --- ext/misc/csv.c | 7 +++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ext/misc/csv.c b/ext/misc/csv.c index 3a7e32d311..a055a8df13 100644 --- a/ext/misc/csv.c +++ b/ext/misc/csv.c @@ -48,6 +48,8 @@ SQLITE_EXTENSION_INIT1 #include #include +#ifndef SQLITE_OMIT_VIRTUALTABLE + /* ** A macro to hint to the compiler that a function should not be ** inlined. @@ -834,6 +836,7 @@ static sqlite3_module CsvModuleFauxWrite = { }; #endif /* SQLITE_TEST */ +#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ #ifdef _WIN32 @@ -849,6 +852,7 @@ int sqlite3_csv_init( char **pzErrMsg, const sqlite3_api_routines *pApi ){ +#ifndef SQLITE_OMIT_VIRTUALTABLE int rc; SQLITE_EXTENSION_INIT2(pApi); rc = sqlite3_create_module(db, "csv", &CsvModule, 0); @@ -858,4 +862,7 @@ int sqlite3_csv_init( } #endif return rc; +#else + return SQLITE_OK; +#endif } diff --git a/manifest b/manifest index 966b26fc0e..3e9a346ef3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sALTER\sTABLE\sso\sthat\sit\sdoes\snot\spromote\sthe\sschema\sversion\spast\s3,\sas\nthat\swill\scause\sDESC\sindexes\sto\sgo\scorrupt.\nTicket\s[f68bf68513a1c]. -D 2016-07-14T19:13:11.812 +C Disable\sthe\sCSV\sextension\swhen\svirtual\stables\sare\sdisabled. +D 2016-07-15T02:50:18.913 F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a @@ -207,7 +207,7 @@ F ext/misc/amatch.c 211108e201105e4bb0c076527b8cfd34330fc234 F ext/misc/carray.c 214c9e9d909ceaae3b2f5f917cc2204deca85cc6 F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 -F ext/misc/csv.c b92692b057707f5b7bb91feaedde790b2e38304e +F ext/misc/csv.c f51b0566ea15e24cce871037e30a4db99ea6cf77 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 @@ -1505,7 +1505,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 824b39e54fb9ba562be4d92cc9a54aee1cdf84cb -R 7d842c7254944c448483c1d7ddff9ad6 +P a7db6e45ad45be9b3003f61d4163f543498a7c9d +R ec00a189cb07c46ebd136f03f1e34d37 U drh -Z f6a6c237e43006b812e6af2a3e69c586 +Z 4982072efce5132597470baa33eb57d2 diff --git a/manifest.uuid b/manifest.uuid index 1fc14b81a9..3747973d87 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a7db6e45ad45be9b3003f61d4163f543498a7c9d \ No newline at end of file +ec7180892ac737f0731cf61f2d095a5c1d18ad93 \ No newline at end of file