Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 recover_db_.Close(); | 342 recover_db_.Close(); |
| 343 if (raze == RAZE_AND_POISON) { | 343 if (raze == RAZE_AND_POISON) { |
| 344 db_->RazeAndClose(); | 344 db_->RazeAndClose(); |
| 345 } else if (raze == POISON) { | 345 } else if (raze == POISON) { |
| 346 db_->Poison(); | 346 db_->Poison(); |
| 347 } | 347 } |
| 348 db_ = NULL; | 348 db_ = NULL; |
| 349 } | 349 } |
| 350 | 350 |
| 351 bool Recovery::AutoRecoverTable(const char* table_name, | 351 bool Recovery::AutoRecoverTable(const char* table_name, |
| 352 size_t extend_columns, | |
| 353 size_t* rows_recovered) { | 352 size_t* rows_recovered) { |
| 354 // Query the info for the recovered table in database [main]. | 353 // Query the info for the recovered table in database [main]. |
| 355 std::string query( | 354 std::string query( |
| 356 base::StringPrintf("PRAGMA main.table_info(%s)", table_name)); | 355 base::StringPrintf("PRAGMA main.table_info(%s)", table_name)); |
| 357 Statement s(db()->GetUniqueStatement(query.c_str())); | 356 Statement s(db()->GetUniqueStatement(query.c_str())); |
| 358 | 357 |
| 359 // The columns of the recover virtual table. | 358 // The columns of the recover virtual table. |
| 360 std::vector<std::string> create_column_decls; | 359 std::vector<std::string> create_column_decls; |
| 361 | 360 |
| 362 // The columns to select from the recover virtual table when copying | 361 // The columns to select from the recover virtual table when copying |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 // Receiving no column information implies that the table doesn't exist. | 451 // Receiving no column information implies that the table doesn't exist. |
| 453 if (create_column_decls.empty()) { | 452 if (create_column_decls.empty()) { |
| 454 RecordRecoveryEvent(RECOVERY_FAILED_AUTORECOVER_MISSING_TABLE); | 453 RecordRecoveryEvent(RECOVERY_FAILED_AUTORECOVER_MISSING_TABLE); |
| 455 return false; | 454 return false; |
| 456 } | 455 } |
| 457 | 456 |
| 458 // If the PRIMARY KEY was a single INTEGER column, convert it to ROWID. | 457 // If the PRIMARY KEY was a single INTEGER column, convert it to ROWID. |
| 459 if (pk_column_count == 1 && !rowid_decl.empty()) | 458 if (pk_column_count == 1 && !rowid_decl.empty()) |
| 460 create_column_decls[rowid_ofs] = rowid_decl; | 459 create_column_decls[rowid_ofs] = rowid_decl; |
| 461 | 460 |
| 462 // Additional columns accept anything. | |
| 463 // TODO(shess): ignoreN isn't well namespaced. But it will fail to | |
| 464 // execute in case of conflicts. | |
| 465 for (size_t i = 0; i < extend_columns; ++i) { | |
| 466 create_column_decls.push_back( | |
| 467 base::StringPrintf("ignore%" PRIuS " ANY", i)); | |
| 468 } | |
|
Scott Hess - ex-Googler
2016/02/03 20:36:18
Summary of "why": Recovery works by defining a vir
Ryan Hamilton
2016/02/04 01:36:34
Cute!
Scott Hess - ex-Googler
2016/02/04 18:39:59
I was prototyping an alternative recovery method w
| |
| 469 | |
| 470 std::string recover_create(base::StringPrintf( | 461 std::string recover_create(base::StringPrintf( |
| 471 "CREATE VIRTUAL TABLE temp.recover_%s USING recover(corrupt.%s, %s)", | 462 "CREATE VIRTUAL TABLE temp.recover_%s USING recover(corrupt.%s, %s)", |
| 472 table_name, | 463 table_name, |
| 473 table_name, | 464 table_name, |
| 474 base::JoinString(create_column_decls, ",").c_str())); | 465 base::JoinString(create_column_decls, ",").c_str())); |
| 475 | 466 |
| 476 std::string recover_insert(base::StringPrintf( | 467 std::string recover_insert(base::StringPrintf( |
| 477 "INSERT OR REPLACE INTO main.%s SELECT %s FROM temp.recover_%s", | 468 "INSERT OR REPLACE INTO main.%s SELECT %s FROM temp.recover_%s", |
| 478 table_name, | 469 table_name, |
| 479 base::JoinString(insert_columns, ",").c_str(), | 470 base::JoinString(insert_columns, ",").c_str(), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 } | 528 } |
| 538 return false; | 529 return false; |
| 539 } | 530 } |
| 540 | 531 |
| 541 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION); | 532 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION); |
| 542 *version = recovery_version.ColumnInt(0); | 533 *version = recovery_version.ColumnInt(0); |
| 543 return true; | 534 return true; |
| 544 } | 535 } |
| 545 | 536 |
| 546 } // namespace sql | 537 } // namespace sql |
| OLD | NEW |