From 6b4e9e363a2bf7c119391e6f4ecf68e194636ecc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 17 Jul 2012 09:12:17 +0200 Subject: Disable foreign keys for MySQL and SQLite while creating schema --- common/circular/multiple/driver.cxx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'common/circular') diff --git a/common/circular/multiple/driver.cxx b/common/circular/multiple/driver.cxx index 2f28911..1b80218 100644 --- a/common/circular/multiple/driver.cxx +++ b/common/circular/multiple/driver.cxx @@ -11,9 +11,11 @@ #include #include +#include #include #include +#include // DATABASE_XXX #include #include "test1.hxx" @@ -35,9 +37,27 @@ main (int argc, char* argv[]) // Create the database schema. // { - transaction t (db->begin ()); + connection_ptr c (db->connection ()); + + // Temporarily disable foreign key constraints for MySQL and SQLite. + // For these databases this is the only way to drop circularly- + // dependant tables. + // +#if defined(DATABASE_MYSQL) + c->execute ("SET FOREIGN_KEY_CHECKS=0"); +#elif defined(DATABASE_SQLITE) + c->execute ("PRAGMA foreign_keys=OFF"); +#endif + + transaction t (c->begin ()); schema_catalog::create_schema (*db); t.commit (); + +#if defined(DATABASE_MYSQL) + c->execute ("SET FOREIGN_KEY_CHECKS=1"); +#elif defined(DATABASE_SQLITE) + c->execute ("PRAGMA foreign_keys=ON"); +#endif } query bq (query::d->id != 0); -- cgit v1.1