aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-03-18 14:17:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-03-18 14:18:26 +0200
commit3fb92c470f67162617704ad897cf90f73a18ac00 (patch)
tree5da4028fc38c96f97b2011b207ffd835d75d622f
parent7e88b0a80618848d3a3c5f6cad886c8b7785787d (diff)
Add separate exception for SQLite forced rollbacks
-rw-r--r--odb/sqlite/error.cxx20
-rw-r--r--odb/sqlite/exceptions.cxx10
-rw-r--r--odb/sqlite/exceptions.hxx12
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,