From 2d71ca94a98b724a4b70cd7dcb59e0ec3be56685 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Feb 2004 02:27:04 +0000 Subject: [PATCH] Move the file-format-2 to file-format-3 conversion into sqliteInit(). (CVS 1218) FossilOrigin-Name: dcbe2800be2f805818724a7b9e468c4fd4f02529 --- manifest | 12 ++++---- manifest.uuid | 2 +- src/main.c | 79 ++++++++++++++++++++++++++------------------------- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/manifest b/manifest index d99367595d..da99a16eb7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sSQLITE_PAGE_SIZE\sto\sbe\sredefined\son\sthe\scompiler\scommand-line.\s(CVS\s1217) -D 2004-02-10T01:54:28 +C Move\sthe\sfile-format-2\sto\sfile-format-3\sconversion\sinto\ssqliteInit().\s(CVS\s1218) +D 2004-02-10T02:27:04 F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -36,7 +36,7 @@ F src/func.c 5a0face8c3a948c62677243987a18ba2f9ef9c9b F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7 F src/insert.c 01f66866f35c986eab4a57373ca689a3255ef2df -F src/main.c 808ea1bda0798f4a714479aee8289d65f04cf29b +F src/main.c 6ec57b0f146572033c70493417d251365a7b4fbe F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565 F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c F src/os.h 8d02b622153d2df442da1ec37cdd6b1bd9804a25 @@ -183,7 +183,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 1cff18868dab5f8ead8ed8d07e088d7fdda04569 -R 2282b1880e3a49fd92893af5cc842432 +P 4c7bf714b5f3d2bb7366367ddf906141a7e36407 +R f85f80413b9f3d1ec6ff32e333e954ad U drh -Z 382396977f47fa557ea3e3bc564ad2a2 +Z a139fd450dfe5d0adfcdd504d2d2ab73 diff --git a/manifest.uuid b/manifest.uuid index 8c6ebcbc98..657a329d4c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c7bf714b5f3d2bb7366367ddf906141a7e36407 \ No newline at end of file +dcbe2800be2f805818724a7b9e468c4fd4f02529 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 17d2e04eb2..b338c3dda4 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.146 2004/01/15 13:29:32 drh Exp $ +** $Id: main.c,v 1.147 2004/02/10 02:27:04 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -127,6 +127,9 @@ int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){ ** format version 1 or 2 to version 3. The correct operation of ** this routine relys on the fact that no indices are used when ** copying a table out to a temporary file. +** +** The change from version 2 to version 3 occurred between SQLite +** version 2.5.6 and 2.6.0 on 2002-July-18. */ static int upgrade_3_callback(void *pInit, int argc, char **argv, char **NotUsed){ @@ -388,7 +391,43 @@ int sqliteInit(sqlite *db, char **pzErrMsg){ if( rc==SQLITE_OK ){ db->flags |= SQLITE_Initialized; sqliteCommitInternalChanges(db); - }else{ + } + + /* If the database is in formats 1 or 2, then upgrade it to + ** version 3. This will reconstruct all indices. If the + ** upgrade fails for any reason (ex: out of disk space, database + ** is read only, interrupt received, etc.) then fail the init. + */ + if( rc==SQLITE_OK && db->file_format<3 ){ + char *zErr = 0; + InitData initData; + int meta[SQLITE_N_BTREE_META]; + + db->magic = SQLITE_MAGIC_OPEN; + initData.db = db; + initData.pzErrMsg = &zErr; + db->file_format = 3; + rc = sqlite_exec(db, + "BEGIN; SELECT name FROM sqlite_master WHERE type='table';", + upgrade_3_callback, + &initData, + &zErr); + if( rc==SQLITE_OK ){ + sqliteBtreeGetMeta(db->aDb[0].pBt, meta); + meta[2] = 4; + sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta); + sqlite_exec(db, "COMMIT", 0, 0, 0); + } + if( rc!=SQLITE_OK ){ + sqliteSetString(pzErrMsg, + "unable to upgrade database to the version 2.6 format", + zErr ? ": " : 0, zErr, (char*)0); + sqliteStrRealloc(pzErrMsg); + } + sqlite_freemem(zErr); + } + + if( rc!=SQLITE_OK ){ db->flags &= ~SQLITE_Initialized; } return rc; @@ -475,42 +514,6 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){ *pzErrMsg = 0; } - /* If the database is in formats 1 or 2, then upgrade it to - ** version 3. This will reconstruct all indices. If the - ** upgrade fails for any reason (ex: out of disk space, database - ** is read only, interrupt received, etc.) then refuse to open. - */ - if( rc==SQLITE_OK && db->file_format<3 ){ - char *zErr = 0; - InitData initData; - int meta[SQLITE_N_BTREE_META]; - - initData.db = db; - initData.pzErrMsg = &zErr; - db->file_format = 3; - rc = sqlite_exec(db, - "BEGIN; SELECT name FROM sqlite_master WHERE type='table';", - upgrade_3_callback, - &initData, - &zErr); - if( rc==SQLITE_OK ){ - sqliteBtreeGetMeta(db->aDb[0].pBt, meta); - meta[2] = 4; - sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta); - sqlite_exec(db, "COMMIT", 0, 0, 0); - } - if( rc!=SQLITE_OK ){ - sqliteSetString(pzErrMsg, - "unable to upgrade database to the version 2.6 format", - zErr ? ": " : 0, zErr, (char*)0); - sqlite_freemem(zErr); - sqliteStrRealloc(pzErrMsg); - sqlite_close(db); - return 0; - } - sqlite_freemem(zErr); - } - /* Return a pointer to the newly opened database structure */ return db;