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". --- schema/custom/driver.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'schema') 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 #include +#include #include #include @@ -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. -- cgit v1.1