diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-17 09:12:17 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-17 09:12:17 +0200 |
commit | 6b4e9e363a2bf7c119391e6f4ecf68e194636ecc (patch) | |
tree | 04ed11b3e4271b67185995b0779ef1bae6170bf8 /common/circular | |
parent | dc5874e5b8cdb2a8c8a5dc77a0bb4bd891079e3f (diff) |
Disable foreign keys for MySQL and SQLite while creating schema
Diffstat (limited to 'common/circular')
-rw-r--r-- | common/circular/multiple/driver.cxx | 22 |
1 files changed, 21 insertions, 1 deletions
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 <iostream> #include <odb/database.hxx> +#include <odb/connection.hxx> #include <odb/transaction.hxx> #include <odb/schema-catalog.hxx> +#include <common/config.hxx> // DATABASE_XXX #include <common/common.hxx> #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<base> bq (query<base>::d->id != 0); |