aboutsummaryrefslogtreecommitdiff
path: root/schema
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-22 10:47:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-22 10:47:30 +0200
commit5bca7cdc208dd5c9261e47e7350e37ea9692d6ed (patch)
tree797bf3151c060a98059ee343f8e0a1ca040930ad /schema
parent0da4b5d62dc10993db4d55236cb175e891a9c62b (diff)
Enable foreign key constraints checking in SQLite
Due to bugs in SQLite DDL foreign key support, we have to temporarily disable foreign keys when re-creating the schema. New manual section: 12.5.3, "Foreign Key Constraints".
Diffstat (limited to 'schema')
-rw-r--r--schema/custom/driver.cxx19
1 files changed, 18 insertions, 1 deletions
diff --git a/schema/custom/driver.cxx b/schema/custom/driver.cxx
index d08bb62..1ca563c 100644
--- a/schema/custom/driver.cxx
+++ b/schema/custom/driver.cxx
@@ -6,6 +6,7 @@
#include <iostream>
#include <odb/database.hxx>
+#include <odb/connection.hxx>
#include <odb/session.hxx>
#include <odb/transaction.hxx>
@@ -28,7 +29,17 @@ main (int argc, char* argv[])
//
#if defined(DATABASE_MYSQL) || defined(DATABASE_SQLITE)
{
- transaction t (db->begin ());
+
+ // Due to bugs in SQLite foreign key support for DDL statements,
+ // we need to temporarily disable foreign keys.
+ //
+ connection_ptr c (db->connection ());
+
+#ifdef DATABASE_SQLITE
+ c->execute ("PRAGMA foreign_keys=OFF");
+#endif
+
+ transaction t (c->begin ());
// Try to drop the tables if they exist and ignore the error
// if they don't.
@@ -60,6 +71,10 @@ main (int argc, char* argv[])
"degree VARCHAR (255) NOT NULL)");
t.commit ();
+
+#ifdef DATABASE_SQLITE
+ c->execute ("PRAGMA foreign_keys=ON");
+#endif
}
#elif defined(DATABASE_PGSQL)
{
@@ -101,6 +116,8 @@ main (int argc, char* argv[])
t.commit ();
}
+#else
+# error unknown database
#endif
// Create a few persistent objects.