From: dan Date: Wed, 24 Jul 2019 08:15:09 +0000 (+0000) Subject: Improve the ".recover" command in the shell tool so that it is not confused by auto... X-Git-Tag: version-3.30.0~198 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=95063c286768c880447ff66641e1a722c32d0b10;p=thirdparty%2Fsqlite.git Improve the ".recover" command in the shell tool so that it is not confused by auto-vacuum databases. And so that it can recover tables for which one or more of the column names are SQL keywords. FossilOrigin-Name: 87d76047d6a3df31bc9b7c0cffa7b758236c124f87263a520850b019cbbc4c6e --- diff --git a/manifest b/manifest index 028a049bcc..8353b07655 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sredefining\stypes\su32\sand\su16\swhen\sfossildelta.c\sis\scompiled\sas\spart\sof\sthe\samalgamation. -D 2019-07-23T13:26:43.019 +C Improve\sthe\s".recover"\scommand\sin\sthe\sshell\stool\sso\sthat\sit\sis\snot\sconfused\sby\sauto-vacuum\sdatabases.\sAnd\sso\sthat\sit\scan\srecover\stables\sfor\swhich\sone\sor\smore\sof\sthe\scolumn\snames\sare\sSQL\skeywords. +D 2019-07-24T08:15:09.374 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -523,7 +523,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c edf29463177e9fa9dad5346e9adf482f24db9f180c693d0ba993e25dc797f6b7 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 F src/select.c 9817d812b13c956ac28d27390602751a8add217f87224d2636fb3ef7e4d646a7 -F src/shell.c.in a571d51dd7605b34796e9942dce0e895156d1860383faf6aaca3c88b08fe2a43 +F src/shell.c.in 68ef28e3a5f110c202d574a537ec75648aec075a74b19acb69192394efb00de9 F src/sqlite.h.in 83ebc8ab1a2e82d92214006ea2c15bf8a0604f3fac2c31dd9ce9021f568c71f2 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5 @@ -1837,7 +1837,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 f60a83069168899dcfd706b4d0901084c7ce92d85277950317e962a8a98ec668 -R 84008622b9c994d74ed4e65360e28d93 +P d8e88248e3204b5f2b95b9b8921ee7ee2f7574ae81e6abd5b4f2ddf187f7d71b +R 01d1db0886e417c95a44058ab3274e67 U dan -Z 85dff92fade63aa4999107c46113ee46 +Z f78057b0d92324722c7a72785904e4d4 diff --git a/manifest.uuid b/manifest.uuid index a29c2b830d..eb75d34e9d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d8e88248e3204b5f2b95b9b8921ee7ee2f7574ae81e6abd5b4f2ddf187f7d71b \ No newline at end of file +87d76047d6a3df31bc9b7c0cffa7b758236c124f87263a520850b019cbbc4c6e \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index b51df8194b..7ccf0bae8c 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -6397,7 +6397,7 @@ static RecoverTable *recoverNewTable( } i = 1; shellPreparePrintf(dbtmp, &rc, &pStmt, - "SELECT %Q || group_concat(name, ', ') " + "SELECT %Q || group_concat(quote(name), ', ') " " FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) " "FROM pragma_table_info(%Q)", bIntkey ? ", " : "", pTab->iPk, @@ -6619,6 +6619,21 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){ ); } + /* If this is an auto-vacuum database, add all pointer-map pages to + ** the freelist table. Do this regardless of whether or not + ** --freelist-corrupt was specified. */ + shellExec(pState->db, &rc, + "WITH ptrmap(pgno) AS (" + " SELECT 2 WHERE shell_int32(" + " (SELECT data FROM sqlite_dbpage WHERE pgno=1), 13" + " )" + " UNION ALL " + " SELECT pgno+1+(SELECT page_size FROM pragma_page_size)/5 AS pp " + " FROM ptrmap WHERE pp<=(SELECT page_count FROM pragma_page_count)" + ")" + "REPLACE INTO recovery.freelist SELECT pgno FROM ptrmap" + ); + shellExec(pState->db, &rc, "CREATE TABLE recovery.dbptr(" " pgno, child, PRIMARY KEY(child, pgno)"