Chromium Code Reviews| Index: sql/connection.cc |
| diff --git a/sql/connection.cc b/sql/connection.cc |
| index ab84266673330e57bb24e2496743bd9f73f3948d..3a690a36adbeeb69a27bf7bad7f3c0d2badfe3c5 100644 |
| --- a/sql/connection.cc |
| +++ b/sql/connection.cc |
| @@ -243,23 +243,7 @@ bool Connection::IsExpectedSqliteError(int error) { |
| void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { |
| AssertIOAllowed(); |
| - // Trim extended error codes. |
| - const int error = (extended_error & 0xFF); |
| - std::string debug_info; |
| - if (error == SQLITE_CORRUPT) { |
| - // CollectCorruptionInfo() is implemented in terms of sql::Connection, |
| - // prevent reentrant calls to the error callback. |
| - // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite. |
| - ErrorCallback original_callback = std::move(error_callback_); |
| - reset_error_callback(); |
| - |
| - debug_info = CollectCorruptionInfo(); |
| - |
| - error_callback_ = std::move(original_callback); |
| - } else { |
| - debug_info = CollectErrorInfo(extended_error, stmt); |
| - } |
| - |
| + std::string debug_info = GetDiagnosticInfo(extended_error, stmt); |
|
afakhry
2016/07/13 19:57:59
Note that this now will return debug info that con
|
| if (!debug_info.empty() && RegisterIntentToUpload()) { |
| char debug_buf[2000]; |
| base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf)); |
| @@ -1922,6 +1906,39 @@ bool Connection::QuickIntegrityCheck() { |
| return messages.size() == 1 && messages[0] == "ok"; |
| } |
| +std::string Connection::GetDiagnosticInfo(int extended_error, |
| + Statement* statement) { |
| + std::string result; |
| + const bool has_valid_header = |
| + (ExecuteAndReturnErrorCode("PRAGMA auto_vacuum") == SQLITE_OK); |
| + const bool select_sqlite_master_result = |
| + (ExecuteAndReturnErrorCode("SELECT COUNT(*) FROM sqlite_master") == |
| + SQLITE_OK); |
| + |
| + // Trim extended error codes. |
| + const int error = (extended_error & 0xFF); |
| + if (error == SQLITE_CORRUPT) { |
| + // CollectCorruptionInfo() is implemented in terms of sql::Connection, |
| + // prevent reentrant calls to the error callback. |
| + // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite. |
| + ErrorCallback original_callback = std::move(error_callback_); |
| + reset_error_callback(); |
| + |
| + result = CollectCorruptionInfo(); |
|
afakhry
2016/07/13 19:57:59
Another question to (shess | michaeln): Should we
|
| + |
| + error_callback_ = std::move(original_callback); |
| + } else { |
| + result = CollectErrorInfo(extended_error, statement); |
| + } |
| + |
| + base::StringAppendF(&result, "Has valid header: %s\n", |
| + (has_valid_header ? "Yes" : "No")); |
| + base::StringAppendF(&result, "Has valid schema: %s\n", |
| + (select_sqlite_master_result ? "Yes" : "No")); |
| + |
| + return result; |
| +} |
| + |
| // TODO(shess): Allow specifying maximum results (default 100 lines). |
| bool Connection::IntegrityCheckHelper( |
| const char* pragma_sql, |