Chromium Code Reviews| Index: sql/connection.cc |
| diff --git a/sql/connection.cc b/sql/connection.cc |
| index ab84266673330e57bb24e2496743bd9f73f3948d..a566843f8489211bd60b34ab54d3943e62248120 100644 |
| --- a/sql/connection.cc |
| +++ b/sql/connection.cc |
| @@ -1922,6 +1922,40 @@ 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); |
| + result["Has valid header"] = has_valid_header ? "Yes" : "No"; |
| + const bool select_sqlite_master_result = |
| + (ExecuteAndReturnErrorCode("SELECT COUNT(*) FROM sqlite_master") == |
| + SQLITE_OK); |
| + result["\"SELECT COUNT(*) FROM sqlite_master\" succeeds"] = |
| + select_sqlite_master_result ? "Yes" : "No"; |
|
Scott Hess - ex-Googler
2016/07/10 05:16:52
Gross. You're running the SELECT to determine som
afakhry
2016/07/11 16:47:46
That's because I didn't know what that statement d
Scott Hess - ex-Googler
2016/07/13 01:18:46
Do you expect the master table to not exist?
Earl
afakhry
2016/07/13 19:57:58
Well, I'm not the sql expert here, so I don't know
|
| + |
| + // 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) { |
|
michaeln
2016/07/12 20:05:32
instead of dropping errors on the floor with a Nul
afakhry
2016/07/13 19:57:58
Done. I'm actually using the same code in Connecti
|
| + std::vector<std::string> integrity_check_output; |
| + if (FullIntegrityCheck(&integrity_check_output)) { |
| + integrity_check_result = ""; |
| + for (const auto& line : integrity_check_output) |
|
michaeln
2016/07/09 03:00:38
The output is uninteresting in the success case, i
afakhry
2016/07/11 16:47:45
Done.
|
| + integrity_check_result += line + "\n"; |
| + |
| + // we can only get the schema if the integrity check passes. |
| + schema = GetSchema(); |
| + } |
| + } |
| + |
| + result["Integrity check"] = integrity_check_result; |
| + result["Schema"] = schema; |
|
michaeln
2016/07/09 03:00:38
nit: for readability, might be nice to set all fou
Scott Hess - ex-Googler
2016/07/10 05:16:52
Note that |schema| and the integrity check results
afakhry
2016/07/11 16:47:45
Done.
afakhry
2016/07/11 16:47:46
For the integrity check, multilines are handled ab
michaeln
2016/07/12 20:05:32
i think i'd vote for a basic string too, i don't t
Scott Hess - ex-Googler
2016/07/13 01:18:46
IMHO having callers depend on keys would be really
Scott Hess - ex-Googler
2016/07/13 01:18:46
Multilines are handled above by injecting newlines
afakhry
2016/07/13 19:57:58
Done. Using a string now.
afakhry
2016/07/13 19:57:58
Now I'm using whatever CollectCorruptionInfo() or
afakhry
2016/07/13 19:57:58
Done.
afakhry
2016/07/13 19:57:58
Agreed, formatting is not really the primary conce
|
| + |
| + return result; |
| +} |
| + |
| // TODO(shess): Allow specifying maximum results (default 100 lines). |
| bool Connection::IntegrityCheckHelper( |
| const char* pragma_sql, |