summaryrefslogtreecommitdiffstats
path: root/sql/error_delegate_util.cc
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 04:31:53 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 04:31:53 +0000
commit0d04ede3f14d8c248b5f91687694673df8c145b5 (patch)
tree3c2ea2c08726dd0424cb295c790308280289c890 /sql/error_delegate_util.cc
parentb50b6edf3dee383cae64c39e4b101c848b7ebc74 (diff)
downloadchromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.zip
chromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.tar.gz
chromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.tar.bz2
Move ErrorDelegate to its own file and add static utility functions to ErrorDelegate
BUG=151841 Test=None R=shess, erikwright TBR=cpu Review URL: https://chromiumcodereview.appspot.com/11141012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/error_delegate_util.cc')
-rw-r--r--sql/error_delegate_util.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/sql/error_delegate_util.cc b/sql/error_delegate_util.cc
new file mode 100644
index 0000000..37fe006
--- /dev/null
+++ b/sql/error_delegate_util.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sql/error_delegate_util.h"
+
+#include "third_party/sqlite/sqlite3.h"
+
+namespace sql {
+
+bool IsErrorCatastrophic(int error) {
+ switch (error) {
+ case SQLITE_DONE:
+ case SQLITE_OK:
+ // Theoretically, the wrapped delegate might have resolved the error, and
+ // we would end up here.
+ return false;
+
+ case SQLITE_CORRUPT:
+ case SQLITE_NOTADB:
+ // Highly unlikely we would ever recover from these.
+ return true;
+
+ case SQLITE_CANTOPEN:
+ // TODO(erikwright): Figure out what this means.
+ return false;
+
+ case SQLITE_IOERR:
+ // This could be broken blocks, in which case deleting the DB would be a
+ // good idea. But it might also be transient.
+ // TODO(erikwright): Figure out if we can distinguish between the two,
+ // or determine through metrics analysis to what extent these failures are
+ // transient.
+ return false;
+
+ case SQLITE_BUSY:
+ // Presumably transient.
+ return false;
+
+ case SQLITE_TOOBIG:
+ case SQLITE_FULL:
+ case SQLITE_NOMEM:
+ // Not a problem with the database.
+ return false;
+
+ case SQLITE_READONLY:
+ // Presumably either transient or we don't have the privileges to
+ // move/delete the file anyway.
+ return false;
+
+ case SQLITE_CONSTRAINT:
+ case SQLITE_ERROR:
+ // These probgably indicate a programming error or a migration failure
+ // that we prefer not to mask.
+ return false;
+
+ case SQLITE_LOCKED:
+ case SQLITE_INTERNAL:
+ case SQLITE_PERM:
+ case SQLITE_ABORT:
+ case SQLITE_INTERRUPT:
+ case SQLITE_NOTFOUND:
+ case SQLITE_PROTOCOL:
+ case SQLITE_EMPTY:
+ case SQLITE_SCHEMA:
+ case SQLITE_MISMATCH:
+ case SQLITE_MISUSE:
+ case SQLITE_NOLFS:
+ case SQLITE_AUTH:
+ case SQLITE_FORMAT:
+ case SQLITE_RANGE:
+ case SQLITE_ROW:
+ // None of these appear in error reports, so for now let's not try to
+ // guess at how to handle them.
+ return false;
+ }
+ return false;
+}
+
+} // namespace sql