diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-11 14:21:52 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-21 15:40:00 +0200 |
commit | a6630dff5bf2002c0c133ea6c5e16d8a0a22138f (patch) | |
tree | 64e05f2b2a6e0d602fe2d89bec8698ca9b0b70f4 /odb/relational/schema.hxx | |
parent | 7208e97cabf7c21169a036ae7cf697042984e9cb (diff) |
Create indexes in separate SQL statements
This is more vendor-neutral.
Diffstat (limited to 'odb/relational/schema.hxx')
-rw-r--r-- | odb/relational/schema.hxx | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx index 9da6624..6c481da 100644 --- a/odb/relational/schema.hxx +++ b/odb/relational/schema.hxx @@ -50,10 +50,20 @@ namespace relational struct drop_common: virtual context { virtual void - drop (string const& table) + drop_table (string const& table) { os << "DROP TABLE IF EXISTS " << quote_id (table) << endl; } + + virtual void + drop_index (string const& /*table*/, string const& /*column*/) + { + // Most database systems drop indexes together with the table. + // + + //os << "DROP INDEX IF EXISTS " << quote_id (table + '_' + column) + // << endl; + } }; struct member_drop: object_members_base, common, virtual drop_common @@ -78,11 +88,26 @@ namespace relational if (tables_.count (name)) return; + // Drop table. + // pre_statement (); - drop (name); + drop_table (name); post_statement (); tables_.insert (name); + + // Drop indexes. + // + pre_statement (); + drop_index (name, column_name (m, "id", "object_id")); + post_statement (); + + if (container_kind (m.type ()) == ck_ordered && !unordered (m)) + { + pre_statement (); + drop_index (name, column_name (m, "index", "index")); + post_statement (); + } } protected: @@ -120,7 +145,7 @@ namespace relational return; pre_statement (); - drop (name); + drop_table (name); post_statement (); tables_.insert (name); @@ -187,25 +212,26 @@ namespace relational struct create_common: virtual context { virtual void - create_pre (string const& table) + create_table_pre (string const& table) { os << "CREATE TABLE " << quote_id (table) << " (" << endl; } virtual void - index (string const& column) + create_table_post () { - os << "INDEX (" << quote_id (column) << ")"; + os << ")" << endl; } virtual void - create_post () + create_index (string const& table, string const& column) { - os << ")" << endl; + os << "CREATE INDEX " << quote_id (table + '_' + column) << endl + << " ON " << quote_id (table) << " (" << quote_id (column) << ")" + << endl; } }; - struct member_create: object_members_base, common, virtual create_common { typedef member_create base; @@ -236,7 +262,7 @@ namespace relational return; pre_statement (); - create_pre (name); + create_table_pre (name); // object_id (simple value) // @@ -298,25 +324,23 @@ namespace relational } } - // object_id index - // - os << "," << endl - << " "; - index (id_name); + create_table_post (); + post_statement (); + + tables_.insert (name); - // index index + // Create indexes. // + pre_statement (); + create_index (name, id_name); + post_statement (); + if (ordered) { - os << "," << endl - << " "; - index (index_name); + pre_statement (); + create_index (name, index_name); + post_statement (); } - - create_post (); - post_statement (); - - tables_.insert (name); } protected: @@ -357,14 +381,14 @@ namespace relational return; pre_statement (); - create_pre (name); + create_table_pre (name); { instance<object_columns> oc; oc->traverse (c); } - create_post (); + create_table_post (); post_statement (); tables_.insert (name); |