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 #include "sql/recovery.h" | 5 #include "sql/recovery.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
10 #include "sql/connection.h" | 10 #include "sql/connection.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // within the transaction context, because it would potentially | 65 // within the transaction context, because it would potentially |
66 // preserve any in-flight changes. Unfortunately, any attach-based | 66 // preserve any in-flight changes. Unfortunately, any attach-based |
67 // system could not handle that. A system which manually queried | 67 // system could not handle that. A system which manually queried |
68 // one database and stored to the other possibly could, but would be | 68 // one database and stored to the other possibly could, but would be |
69 // more complicated. | 69 // more complicated. |
70 db_->RollbackAllTransactions(); | 70 db_->RollbackAllTransactions(); |
71 | 71 |
72 if (!recover_db_.OpenTemporary()) | 72 if (!recover_db_.OpenTemporary()) |
73 return false; | 73 return false; |
74 | 74 |
| 75 // TODO(shess): Figure out a story for USE_SYSTEM_SQLITE. The |
| 76 // virtual table implementation relies on SQLite internals for some |
| 77 // types and functions, which could be copied inline to make it |
| 78 // standalone. Or an alternate implementation could try to read |
| 79 // through errors entirely at the SQLite level. |
| 80 // |
| 81 // For now, defer to the caller. The setup will succeed, but the |
| 82 // later CREATE VIRTUAL TABLE call will fail, at which point the |
| 83 // caller can fire Unrecoverable(). |
| 84 #if !defined(USE_SYSTEM_SQLITE) |
| 85 int rc = recoverVtableInit(recover_db_.db_); |
| 86 if (rc != SQLITE_OK) { |
| 87 LOG(ERROR) << "Failed to initialize recover module: " |
| 88 << recover_db_.GetErrorMessage(); |
| 89 return false; |
| 90 } |
| 91 #endif |
| 92 |
75 // Turn on |SQLITE_RecoveryMode| for the handle, which allows | 93 // Turn on |SQLITE_RecoveryMode| for the handle, which allows |
76 // reading certain broken databases. | 94 // reading certain broken databases. |
77 if (!recover_db_.Execute("PRAGMA writable_schema=1")) | 95 if (!recover_db_.Execute("PRAGMA writable_schema=1")) |
78 return false; | 96 return false; |
79 | 97 |
80 if (!recover_db_.AttachDatabase(db_path, "corrupt")) | 98 if (!recover_db_.AttachDatabase(db_path, "corrupt")) |
81 return false; | 99 return false; |
82 | 100 |
83 return true; | 101 return true; |
84 } | 102 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 recover_db_.Close(); | 198 recover_db_.Close(); |
181 if (raze == RAZE_AND_POISON) { | 199 if (raze == RAZE_AND_POISON) { |
182 db_->RazeAndClose(); | 200 db_->RazeAndClose(); |
183 } else if (raze == POISON) { | 201 } else if (raze == POISON) { |
184 db_->Poison(); | 202 db_->Poison(); |
185 } | 203 } |
186 db_ = NULL; | 204 db_ = NULL; |
187 } | 205 } |
188 | 206 |
189 } // namespace sql | 207 } // namespace sql |
OLD | NEW |