OLD | NEW |
1 From 13a64d3c7fb541be8cb753c575837c1b84f5d9fd Mon Sep 17 00:00:00 2001 | 1 From 13a64d3c7fb541be8cb753c575837c1b84f5d9fd 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/16] 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 |
(...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 +static int recoverColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
{ | 1884 +static int recoverColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i)
{ |
1885 + RecoverCursor *pCursor = (RecoverCursor*)cur; | 1885 + RecoverCursor *pCursor = (RecoverCursor*)cur; |
1886 + Recover *pRecover = (Recover*)pCursor->base.pVtab; | 1886 + Recover *pRecover = (Recover*)pCursor->base.pVtab; |
1887 + u64 iColType; /* Storage type of column i. */ | 1887 + u64 iColType; /* Storage type of column i. */ |
1888 + unsigned char *pColData; /* Column i's data. */ | 1888 + unsigned char *pColData; /* Column i's data. */ |
1889 + int shouldFree; /* Non-zero if pColData should be freed. */ | 1889 + int shouldFree; /* Non-zero if pColData should be freed. */ |
1890 + int rc; | 1890 + int rc; |
1891 + | 1891 + |
1892 + FNENTRY(); | 1892 + FNENTRY(); |
1893 + | 1893 + |
1894 + if( i>=pRecover->nCols ){ | 1894 + if( (unsigned)i>=pRecover->nCols ){ |
1895 + return SQLITE_ERROR; | 1895 + return SQLITE_ERROR; |
1896 + } | 1896 + } |
1897 + | 1897 + |
1898 + /* ROWID alias. */ | 1898 + /* ROWID alias. */ |
1899 + if( (pRecover->pTypes[i]&MASK_ROWID) ){ | 1899 + if( (pRecover->pTypes[i]&MASK_ROWID) ){ |
1900 + sqlite3_result_int64(ctx, leafCursorCellRowid(pCursor->pLeafCursor)); | 1900 + sqlite3_result_int64(ctx, leafCursorCellRowid(pCursor->pLeafCursor)); |
1901 + return SQLITE_OK; | 1901 + return SQLITE_OK; |
1902 + } | 1902 + } |
1903 + | 1903 + |
1904 + pColData = NULL; | 1904 + pColData = NULL; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 + * recoverCreate(). | 2191 + * recoverCreate(). |
2192 + */ | 2192 + */ |
2193 +/* TODO(shess): Explore cases where it would make sense to set *pzErr. */ | 2193 +/* TODO(shess): Explore cases where it would make sense to set *pzErr. */ |
2194 +static int recoverInit( | 2194 +static int recoverInit( |
2195 + sqlite3 *db, /* Database connection */ | 2195 + sqlite3 *db, /* Database connection */ |
2196 + void *pAux, /* unused */ | 2196 + void *pAux, /* unused */ |
2197 + int argc, const char *const*argv, /* Parameters to CREATE TABLE statement *
/ | 2197 + int argc, const char *const*argv, /* Parameters to CREATE TABLE statement *
/ |
2198 + sqlite3_vtab **ppVtab, /* OUT: New virtual table */ | 2198 + sqlite3_vtab **ppVtab, /* OUT: New virtual table */ |
2199 + char **pzErr /* OUT: Error message, if any */ | 2199 + char **pzErr /* OUT: Error message, if any */ |
2200 +){ | 2200 +){ |
2201 + const unsigned kTypeCol = 4; /* First argument with column type info. */ | 2201 + const int kTypeCol = 4; /* First argument with column type info. */ |
2202 + Recover *pRecover; /* Virtual table structure being created. */ | 2202 + Recover *pRecover; /* Virtual table structure being created. */ |
2203 + char *zDot; /* Any dot found in "db.table" backing. */ | 2203 + char *zDot; /* Any dot found in "db.table" backing. */ |
2204 + u32 iRootPage; /* Root page of backing table. */ | 2204 + u32 iRootPage; /* Root page of backing table. */ |
2205 + char *zCreateSql; /* Schema of created virtual table. */ | 2205 + char *zCreateSql; /* Schema of created virtual table. */ |
2206 + int rc; | 2206 + int rc; |
2207 + | 2207 + |
2208 + /* Require to be in the temp database. */ | 2208 + /* Require to be in the temp database. */ |
2209 + if( ascii_strcasecmp(argv[1], "temp")!=0 ){ | 2209 + if( ascii_strcasecmp(argv[1], "temp")!=0 ){ |
2210 + *pzErr = sqlite3_mprintf("recover table must be in temp database"); | 2210 + *pzErr = sqlite3_mprintf("recover table must be in temp database"); |
2211 + return SQLITE_MISUSE; | 2211 + return SQLITE_MISUSE; |
2212 + } | 2212 + } |
2213 + | 2213 + |
2214 + /* Need the backing table and at least one column. */ | 2214 + /* Need the backing table and at least one column. */ |
2215 + if( argc<=kTypeCol ){ | 2215 + if( argc<=kTypeCol ){ |
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3598 notify.c | 3598 notify.c |
3599 | 3599 |
3600 + recover.c | 3600 + recover.c |
3601 + | 3601 + |
3602 fts3.c | 3602 fts3.c |
3603 fts3_aux.c | 3603 fts3_aux.c |
3604 fts3_expr.c | 3604 fts3_expr.c |
3605 -- | 3605 -- |
3606 2.2.1 | 3606 2.2.1 |
3607 | 3607 |
OLD | NEW |