aboutsummaryrefslogtreecommitdiff
path: root/sqlite/transaction/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-02 14:40:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-02 14:40:50 +0200
commite8b23f12981a754757c49471f4e4a2376368909b (patch)
tree4977861a21b253b4fe7de43ba76e5d8f270997df /sqlite/transaction/driver.cxx
parentdcb6d84266a0b291781855cf623aa4d4c395f14d (diff)
Handle SQLite commit failures that don't automatically rollback transaction
Diffstat (limited to 'sqlite/transaction/driver.cxx')
-rw-r--r--sqlite/transaction/driver.cxx60
1 files changed, 60 insertions, 0 deletions
diff --git a/sqlite/transaction/driver.cxx b/sqlite/transaction/driver.cxx
new file mode 100644
index 0000000..a70e1fd
--- /dev/null
+++ b/sqlite/transaction/driver.cxx
@@ -0,0 +1,60 @@
+// file : sqlite/transaction/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test esoteric SQLite transaction semantics aspects.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/sqlite/database.hxx>
+#include <odb/sqlite/transaction.hxx>
+
+#include <common/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+namespace sqlite = odb::sqlite;
+using namespace sqlite;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ auto_ptr<database> db (create_specific_database<database> (argc, argv));
+
+ // In SQLite, when a commit fails because of the deferred foreign
+ // key constraint violation, the transaction is not automatically
+ // rolled back. Make sure we compensate for that.
+ //
+ try
+ {
+ object o;
+ o.p = odb::lazy_ptr<object1> (*db, 0);
+
+ transaction t (db->begin ());
+ db->persist(o);
+ t.commit ();
+ }
+ catch (const odb::exception&)
+ {
+ }
+
+ // Make sure we can start a new transaction.
+ //
+ {
+ transaction t (db->begin ());
+ t.commit ();
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}