diff options
-rw-r--r-- | odb/sqlite/error.cxx | 20 | ||||
-rw-r--r-- | odb/sqlite/exceptions.cxx | 10 | ||||
-rw-r--r-- | odb/sqlite/exceptions.hxx | 12 |
3 files changed, 36 insertions, 6 deletions
diff --git a/odb/sqlite/error.cxx b/odb/sqlite/error.cxx index 74822d3..6107427 100644 --- a/odb/sqlite/error.cxx +++ b/odb/sqlite/error.cxx @@ -47,6 +47,15 @@ namespace odb m = "SQLite API misuse"; break; } +#ifdef SQLITE_ABORT_ROLLBACK + case SQLITE_ABORT: + { + if (ee == SQLITE_ABORT_ROLLBACK) + throw forced_rollback (); + + break; + } +#endif case SQLITE_LOCKED: { #ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY @@ -65,16 +74,15 @@ namespace odb if (e != SQLITE_IOERR || ee == SQLITE_IOERR_BLOCKED) throw timeout (); #endif - - // Fall throught. - } - default: - { - m = sqlite3_errmsg (h); break; } + default: + break; } + if (m.empty ()) + m = sqlite3_errmsg (h); + throw database_exception (e, ee, m); } } diff --git a/odb/sqlite/exceptions.cxx b/odb/sqlite/exceptions.cxx index 40b2d4c..08cdf90 100644 --- a/odb/sqlite/exceptions.cxx +++ b/odb/sqlite/exceptions.cxx @@ -13,6 +13,16 @@ namespace odb namespace sqlite { // + // forced_rollback + // + + const char* forced_rollback:: + what () const throw () + { + return "transaction is forced to rollback"; + } + + // // database_exception // diff --git a/odb/sqlite/exceptions.hxx b/odb/sqlite/exceptions.hxx index 5afcdf5..be13bbe 100644 --- a/odb/sqlite/exceptions.hxx +++ b/odb/sqlite/exceptions.hxx @@ -19,6 +19,18 @@ namespace odb { namespace sqlite { + // This exception is thrown if SQLite is forcing the current transaction + // to rollback. This can happen in SQLite 3.7.11 or later if one of the + // connections participating in the shared cache rolls back a transaction. + // See the SQLITE_ABORT_ROLLBACK extended error code for detail on this + // behavior. + // + struct LIBODB_EXPORT forced_rollback: recoverable + { + virtual const char* + what () const throw (); + }; + struct LIBODB_SQLITE_EXPORT database_exception: odb::database_exception { database_exception (int error, |