From 9ecf8955737cfd1b1feb3421240389b439ba3759 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 Apr 2013 07:26:39 +0200 Subject: Add schema_catalog::drop_schema(), control schema dropping in create_schema() --- odb/schema-catalog.cxx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'odb/schema-catalog.cxx') diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx index 52b612f..9599afe 100644 --- a/odb/schema-catalog.cxx +++ b/odb/schema-catalog.cxx @@ -42,7 +42,7 @@ namespace odb } void schema_catalog:: - create_schema (database& db, const string& name) + create_schema (database& db, const string& name, bool drop) { const schema_catalog_impl& c (*schema_catalog_init::catalog); schema_catalog_impl::const_iterator i (c.find (key (db.id (), name))); @@ -52,11 +52,12 @@ namespace odb const create_functions& fs (i->second.create); + if (drop) + drop_schema (db, name); + // Run the passes until we ran them all or all the functions - // return false, which means no more passes necessary. Do that - // first for drop passes, then for create. + // return false, which means no more passes necessary. // - for (unsigned short pass (1); pass < 3; ++pass) { bool done (true); @@ -64,14 +65,29 @@ namespace odb for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); j != e; ++j) { - if ((*j) (db, pass, true)) + if ((*j) (db, pass, false)) done = false; } if (done) break; } + } + + void schema_catalog:: + drop_schema (database& db, const string& name) + { + const schema_catalog_impl& c (*schema_catalog_init::catalog); + schema_catalog_impl::const_iterator i (c.find (key (db.id (), name))); + if (i == c.end ()) + throw unknown_schema (name); + + const create_functions& fs (i->second.create); + + // Run the passes until we ran them all or all the functions + // return false, which means no more passes necessary. + // for (unsigned short pass (1); pass < 3; ++pass) { bool done (true); @@ -79,7 +95,7 @@ namespace odb for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); j != e; ++j) { - if ((*j) (db, pass, false)) + if ((*j) (db, pass, true)) done = false; } -- cgit v1.1