diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-22 12:42:42 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-22 12:42:42 +0000 |
commit | 80abf155a940e0276c58e7b29f9c7d293dca4847 (patch) | |
tree | 5c698b843dd6aa6c9f7b3b19ff46a5be4ac5ff2d /sql | |
parent | 8812e3d07c527b8fd43e4bb27b6a4c886bb888b5 (diff) | |
download | chromium_src-80abf155a940e0276c58e7b29f9c7d293dca4847.zip chromium_src-80abf155a940e0276c58e7b29f9c7d293dca4847.tar.gz chromium_src-80abf155a940e0276c58e7b29f9c7d293dca4847.tar.bz2 |
Post integrity_check data for corrupt thumbnail databases.
Analyzing the results from DatabaseErrorCallback() show a lot of
SQLITE_CORRUPT opening the database and setting up the meta table.
Add additional diagnostic information for these cases to direct future
development, and also dial down the amount of data uploaded to allow
finding other cases more easily.
For SQLITE_CORRUPT and SQLITE_READONLY, only give the chance to report
on first encounter. Cross-platform results are inconsistent. On OSX,
almost all of the SQLITE_CORRUPT cases are in initialization, whereas
on Windows there are more in code which updates the database. For
these errors, it is reasonable to expect any future call to return the
error again, so it is pointless to let it get multiple attempts.
BUG=240396
Review URL: https://chromiumcodereview.appspot.com/15327004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 19 | ||||
-rw-r--r-- | sql/connection.h | 7 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index b3af75e..09d8195 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -13,6 +13,7 @@ #include "base/metrics/sparse_histogram.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/strings/string_split.h" #include "base/utf_string_conversions.h" #include "sql/statement.h" #include "third_party/sqlite/sqlite3.h" @@ -766,4 +767,22 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) { return err; } +// TODO(shess): Allow specifying integrity_check versus quick_check. +// TODO(shess): Allow specifying maximum results (default 100 lines). +bool Connection::IntegrityCheck(std::vector<std::string>* messages) { + const char kSql[] = "PRAGMA integrity_check"; + sql::Statement stmt(GetUniqueStatement(kSql)); + + messages->clear(); + + // The pragma appears to return all results (up to 100 by default) + // as a single string. This doesn't appear to be an API contract, + // it could return separate lines, so loop _and_ split. + while (stmt.Step()) { + std::string result(stmt.ColumnString(0)); + base::SplitString(result, '\n', messages); + } + return stmt.Succeeded(); +} + } // namespace sql diff --git a/sql/connection.h b/sql/connection.h index 96312c4..049d7cf 100644 --- a/sql/connection.h +++ b/sql/connection.h @@ -8,6 +8,7 @@ #include <map> #include <set> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/callback.h" @@ -180,6 +181,12 @@ class SQL_EXPORT Connection { // histogram is recorded. void AddTaggedHistogram(const std::string& name, size_t sample) const; + // Run "PRAGMA integrity_check" and post each line of results into + // |messages|. Returns the success of running the statement - per + // the SQLite documentation, if no errors are found the call should + // succeed, and a single value "ok" should be in messages. + bool IntegrityCheck(std::vector<std::string>* messages); + // Initialization ------------------------------------------------------------ // Initializes the SQL connection for the given file, returning true if the |