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 <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "sql/connection.h" | 13 #include "sql/connection.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class FilePath; | 16 class FilePath; |
17 } | 17 } |
18 | 18 |
19 namespace sql { | 19 namespace sql { |
20 | 20 |
21 // Recovery module for sql/. The basic idea is to create a fresh database and | 21 // Recovery module for sql/. The basic idea is to create a fresh database and |
22 // populate it with the recovered contents of the original database. If | 22 // populate it with the recovered contents of the original database. If |
23 // recovery is successful, the recovered database is backed up over the original | 23 // recovery is successful, the recovered database is backed up over the original |
24 // database. If recovery is not successful, the original database is razed. In | 24 // database. If recovery is not successful, the original database is razed. In |
25 // either case, the original handle is poisoned so that operations on the stack | 25 // either case, the original handle is poisoned so that operations on the stack |
26 // do not accidentally disrupt the restored data. | 26 // do not accidentally disrupt the restored data. |
27 // | 27 // |
28 // RecoverDatabaseOrRaze() automates this, including recoverying the schema of | 28 // RecoverDatabase() automates this, including recoverying the schema of from |
29 // from the suspect database. If a database requires special handling, such as | 29 // the suspect database. If a database requires special handling, such as |
30 // recovering between different schema, or tables requiring post-processing, | 30 // recovering between different schema, or tables requiring post-processing, |
31 // then the module can be used manually like: | 31 // then the module can be used manually like: |
32 // | 32 // |
33 // { | 33 // { |
34 // std::unique_ptr<sql::Recovery> r = | 34 // std::unique_ptr<sql::Recovery> r = |
35 // sql::Recovery::Begin(orig_db, orig_db_path); | 35 // sql::Recovery::Begin(orig_db, orig_db_path); |
36 // if (r) { | 36 // if (r) { |
37 // // Create the schema to recover to. On failure, clear the | 37 // // Create the schema to recover to. On failure, clear the |
38 // // database. | 38 // // database. |
39 // if (!r.db()->Execute(kCreateSchemaSql)) { | 39 // if (!r.db()->Execute(kCreateSchemaSql)) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 Connection* db_; // Original database connection. | 195 Connection* db_; // Original database connection. |
196 Connection recover_db_; // Recovery connection. | 196 Connection recover_db_; // Recovery connection. |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(Recovery); | 198 DISALLOW_COPY_AND_ASSIGN(Recovery); |
199 }; | 199 }; |
200 | 200 |
201 } // namespace sql | 201 } // namespace sql |
202 | 202 |
203 #endif // SQL_RECOVERY_H_ | 203 #endif // SQL_RECOVERY_H_ |
OLD | NEW |