Implement sql::Connection::Raze() in terms of sqlite3_backup API.
Wraps up the notion of reseting a database in a way which respects
SQLite locking constraints and doesn't require closing the database.
A similar outcome could be managed using filesystem operations, which
requires coordination between clients of the database to make sure
that no corruption occurs due to incorrect handling of -journal files.
Also, Windows pins files until the last handle closes, making that
approach challenging in some cases.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9768006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131167 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/sql/connection.h b/sql/connection.h
index 9b81804b..1e3414f4 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -181,6 +181,26 @@
// generally exist either.
void Preload();
+ // Raze the database to the ground. This approximates creating a
+ // fresh database from scratch, within the constraints of SQLite's
+ // locking protocol (locks and open handles can make doing this with
+ // filesystem operations problematic). Returns true if the database
+ // was razed.
+ //
+ // false is returned if the database is locked by some other
+ // process. RazeWithTimeout() may be used if appropriate.
+ //
+ // NOTE(shess): Raze() will DCHECK in the following situations:
+ // - database is not open.
+ // - the connection has a transaction open.
+ // - a SQLite issue occurs which is structural in nature (like the
+ // statements used are broken).
+ // Since Raze() is expected to be called in unexpected situations,
+ // these all return false, since it is unlikely that the caller
+ // could fix them.
+ bool Raze();
+ bool RazeWithTimout(base::TimeDelta timeout);
+
// Transactions --------------------------------------------------------------
// Transaction management. We maintain a virtual transaction stack to emulate