From 5bca7cdc208dd5c9261e47e7350e37ea9692d6ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Aug 2011 10:47:30 +0200 Subject: 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". --- container/database.hxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'container') diff --git a/container/database.hxx b/container/database.hxx index 0e407d4..9a30039 100644 --- a/container/database.hxx +++ b/container/database.hxx @@ -19,6 +19,7 @@ #if defined(DATABASE_MYSQL) # include #elif defined(DATABASE_SQLITE) +# include # include # include # include @@ -55,12 +56,20 @@ create_database (int& argc, char* argv[]) new odb::sqlite::database ( argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - // 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. // { - 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 db (new odb::pgsql::database (argc, argv)); -- cgit v1.1