aboutsummaryrefslogtreecommitdiff
path: root/libcommon
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
commitab0fb8ac7e097dcdd3111dc2865f0de14ab27118 (patch)
tree4bbd04d8b62eff8168e23ef24451ef129f2fc30d /libcommon
parent4cb83ca74184b364b3d03df3d13b175c965f3559 (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 'libcommon')
-rw-r--r--libcommon/common/common.cxx15
1 files changed, 12 insertions, 3 deletions
diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx
index 37f8424..47dee81 100644
--- a/libcommon/common/common.cxx
+++ b/libcommon/common/common.cxx
@@ -14,6 +14,7 @@
# include <odb/mysql/database.hxx>
# include <odb/mysql/connection-factory.hxx>
#elif defined(DATABASE_SQLITE)
+# include <odb/connection.hxx>
# include <odb/transaction.hxx>
# include <odb/schema-catalog.hxx>
# include <odb/sqlite/database.hxx>
@@ -81,15 +82,23 @@ create_database (int& argc,
db.reset (
new sqlite::database (
- argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, f));
+ argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, true, f));
- // Create the database schema.
+ // Create the database schema. Due to bugs in SQLite foreign key
+ // support for DDL statements, we need to temporarily disable
+ // foreign keys.
//
if (schema)
{
- transaction t (db->begin ());
+ connection_ptr c (db->connection ());
+
+ c->execute ("PRAGMA foreign_keys=OFF");
+
+ transaction t (c->begin ());
schema_catalog::create_schema (*db);
t.commit ();
+
+ c->execute ("PRAGMA foreign_keys=ON");
}
#elif defined(DATABASE_PGSQL)
auto_ptr<pgsql::connection_factory> f;