| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SQL_RECOVERY_H_ | 5 #ifndef SQL_RECOVERY_H_ |
| 6 #define SQL_RECOVERY_H_ | 6 #define SQL_RECOVERY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 // Handle to the temporary recovery database. | 112 // Handle to the temporary recovery database. |
| 113 sql::Connection* db() { return &recover_db_; } | 113 sql::Connection* db() { return &recover_db_; } |
| 114 | 114 |
| 115 // Attempt to recover the named table from the corrupt database into | 115 // Attempt to recover the named table from the corrupt database into |
| 116 // the recovery database using a temporary recover virtual table. | 116 // the recovery database using a temporary recover virtual table. |
| 117 // The virtual table schema is derived from the named table's schema | 117 // The virtual table schema is derived from the named table's schema |
| 118 // in database [main]. Data is copied using INSERT OR REPLACE, so | 118 // in database [main]. Data is copied using INSERT OR REPLACE, so |
| 119 // duplicates overwrite each other. | 119 // duplicates overwrite each other. |
| 120 // | 120 // |
| 121 // |extend_columns| allows recovering tables which have excess | 121 // If the source table has fewer columns than the target, the target |
| 122 // columns relative to the target schema. The recover virtual table | 122 // DEFAULT value will be used for those columns. |
| 123 // treats more data than specified as a sign of corruption. | |
| 124 // | 123 // |
| 125 // Returns true if all operations succeeded, with the number of rows | 124 // Returns true if all operations succeeded, with the number of rows |
| 126 // recovered in |*rows_recovered|. | 125 // recovered in |*rows_recovered|. |
| 127 // | 126 // |
| 128 // NOTE(shess): Due to a flaw in the recovery virtual table, at this | 127 // NOTE(shess): Due to a flaw in the recovery virtual table, at this |
| 129 // time this code injects the DEFAULT value of the target table in | 128 // time this code injects the DEFAULT value of the target table in |
| 130 // locations where the recovery table returns NULL. This is not | 129 // locations where the recovery table returns NULL. This is not |
| 131 // entirely correct, because it happens both when there is a short | 130 // entirely correct, because it happens both when there is a short |
| 132 // row (correct) but also where there is an actual NULL value | 131 // row (correct) but also where there is an actual NULL value |
| 133 // (incorrect). | 132 // (incorrect). |
| 134 // | 133 // |
| 135 // TODO(shess): Flag for INSERT OR REPLACE vs IGNORE. | 134 // TODO(shess): Flag for INSERT OR REPLACE vs IGNORE. |
| 136 // TODO(shess): Handle extended table names. | 135 // TODO(shess): Handle extended table names. |
| 137 bool AutoRecoverTable(const char* table_name, | 136 bool AutoRecoverTable(const char* table_name, size_t* rows_recovered); |
| 138 size_t extend_columns, | |
| 139 size_t* rows_recovered); | |
| 140 | 137 |
| 141 // Setup a recover virtual table at temp.recover_meta, reading from | 138 // Setup a recover virtual table at temp.recover_meta, reading from |
| 142 // corrupt.meta. Returns true if created. | 139 // corrupt.meta. Returns true if created. |
| 143 // TODO(shess): Perhaps integrate into Begin(). | 140 // TODO(shess): Perhaps integrate into Begin(). |
| 144 // TODO(shess): Add helpers to fetch additional items from the meta | 141 // TODO(shess): Add helpers to fetch additional items from the meta |
| 145 // table as needed. | 142 // table as needed. |
| 146 bool SetupMeta(); | 143 bool SetupMeta(); |
| 147 | 144 |
| 148 // Fetch the version number from temp.recover_meta. Returns false | 145 // Fetch the version number from temp.recover_meta. Returns false |
| 149 // if the query fails, or if there is no version row. Otherwise | 146 // if the query fails, or if there is no version row. Otherwise |
| (...skipping 23 matching lines...) Expand all Loading... |
| 173 | 170 |
| 174 Connection* db_; // Original database connection. | 171 Connection* db_; // Original database connection. |
| 175 Connection recover_db_; // Recovery connection. | 172 Connection recover_db_; // Recovery connection. |
| 176 | 173 |
| 177 DISALLOW_COPY_AND_ASSIGN(Recovery); | 174 DISALLOW_COPY_AND_ASSIGN(Recovery); |
| 178 }; | 175 }; |
| 179 | 176 |
| 180 } // namespace sql | 177 } // namespace sql |
| 181 | 178 |
| 182 #endif // SQL_RECOVERY_H_ | 179 #endif // SQL_RECOVERY_H_ |
| OLD | NEW |