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

Unified Diff: sql/connection.cc

Issue 16664005: [sql] Framework for allowing tests to handle errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor along lines of comment #4. Created 7 years, 6 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 | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | sql/sql.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection.cc
diff --git a/sql/connection.cc b/sql/connection.cc
index 4eb060b879a9fb1683ae77f1a865b600315245a8..73fb6846e0ea4ecfedf456abf40afe75e8911e7c 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -68,6 +68,27 @@ class ScopedWritableSchema {
namespace sql {
+// static
+Connection::ErrorIgnorerCallback Connection::current_ignorer_cb_;
+
+// static
+bool Connection::ShouldIgnore(int error) {
+ if (current_ignorer_cb_.is_null())
+ return false;
+ return current_ignorer_cb_.Run(error);
+}
+
+// static
+void Connection::SetErrorIgnorer(const Connection::ErrorIgnorerCallback& cb) {
+ CHECK(current_ignorer_cb_.is_null());
+ current_ignorer_cb_ = cb;
+}
+
+// static
+void Connection::ResetErrorIgnorer() {
+ current_ignorer_cb_.Reset();
+}
+
bool StatementID::operator<(const StatementID& other) const {
if (number_ != other.number_)
return number_ < other.number_;
@@ -440,6 +461,7 @@ bool Connection::Execute(const char* sql) {
// This needs to be a FATAL log because the error case of arriving here is
// that there's a malformed SQL statement. This can arise in development if
// a change alters the schema but not all queries adjust.
+ // in production if the schema is corrupted.
erikwright (departed) 2013/06/13 01:26:24 Fix up the capitalization/grammar here.
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done. A snippet got lost somewhere in editing.
if (error == SQLITE_ERROR)
DLOG(FATAL) << "SQL Error in " << sql << ", " << GetErrorMessage();
return error == SQLITE_OK;
@@ -664,11 +686,10 @@ bool Connection::OpenInternal(const std::string& file_name) {
// assumptions about who might change things in the database.
// http://crbug.com/56559
if (exclusive_locking_) {
- // TODO(shess): This should probably be a full CHECK(). Code
- // which requests exclusive locking but doesn't get it is almost
- // certain to be ill-tested.
- if (!Execute("PRAGMA locking_mode=EXCLUSIVE"))
- DLOG(FATAL) << "Could not set locking mode: " << GetErrorMessage();
+ // TODO(shess): This should probably be a failure. Code which
+ // requests exclusive locking but doesn't get it is almost certain
+ // to be ill-tested.
+ ignore_result(Execute("PRAGMA locking_mode=EXCLUSIVE"));
}
// http://www.sqlite.org/pragma.html#pragma_journal_mode
@@ -693,19 +714,16 @@ bool Connection::OpenInternal(const std::string& file_name) {
DCHECK_LE(page_size_, kSqliteMaxPageSize);
const std::string sql =
base::StringPrintf("PRAGMA page_size=%d", page_size_);
- if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout))
- DLOG(FATAL) << "Could not set page size: " << GetErrorMessage();
+ ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout));
}
if (cache_size_ != 0) {
const std::string sql =
base::StringPrintf("PRAGMA cache_size=%d", cache_size_);
- if (!ExecuteWithTimeout(sql.c_str(), kBusyTimeout))
- DLOG(FATAL) << "Could not set cache size: " << GetErrorMessage();
+ ignore_result(ExecuteWithTimeout(sql.c_str(), kBusyTimeout));
}
if (!ExecuteWithTimeout("PRAGMA secure_delete=ON", kBusyTimeout)) {
- DLOG(FATAL) << "Could not enable secure_delete: " << GetErrorMessage();
Close();
return false;
}
@@ -770,7 +788,8 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) {
return error_delegate_->OnError(err, this, stmt);
// The default handling is to assert on debug and to ignore on release.
- DLOG(FATAL) << GetErrorMessage();
+ if (!ShouldIgnore(err))
+ DLOG(FATAL) << GetErrorMessage();
return err;
}
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | sql/sql.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698