summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-14 04:09:12 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-14 04:09:12 +0000
commit526b466671fc03ee6592c78a77f194c78122dcd2 (patch)
tree8e3c243c621a13aa59561681e8be7d5abe7c3326 /sql
parentc090470d08860b16f56773c1b198e2ce24e6c907 (diff)
downloadchromium_src-526b466671fc03ee6592c78a77f194c78122dcd2.zip
chromium_src-526b466671fc03ee6592c78a77f194c78122dcd2.tar.gz
chromium_src-526b466671fc03ee6592c78a77f194c78122dcd2.tar.bz2
Remove sql::ErrorDelegate.
API cleanup. Replaced by ErrorCallback. BUG=none Review URL: https://chromiumcodereview.appspot.com/16788002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/connection.cc11
-rw-r--r--sql/connection.h45
-rw-r--r--sql/sqlite_features_unittest.cc32
-rw-r--r--sql/statement_unittest.cc32
4 files changed, 20 insertions, 100 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index dd71563..510d6a7 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -74,9 +74,6 @@ bool StatementID::operator<(const StatementID& other) const {
return strcmp(str_, other.str_) < 0;
}
-ErrorDelegate::~ErrorDelegate() {
-}
-
Connection::StatementRef::StatementRef(Connection* connection,
sqlite3_stmt* stmt,
bool was_valid)
@@ -122,7 +119,8 @@ Connection::Connection()
transaction_nesting_(0),
needs_rollback_(false),
in_memory_(false),
- poisoned_(false) {}
+ poisoned_(false) {
+}
Connection::~Connection() {
Close();
@@ -762,11 +760,6 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) {
return err;
}
- // TODO(shess): Remove |error_delegate_| once everything is
- // converted to |error_callback_|.
- if (error_delegate_.get())
- return error_delegate_->OnError(err, this, stmt);
-
// The default handling is to assert on debug and to ignore on release.
DLOG(FATAL) << GetErrorMessage();
return err;
diff --git a/sql/connection.h b/sql/connection.h
index 049d7cf..8db794d 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -78,30 +78,6 @@ class StatementID {
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 SQL_EXPORT ErrorDelegate {
- public:
- virtual ~ErrorDelegate();
-
- // |error| is an sqlite result code as seen in sqlite3.h. |connection| is the
- // db connection where the error happened and |stmt| is our best guess at the
- // statement that triggered the error. Do not store these pointers.
- //
- // |stmt| MAY BE NULL if there is no statement causing the problem (i.e. on
- // initialization).
- //
- // If the error condition has been fixed and the original statement succesfuly
- // re-tried then returning SQLITE_OK is appropriate; otherwise it is
- // recommended that you return the original |error| or the appropriate error
- // code.
- virtual int OnError(int error, Connection* connection, Statement* stmt) = 0;
-};
-
class SQL_EXPORT Connection {
private:
class StatementRef; // Forward declaration, see real one below.
@@ -145,14 +121,6 @@ class SQL_EXPORT Connection {
//
// If no callback is set, the default action is to crash in debug
// mode or return failure in release mode.
- //
- // TODO(shess): ErrorDelegate allowed for returning a different
- // error. Determine if this is necessary for the callback. In my
- // experience, this is not well-tested and probably not safe, and
- // current clients always return the same error passed.
- // Additionally, most errors don't admit to a clean way to retry the
- // failed operation, so converting an error to SQLITE_OK is probably
- // not feasible.
typedef base::Callback<void(int, Statement*)> ErrorCallback;
void set_error_callback(const ErrorCallback& callback) {
error_callback_ = callback;
@@ -161,15 +129,6 @@ class SQL_EXPORT Connection {
error_callback_.Reset();
}
- // Sets the object that will handle errors. Recomended that it should be set
- // before calling Open(). If not set, the default is to ignore errors on
- // release and assert on debug builds.
- // Takes ownership of |delegate|.
- // NOTE(shess): Deprecated, use set_error_callback().
- void set_error_delegate(ErrorDelegate* delegate) {
- error_delegate_.reset(delegate);
- }
-
// Set this tag to enable additional connection-type histogramming
// for SQLite error codes and database version numbers.
void set_histogram_tag(const std::string& tag) {
@@ -529,10 +488,6 @@ class SQL_EXPORT Connection {
ErrorCallback error_callback_;
- // This object handles errors resulting from all forms of executing sqlite
- // commands or statements. It can be null which means default handling.
- scoped_ptr<ErrorDelegate> error_delegate_;
-
// Tag for auxiliary histograms.
std::string histogram_tag_;
diff --git a/sql/sqlite_features_unittest.cc b/sql/sqlite_features_unittest.cc
index 2f6a49e..4fc730c 100644
--- a/sql/sqlite_features_unittest.cc
+++ b/sql/sqlite_features_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "sql/connection.h"
@@ -15,28 +16,12 @@
namespace {
-class StatementErrorHandler : public sql::ErrorDelegate {
- public:
- StatementErrorHandler(int* error, std::string* sql_text)
- : error_(error),
- sql_text_(sql_text) {}
-
- virtual ~StatementErrorHandler() {}
-
- virtual int OnError(int error, sql::Connection* connection,
- sql::Statement* stmt) OVERRIDE {
- *error_ = error;
- const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
- *sql_text_ = sql_txt ? sql_txt : "no statement available";
- return error;
- }
-
- private:
- int* error_;
- std::string* sql_text_;
-
- DISALLOW_COPY_AND_ASSIGN(StatementErrorHandler);
-};
+void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
+ int error, sql::Statement* stmt) {
+ *error_pointer = error;
+ const char* text = stmt ? stmt->GetSQLStatement() : NULL;
+ *sql_text = text ? text : "no statement available";
+}
class SQLiteFeaturesTest : public testing::Test {
public:
@@ -48,7 +33,8 @@ class SQLiteFeaturesTest : public testing::Test {
// The error delegate will set |error_| and |sql_text_| when any sqlite
// statement operation returns an error code.
- db_.set_error_delegate(new StatementErrorHandler(&error_, &sql_text_));
+ db_.set_error_callback(base::Bind(&CaptureErrorCallback,
+ &error_, &sql_text_));
}
virtual void TearDown() {
diff --git a/sql/statement_unittest.cc b/sql/statement_unittest.cc
index ffa8aef..3d32862 100644
--- a/sql/statement_unittest.cc
+++ b/sql/statement_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "sql/connection.h"
@@ -13,28 +14,12 @@
namespace {
-class StatementErrorHandler : public sql::ErrorDelegate {
- public:
- StatementErrorHandler(int* error, std::string* sql_text)
- : error_(error),
- sql_text_(sql_text) {}
-
- virtual ~StatementErrorHandler() {}
-
- virtual int OnError(int error, sql::Connection* connection,
- sql::Statement* stmt) OVERRIDE {
- *error_ = error;
- const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
- *sql_text_ = sql_txt ? sql_txt : "no statement available";
- return error;
- }
-
- private:
- int* error_;
- std::string* sql_text_;
-
- DISALLOW_COPY_AND_ASSIGN(StatementErrorHandler);
-};
+void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
+ int error, sql::Statement* stmt) {
+ *error_pointer = error;
+ const char* text = stmt ? stmt->GetSQLStatement() : NULL;
+ *sql_text = text ? text : "no statement available";
+}
class SQLStatementTest : public testing::Test {
public:
@@ -45,7 +30,8 @@ class SQLStatementTest : public testing::Test {
ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
// The error delegate will set |error_| and |sql_text_| when any sqlite
// statement operation returns an error code.
- db_.set_error_delegate(new StatementErrorHandler(&error_, &sql_text_));
+ db_.set_error_callback(base::Bind(&CaptureErrorCallback,
+ &error_, &sql_text_));
}
virtual void TearDown() {