Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1654)

Unified Diff: app/sql/connection.h

Issue 223003: Add basic sqlite error handling to the new sqlite handlers... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | app/sql/connection.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/sql/connection.h
===================================================================
--- app/sql/connection.h (revision 27122)
+++ app/sql/connection.h (working copy)
@@ -66,6 +66,27 @@
#define SQL_FROM_HERE sql::StatementID(__FILE__, __LINE__)
+class Connection;
+
+// ErrorDelegate defines the interface to implement error handling and recovery
+// for sqlite operations. This allows the rest of the classes to return true or
+// false while the actual error code and causing statement are delivered using
+// the OnError() callback.
+// The tipical usage is to centralize the code designed to handle database
+// corruption, low-level IO errors or locking violations.
+class ErrorDelegate : public base::RefCounted<ErrorDelegate> {
+ public:
+ virtual ~ErrorDelegate() {}
+ // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h
+ // |connection| is db connection where the error happened and |stmt| is
+ // our best guess at the statement that triggered the error. Do not store
+ // these pointers.
+ // If the error condition has been fixed an the original statement succesfuly
+ // re-tried then returning SQLITE_OK is appropiate; otherwise is recomended
+ // that you return the original |error| or the appropiae error code.
+ virtual int OnError(int error, Connection* connection, Statement* stmt) = 0;
+};
+
class Connection {
private:
class StatementRef; // Forward declaration, see real one below.
@@ -104,6 +125,13 @@
// This must be called before Init() to have an effect.
void set_exclusive_locking() { exclusive_locking_ = true; }
+ // Sets the object that will handle errors. Recomended that it should be set
+ // before calling Init(). If not set, the default is to ignore errors on
+ // release and assert on debug builds.
+ void set_error_delegate(ErrorDelegate* delegate) {
+ error_delegate_ = delegate;
+ }
+
// Initialization ------------------------------------------------------------
// Initializes the SQL connection for the given file, returning true if the
@@ -278,6 +306,10 @@
// Frees all cached statements from statement_cache_.
void ClearCache();
+ // Called by Statement objects when an sqlite function returns an error.
+ // The return value is the error code reflected back to client code.
+ int OnSqliteError(int err, Statement* stmt);
+
// The actual sqlite database. Will be NULL before Init has been called or if
// Init resulted in an error.
sqlite3* db_;
@@ -308,6 +340,10 @@
// a rollback instead of a commit.
bool needs_rollback_;
+ // This object handles errors resulting from all forms of executing sqlite
+ // commands or statements. It can be null which means default handling.
+ scoped_refptr<ErrorDelegate> error_delegate_;
+
DISALLOW_COPY_AND_ASSIGN(Connection);
};
« no previous file with comments | « no previous file | app/sql/connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698