From 92cd00a38e3897077f365d222941eb97ebb9eac2 Mon Sep 17 00:00:00 2001 From: "shess@chromium.org" Date: Fri, 16 Aug 2013 11:09:58 +0000 Subject: Refactor clearing thumbnail history. Previously, ThumbnailDatabase exposed much internals knowledge. Push most of that down into the class and remove the schema hacks which are no longer necessary. BUG=272519 TEST=Unit tests. Review URL: https://chromiumcodereview.appspot.com/22898003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217993 0039d316-1c4b-4281-b951-d872f2087c98 --- sql/connection.cc | 23 +++++++++++++++++++++++ sql/connection.h | 5 +++++ 2 files changed, 28 insertions(+) (limited to 'sql') diff --git a/sql/connection.cc b/sql/connection.cc index 3bc2545..097edd7 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -724,6 +724,29 @@ scoped_refptr Connection::GetUntrackedStatement( return new StatementRef(NULL, stmt, true); } +std::string Connection::GetSchema() const { + // The ORDER BY should not be necessary, but relying on organic + // order for something like this is questionable. + const char* kSql = + "SELECT type, name, tbl_name, sql " + "FROM sqlite_master ORDER BY 1, 2, 3, 4"; + Statement statement(GetUntrackedStatement(kSql)); + + std::string schema; + while (statement.Step()) { + schema += statement.ColumnString(0); + schema += '|'; + schema += statement.ColumnString(1); + schema += '|'; + schema += statement.ColumnString(2); + schema += '|'; + schema += statement.ColumnString(3); + schema += '\n'; + } + + return schema; +} + bool Connection::IsSQLValid(const char* sql) { AssertIOAllowed(); if (!db_) { diff --git a/sql/connection.h b/sql/connection.h index 24f06de..7938606 100644 --- a/sql/connection.h +++ b/sql/connection.h @@ -389,6 +389,11 @@ class SQL_EXPORT Connection { // last sqlite operation. const char* GetErrorMessage() const; + // Return a reproducible representation of the schema equivalent to + // running the following statement at a sqlite3 command-line: + // SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4; + std::string GetSchema() const; + private: // For recovery module. friend class Recovery; -- cgit v1.1