From 8101ed727f48216e887183dc3c7b5d96e37c2650 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 17 Jul 2012 09:10:03 +0200 Subject: Implement multi-pass table dropping for SQL Server We have to first drop constraints before dropping tables in case the tables are dropped in a wrong order or there are circular dependencies. --- odb/relational/schema.hxx | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'odb/relational/schema.hxx') diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx index b0ac01f..4f31dca 100644 --- a/odb/relational/schema.hxx +++ b/odb/relational/schema.hxx @@ -690,6 +690,13 @@ namespace relational empty_ = true; pass_ = p; new_pass_ = true; + + if (pass_ == 1) + empty_passes_ = 0; // New set of passes. + + // Assume this pass is empty. + // + empty_passes_++; } // Did this pass produce anything? @@ -716,28 +723,44 @@ namespace relational { first_ = false; - // If this line starts a new pass, then output the - // switch/case blocks. + // If this line starts a new pass, then output the switch/case + // blocks. // if (new_pass_) { new_pass_ = false; empty_ = false; + empty_passes_--; // This pass is not empty. - if (pass_ == 1) + // Output case statements for empty preceeding passes, if any. + // + if (empty_passes_ != 0) { + unsigned short s (pass_ - empty_passes_); + + if (s == 1) + os << "switch (pass)" + << "{"; + else + os << "return true;" // One more pass. + << "}"; + + for (; s != pass_; ++s) + os << "case " << s << ":" << endl; + + os << "{"; + empty_passes_ = 0; + } + + if (pass_ == 1) os << "switch (pass)" - << "{" - << "case 1:" << endl << "{"; - } else - { os << "return true;" // One more pass. - << "}" - << "case " << pass_ << ":" << endl - << "{"; - } + << "}"; + + os << "case " << pass_ << ":" << endl + << "{"; } os << "db.execute ("; @@ -761,6 +784,7 @@ namespace relational bool empty_; bool new_pass_; unsigned short pass_; + unsigned short empty_passes_; // Number of preceding empty passes. }; struct cxx_object: virtual context -- cgit v1.1