| OLD | NEW |
| 1 From 13a64d3c7fb541be8cb753c575837c1b84f5d9fd Mon Sep 17 00:00:00 2001 | 1 From ec588be0416fab3e957d0901eb6e638543b01229 Mon Sep 17 00:00:00 2001 |
| 2 From: Scott Hess <shess@chromium.org> | 2 From: Scott Hess <shess@chromium.org> |
| 3 Date: Sat, 20 Jul 2013 11:42:21 -0700 | 3 Date: Sat, 20 Jul 2013 11:42:21 -0700 |
| 4 Subject: [PATCH 06/16] Virtual table supporting recovery of corrupted | 4 Subject: [PATCH 06/11] Virtual table supporting recovery of corrupted |
| 5 databases. | 5 databases. |
| 6 | 6 |
| 7 "recover" implements a virtual table which uses the SQLite pager layer | 7 "recover" implements a virtual table which uses the SQLite pager layer |
| 8 to read table pages and pull out the data which is structurally sound | 8 to read table pages and pull out the data which is structurally sound |
| 9 (at least at the storage layer). | 9 (at least at the storage layer). |
| 10 | 10 |
| 11 BUG=109482 | 11 BUG=109482 |
| 12 | 12 |
| 13 Since this implements a new feature for SQLite, the review URLs aren't | 13 Since this implements a new feature for SQLite, the review URLs aren't |
| 14 listed. This patch and the top of recover.c should be considered | 14 listed. This patch and the top of recover.c should be considered |
| 15 authoritative. The history is mostly under | 15 authoritative. The history is mostly under |
| 16 third_party/sqlite/src/src/{recover,recover-alt}.c . | 16 third_party/sqlite/src/src/{recover,recover-alt}.c . |
| 17 --- | 17 --- |
| 18 third_party/sqlite/src/Makefile.in | 1 + | 18 third_party/sqlite/src/Makefile.in | 1 + |
| 19 third_party/sqlite/src/Makefile.linux-gcc | 4 + | 19 third_party/sqlite/src/Makefile.linux-gcc | 4 + |
| 20 third_party/sqlite/src/main.mk | 4 +- | 20 third_party/sqlite/src/main.mk | 4 +- |
| 21 third_party/sqlite/src/src/main.c | 8 + | 21 third_party/sqlite/src/src/main.c | 8 + |
| 22 third_party/sqlite/src/src/recover.c | 2164 ++++++++++++++++++++++++++++ | 22 third_party/sqlite/src/src/recover.c | 2165 ++++++++++++++++++++++++++++ |
| 23 third_party/sqlite/src/src/sqlite.h.in | 11 + | 23 third_party/sqlite/src/src/sqlite.h.in | 16 + |
| 24 third_party/sqlite/src/test/recover.test | 147 ++ | 24 third_party/sqlite/src/test/recover.test | 147 ++ |
| 25 third_party/sqlite/src/test/recover0.test | 532 +++++++ | 25 third_party/sqlite/src/test/recover0.test | 532 +++++++ |
| 26 third_party/sqlite/src/test/recover1.test | 429 ++++++ | 26 third_party/sqlite/src/test/recover1.test | 429 ++++++ |
| 27 third_party/sqlite/src/test/recover2.test | 157 ++ | 27 third_party/sqlite/src/test/recover2.test | 157 ++ |
| 28 third_party/sqlite/src/tool/mksqlite3c.tcl | 2 + | 28 third_party/sqlite/src/tool/mksqlite3c.tcl | 2 + |
| 29 11 files changed, 3458 insertions(+), 1 deletion(-) | 29 11 files changed, 3464 insertions(+), 1 deletion(-) |
| 30 create mode 100644 third_party/sqlite/src/src/recover.c | 30 create mode 100644 third_party/sqlite/src/src/recover.c |
| 31 create mode 100644 third_party/sqlite/src/test/recover.test | 31 create mode 100644 third_party/sqlite/src/test/recover.test |
| 32 create mode 100644 third_party/sqlite/src/test/recover0.test | 32 create mode 100644 third_party/sqlite/src/test/recover0.test |
| 33 create mode 100644 third_party/sqlite/src/test/recover1.test | 33 create mode 100644 third_party/sqlite/src/test/recover1.test |
| 34 create mode 100644 third_party/sqlite/src/test/recover2.test | 34 create mode 100644 third_party/sqlite/src/test/recover2.test |
| 35 | 35 |
| 36 diff --git a/third_party/sqlite/src/Makefile.in b/third_party/sqlite/src/Makefil
e.in | 36 diff --git a/third_party/sqlite/src/Makefile.in b/third_party/sqlite/src/Makefil
e.in |
| 37 index a2213e8..1389486 100644 | 37 index a2213e8..1389486 100644 |
| 38 --- a/third_party/sqlite/src/Makefile.in | 38 --- a/third_party/sqlite/src/Makefile.in |
| 39 +++ b/third_party/sqlite/src/Makefile.in | 39 +++ b/third_party/sqlite/src/Makefile.in |
| 40 @@ -253,6 +253,7 @@ SRC = \ | 40 @@ -253,6 +253,7 @@ SRC = \ |
| 41 $(TOP)/src/prepare.c \ | 41 $(TOP)/src/prepare.c \ |
| 42 $(TOP)/src/printf.c \ | 42 $(TOP)/src/printf.c \ |
| 43 $(TOP)/src/random.c \ | 43 $(TOP)/src/random.c \ |
| 44 + $(TOP)/src/recover.c \ | 44 + $(TOP)/src/recover.c \ |
| 45 $(TOP)/src/resolve.c \ | 45 $(TOP)/src/resolve.c \ |
| 46 $(TOP)/src/rowset.c \ | 46 $(TOP)/src/rowset.c \ |
| 47 $(TOP)/src/select.c \ | 47 $(TOP)/src/select.c \ |
| 48 diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/
Makefile.linux-gcc | 48 diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/
Makefile.linux-gcc |
| 49 index 554bf56..e631816 100644 | 49 index 4f6cdf1..dd8f46d 100644 |
| 50 --- a/third_party/sqlite/src/Makefile.linux-gcc | 50 --- a/third_party/sqlite/src/Makefile.linux-gcc |
| 51 +++ b/third_party/sqlite/src/Makefile.linux-gcc | 51 +++ b/third_party/sqlite/src/Makefile.linux-gcc |
| 52 @@ -82,6 +82,10 @@ OPTS += -DSQLITE_MEMDEBUG=1 | 52 @@ -81,6 +81,10 @@ OPTS += -DSQLITE_MEMDEBUG=1 |
| 53 # TODO(shess) I can't see why I need this setting. | 53 # TODO(shess) I can't see why I need this setting. |
| 54 OPTS += -DOS_UNIX=1 | 54 OPTS += -DOS_UNIX=1 |
| 55 | 55 |
| 56 +# The recover virtual table is not generally enabled. Enable it for testing | 56 +# The recover virtual table is not generally enabled. Enable it for testing |
| 57 +# purposes. | 57 +# purposes. |
| 58 +OPTS += -DDEFAULT_ENABLE_RECOVER=1 | 58 +OPTS += -DDEFAULT_ENABLE_RECOVER=1 |
| 59 + | 59 + |
| 60 #### The suffix to add to executable files. ".exe" for windows. | 60 #### The suffix to add to executable files. ".exe" for windows. |
| 61 # Nothing for unix. | 61 # Nothing for unix. |
| 62 # | 62 # |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 + if( !db->mallocFailed && rc==SQLITE_OK ){ | 103 + if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 104 + rc = recoverVtableInit(db); | 104 + rc = recoverVtableInit(db); |
| 105 + } | 105 + } |
| 106 +#endif | 106 +#endif |
| 107 + | 107 + |
| 108 #ifdef SQLITE_ENABLE_ICU | 108 #ifdef SQLITE_ENABLE_ICU |
| 109 if( !db->mallocFailed && rc==SQLITE_OK ){ | 109 if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 110 rc = sqlite3IcuInit(db); | 110 rc = sqlite3IcuInit(db); |
| 111 diff --git a/third_party/sqlite/src/src/recover.c b/third_party/sqlite/src/src/r
ecover.c | 111 diff --git a/third_party/sqlite/src/src/recover.c b/third_party/sqlite/src/src/r
ecover.c |
| 112 new file mode 100644 | 112 new file mode 100644 |
| 113 index 0000000..c996d53 | 113 index 0000000..6882d6f |
| 114 --- /dev/null | 114 --- /dev/null |
| 115 +++ b/third_party/sqlite/src/src/recover.c | 115 +++ b/third_party/sqlite/src/src/recover.c |
| 116 @@ -0,0 +1,2164 @@ | 116 @@ -0,0 +1,2165 @@ |
| 117 +/* | 117 +/* |
| 118 +** 2012 Jan 11 | 118 +** 2012 Jan 11 |
| 119 +** | 119 +** |
| 120 +** The author disclaims copyright to this source code. In place of | 120 +** The author disclaims copyright to this source code. In place of |
| 121 +** a legal notice, here is a blessing: | 121 +** a legal notice, here is a blessing: |
| 122 +** | 122 +** |
| 123 +** May you do good and not evil. | 123 +** May you do good and not evil. |
| 124 +** May you find forgiveness for yourself and forgive others. | 124 +** May you find forgiveness for yourself and forgive others. |
| 125 +** May you share freely, never taking more than you give. | 125 +** May you share freely, never taking more than you give. |
| 126 +*/ | 126 +*/ |
| (...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 + recoverRowid, /* xRowid - read data */ | 1984 + recoverRowid, /* xRowid - read data */ |
| 1985 + 0, /* xUpdate - write data */ | 1985 + 0, /* xUpdate - write data */ |
| 1986 + 0, /* xBegin - begin transaction */ | 1986 + 0, /* xBegin - begin transaction */ |
| 1987 + 0, /* xSync - sync transaction */ | 1987 + 0, /* xSync - sync transaction */ |
| 1988 + 0, /* xCommit - commit transaction */ | 1988 + 0, /* xCommit - commit transaction */ |
| 1989 + 0, /* xRollback - rollback transaction */ | 1989 + 0, /* xRollback - rollback transaction */ |
| 1990 + 0, /* xFindFunction - function overloading */ | 1990 + 0, /* xFindFunction - function overloading */ |
| 1991 + 0, /* xRename - rename the table */ | 1991 + 0, /* xRename - rename the table */ |
| 1992 +}; | 1992 +}; |
| 1993 + | 1993 + |
| 1994 +CHROMIUM_SQLITE_API |
| 1994 +int recoverVtableInit(sqlite3 *db){ | 1995 +int recoverVtableInit(sqlite3 *db){ |
| 1995 + return sqlite3_create_module_v2(db, "recover", &recoverModule, NULL, 0); | 1996 + return sqlite3_create_module_v2(db, "recover", &recoverModule, NULL, 0); |
| 1996 +} | 1997 +} |
| 1997 + | 1998 + |
| 1998 +/* This section of code is for parsing the create input and | 1999 +/* This section of code is for parsing the create input and |
| 1999 + * initializing the module. | 2000 + * initializing the module. |
| 2000 + */ | 2001 + */ |
| 2001 + | 2002 + |
| 2002 +/* Find the next word in zText and place the endpoints in pzWord*. | 2003 +/* Find the next word in zText and place the endpoints in pzWord*. |
| 2003 + * Returns true if the word is non-empty. "Word" is defined as | 2004 + * Returns true if the word is non-empty. "Word" is defined as |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 + sqlite3_free(zCreateSql); | 2273 + sqlite3_free(zCreateSql); |
| 2273 + if( rc!=SQLITE_OK ){ | 2274 + if( rc!=SQLITE_OK ){ |
| 2274 + recoverRelease(pRecover); | 2275 + recoverRelease(pRecover); |
| 2275 + return rc; | 2276 + return rc; |
| 2276 + } | 2277 + } |
| 2277 + | 2278 + |
| 2278 + *ppVtab = (sqlite3_vtab *)pRecover; | 2279 + *ppVtab = (sqlite3_vtab *)pRecover; |
| 2279 + return SQLITE_OK; | 2280 + return SQLITE_OK; |
| 2280 +} | 2281 +} |
| 2281 diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src
/sqlite.h.in | 2282 diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src
/sqlite.h.in |
| 2282 index f1d4e40..28b5ef1 100644 | 2283 index 36aa999..333adfe 100644 |
| 2283 --- a/third_party/sqlite/src/src/sqlite.h.in | 2284 --- a/third_party/sqlite/src/src/sqlite.h.in |
| 2284 +++ b/third_party/sqlite/src/src/sqlite.h.in | 2285 +++ b/third_party/sqlite/src/src/sqlite.h.in |
| 2285 @@ -7408,6 +7408,17 @@ int sqlite3_vtab_on_conflict(sqlite3 *); | 2286 @@ -7408,6 +7408,22 @@ int sqlite3_vtab_on_conflict(sqlite3 *); |
| 2286 | 2287 |
| 2287 | 2288 |
| 2288 | 2289 |
| 2289 +/* Begin recover.patch for Chromium */ | 2290 +/* Begin recover virtual table patch for Chromium */ |
| 2291 +/* Our patches don't conform to SQLite's amalgamation processing. Hack it. */ |
| 2292 +#ifndef CHROMIUM_SQLITE_API |
| 2293 +#define CHROMIUM_SQLITE_API SQLITE_API |
| 2294 +#endif |
| 2290 +/* | 2295 +/* |
| 2291 +** Call to initialize the recover virtual-table modules (see recover.c). | 2296 +** Call to initialize the recover virtual-table modules (see recover.c). |
| 2292 +** | 2297 +** |
| 2293 +** This could be loaded by default in main.c, but that would make the | 2298 +** This could be loaded by default in main.c, but that would make the |
| 2294 +** virtual table available to Web SQL. Breaking it out allows only | 2299 +** virtual table available to Web SQL. Breaking it out allows only |
| 2295 +** selected users to enable it (currently sql/recovery.cc). | 2300 +** selected users to enable it (currently sql/recovery.cc). |
| 2296 +*/ | 2301 +*/ |
| 2302 +CHROMIUM_SQLITE_API |
| 2297 +int recoverVtableInit(sqlite3 *db); | 2303 +int recoverVtableInit(sqlite3 *db); |
| 2298 +/* End recover.patch for Chromium */ | 2304 +/* End recover virtual table patch for Chromium */ |
| 2299 + | 2305 + |
| 2300 /* | 2306 /* Begin WebDatabase patch for Chromium */ |
| 2301 ** Undo the hack that converts floating point types to integer for | 2307 /* Expose some SQLite internals for the WebDatabase vfs. |
| 2302 ** builds on processors without floating point support. | 2308 ** DO NOT EXTEND THE USE OF THIS. |
| 2303 diff --git a/third_party/sqlite/src/test/recover.test b/third_party/sqlite/src/t
est/recover.test | 2309 diff --git a/third_party/sqlite/src/test/recover.test b/third_party/sqlite/src/t
est/recover.test |
| 2304 new file mode 100644 | 2310 new file mode 100644 |
| 2305 index 0000000..b5aa182 | 2311 index 0000000..b5aa182 |
| 2306 --- /dev/null | 2312 --- /dev/null |
| 2307 +++ b/third_party/sqlite/src/test/recover.test | 2313 +++ b/third_party/sqlite/src/test/recover.test |
| 2308 @@ -0,0 +1,147 @@ | 2314 @@ -0,0 +1,147 @@ |
| 2309 +# 2012 January 11 {} | 2315 +# 2012 January 11 {} |
| 2310 +# | 2316 +# |
| 2311 +# The author disclaims copyright to this source code. In place of | 2317 +# The author disclaims copyright to this source code. In place of |
| 2312 +# a legal notice, here is a blessing: | 2318 +# a legal notice, here is a blessing: |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3596 @@ -316,6 +316,8 @@ foreach file { | 3602 @@ -316,6 +316,8 @@ foreach file { |
| 3597 main.c | 3603 main.c |
| 3598 notify.c | 3604 notify.c |
| 3599 | 3605 |
| 3600 + recover.c | 3606 + recover.c |
| 3601 + | 3607 + |
| 3602 fts3.c | 3608 fts3.c |
| 3603 fts3_aux.c | 3609 fts3_aux.c |
| 3604 fts3_expr.c | 3610 fts3_expr.c |
| 3605 -- | 3611 -- |
| 3606 2.2.1 | 3612 2.4.5 |
| 3607 | 3613 |
| OLD | NEW |