aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/error.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-21 17:24:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-21 17:24:35 +0200
commitdac72baef46897b80fc98632cef182fb266a5d60 (patch)
treea90f40a5fac59456c6fecf3d31a008c5a061b955 /odb/sqlite/error.cxx
parent3af997a875e439e71754fddb67fd60de9f60307b (diff)
Add base SQLite database classes
Diffstat (limited to 'odb/sqlite/error.cxx')
-rw-r--r--odb/sqlite/error.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/odb/sqlite/error.cxx b/odb/sqlite/error.cxx
new file mode 100644
index 0000000..d34f55b
--- /dev/null
+++ b/odb/sqlite/error.cxx
@@ -0,0 +1,61 @@
+// file : odb/sqlite/errors.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <sqlite3.h>
+
+#include <new> // std::bad_alloc
+#include <string>
+
+#include <odb/sqlite/connection.hxx>
+#include <odb/sqlite/exceptions.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace sqlite
+ {
+ void
+ translate_error (int e, connection& c)
+ {
+ sqlite3* h (c.handle ());
+ int ee (sqlite3_extended_errcode (h));
+ string m;
+
+ switch (e)
+ {
+ case SQLITE_NOMEM:
+ {
+ throw bad_alloc ();
+ }
+ case SQLITE_MISUSE:
+ {
+ // In case of SQLITE_MISUSE, error code/message may or may not
+ // be set.
+ //
+ ee = e;
+ m = "SQLite API misuse";
+ break;
+ }
+ case SQLITE_BUSY:
+ case SQLITE_LOCKED:
+ case SQLITE_IOERR:
+ {
+ if (e != SQLITE_IOERR || ee == SQLITE_IOERR_BLOCKED)
+ throw deadlock ();
+
+ // Fall throught.
+ }
+ default:
+ {
+ m = sqlite3_errmsg (h);
+ break;
+ }
+ }
+
+ throw database_exception (e, ee, m);
+ }
+ }
+}