From dac72baef46897b80fc98632cef182fb266a5d60 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 21 Mar 2011 17:24:35 +0200 Subject: Add base SQLite database classes --- odb/sqlite/error.cxx | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 odb/sqlite/error.cxx (limited to 'odb/sqlite/error.cxx') 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 +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include // std::bad_alloc +#include + +#include +#include + +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); + } + } +} -- cgit v1.1