summaryrefslogtreecommitdiffstats
path: root/sql/connection.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 22:18:10 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 22:18:10 +0000
commit4350e321e41d0faa025ac516aad6365bc8e9a83f (patch)
tree23d66544bf4dc0f62a20820f66ad2264b2323eee /sql/connection.cc
parent90392f8e3110e58c0367c4d87caa7f33709bff6c (diff)
downloadchromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.zip
chromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.tar.gz
chromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.tar.bz2
[sql] Framework for allowing tests to handle errors.
sql/ throws FATAL whenever it sees inappropriate calls, which makes production code to handle errors hard to test. ScopedErrorIgnorer provides a way for tests to signal that specific errors are expected and will be handled. As a first pass, code up some additional tests for some Raze() edge cases, and modify things to pass those tests. BUG=159490 Review URL: https://chromiumcodereview.appspot.com/16664005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/connection.cc')
-rw-r--r--sql/connection.cc44
1 files changed, 32 insertions, 12 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index 510d6a7..67cdf08 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -68,6 +68,28 @@ class ScopedWritableSchema {
namespace sql {
+// static
+Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL;
+
+// static
+bool Connection::ShouldIgnore(int error) {
+ if (!current_ignorer_cb_)
+ return false;
+ return current_ignorer_cb_->Run(error);
+}
+
+// static
+void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) {
+ CHECK(current_ignorer_cb_ == NULL);
+ current_ignorer_cb_ = cb;
+}
+
+// static
+void Connection::ResetErrorIgnorer() {
+ CHECK(current_ignorer_cb_);
+ current_ignorer_cb_ = NULL;
+}
+
bool StatementID::operator<(const StatementID& other) const {
if (number_ != other.number_)
return number_ < other.number_;
@@ -435,7 +457,8 @@ 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.
+ // a change alters the schema but not all queries adjust. This can happen
+ // in production if the schema is corrupted.
if (error == SQLITE_ERROR)
DLOG(FATAL) << "SQL Error in " << sql << ", " << GetErrorMessage();
return error == SQLITE_OK;
@@ -660,11 +683,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
@@ -689,19 +711,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;
}
@@ -761,7 +780,8 @@ int Connection::OnSqliteError(int err, sql::Statement *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;
}