]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix another problem with database freelist handling in the ".recover" command.
authordan <dan@noemail.net>
Fri, 26 Apr 2019 15:40:27 +0000 (15:40 +0000)
committerdan <dan@noemail.net>
Fri, 26 Apr 2019 15:40:27 +0000 (15:40 +0000)
FossilOrigin-Name: bee2652ac26370e612a8c81dd7554befc2d523442a2fbbc77dc73479e6a0d7fd

manifest
manifest.uuid
src/shell.c.in

index d361dc7ebcfd04b204538122f6b4ca30dc06f65f..2ea5b39962c578c5c84f262485cbb71ba18ca4c8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\slocking-page\srelated\sproblem\swith\sthe\s".recover"\scommand.
-D 2019-04-26T15:14:53.514
+C Fix\sanother\sproblem\swith\sdatabase\sfreelist\shandling\sin\sthe\s".recover"\scommand.
+D 2019-04-26T15:40:27.902
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -520,7 +520,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 567888ee3faec14dae06519b4306201771058364a37560186a3e0e755ebc4cb8
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
 F src/select.c b7304d2f491c11a03a7fbdf34bc218282ac54052377809d4dc3b4b1e7f4bfc93
-F src/shell.c.in 63b1075817997806d7f09c2a0433ffac854b6dee47836ef938d51531cdb8042f
+F src/shell.c.in 44dce9f5b3c68c07e30db740aa4e635819ab6fa01a229a21356ddd4fa8f1e47e
 F src/sqlite.h.in 38390767acc1914d58930e03149595ee4710afa4e3c43ab6c3a8aea3f1a6b8cd
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
@@ -1821,7 +1821,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 1da302d85d7ad4ba54f877117a45d667439fd2ef31dc70ea1d54dc1fba196e68
-R 981714fd52a70e51cf4586f924a49fdc
+P afdae10424f0f3d0f10a4b73e9732aa55c5ee664814d8ca0edd372cfb17c2445
+R 5b76306d65317b1b0fee3a74fc0359d7
 U dan
-Z 303a0ea3c8fcc86a61370f3e12d83ec5
+Z 068a6ba7f1f2eaa523c5f432cd2b8c0c
index b5f67ee78050f7520135514a611517e55387025c..4c5a22946168b81f87d6d35674bf19d23129994e 100644 (file)
@@ -1 +1 @@
-afdae10424f0f3d0f10a4b73e9732aa55c5ee664814d8ca0edd372cfb17c2445
\ No newline at end of file
+bee2652ac26370e612a8c81dd7554befc2d523442a2fbbc77dc73479e6a0d7fd
\ No newline at end of file
index 1884e7bfe252c51a0823c89d6ed9055dc47f0a48..c417160d525714b314b1241e3900267cf570a5c4 100644 (file)
@@ -6454,23 +6454,6 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
     "DROP TABLE IF EXISTS recovery.freelist;"
     "DROP TABLE IF EXISTS recovery.map;"
     "DROP TABLE IF EXISTS recovery.schema;"
-    "CREATE TABLE recovery.dbptr("
-    "      pgno, child, PRIMARY KEY(child, pgno)"
-    ") WITHOUT ROWID;"
-    "INSERT OR IGNORE INTO recovery.dbptr(pgno, child) "
-    "    SELECT * FROM sqlite_dbptr;"
-
-    /* Delete any pointer to page 1. This ensures that page 1 is considered
-    ** a root page, regardless of how corrupt the db is. */
-    "DELETE FROM recovery.dbptr WHERE child = 1;"
-
-    /* Delete all pointers to any pages that have more than one pointer
-    ** to them. Such pages will be treated as root pages when recovering
-    ** data.  */
-    "DELETE FROM recovery.dbptr WHERE child IN ("
-    "  SELECT child FROM recovery.dbptr GROUP BY child HAVING count(*)>1"
-    ");"
-
     "CREATE TABLE recovery.freelist(pgno INTEGER PRIMARY KEY);", zRecoveryDb
   );
 
@@ -6497,6 +6480,24 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
   }
 
   shellExec(pState->db, &rc, 
+    "CREATE TABLE recovery.dbptr("
+    "      pgno, child, PRIMARY KEY(child, pgno)"
+    ") WITHOUT ROWID;"
+    "INSERT OR IGNORE INTO recovery.dbptr(pgno, child) "
+    "    SELECT * FROM sqlite_dbptr"
+    "      WHERE pgno NOT IN freelist AND child NOT IN freelist;"
+
+    /* Delete any pointer to page 1. This ensures that page 1 is considered
+    ** a root page, regardless of how corrupt the db is. */
+    "DELETE FROM recovery.dbptr WHERE child = 1;"
+
+    /* Delete all pointers to any pages that have more than one pointer
+    ** to them. Such pages will be treated as root pages when recovering
+    ** data.  */
+    "DELETE FROM recovery.dbptr WHERE child IN ("
+    "  SELECT child FROM recovery.dbptr GROUP BY child HAVING count(*)>1"
+    ");"
+
     /* Create the "map" table that will (eventually) contain instructions
     ** for dealing with each page in the db that contains one or more 
     ** records. */