Index: sql/connection.cc |
diff --git a/sql/connection.cc b/sql/connection.cc |
index ab84266673330e57bb24e2496743bd9f73f3948d..929fa7548f41ab0b0bb5bb9ca124c57f75103886 100644 |
--- a/sql/connection.cc |
+++ b/sql/connection.cc |
@@ -1922,6 +1922,38 @@ bool Connection::QuickIntegrityCheck() { |
return messages.size() == 1 && messages[0] == "ok"; |
} |
+sql::DatabaseDiagnosticMap Connection::GetDiagnosticMap() { |
+ sql::DatabaseDiagnosticMap 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); |
+ |
+ // If any of the above failed, that's an indication that the file is really |
+ // corrupted. Doing the integrity check or getting the schema will crash on |
+ // DCHECKs on debug builds. |
+ std::string integrity_check_result("Failed"); |
+ std::string schema("Failed"); |
+ if (has_valid_header && select_sqlite_master_result) { |
+ std::vector<std::string> integrity_check_output; |
+ if (FullIntegrityCheck(&integrity_check_output)) { |
+ // we can only get the schema if the integrity check passes. |
+ integrity_check_result = "Success"; |
+ schema = GetSchema(); |
+ } |
+ for (const auto& line : integrity_check_output) |
+ integrity_check_result += "\n\t" + line; |
+ } |
+ |
+ result["Has valid header"] = has_valid_header ? "Yes" : "No"; |
+ result["Master table exists"] = select_sqlite_master_result ? "Yes" : "No"; |
+ result["Integrity check"] = integrity_check_result; |
+ result["Schema"] = schema; |
+ |
+ return result; |
+} |
+ |
// TODO(shess): Allow specifying maximum results (default 100 lines). |
bool Connection::IntegrityCheckHelper( |
const char* pragma_sql, |