summaryrefslogtreecommitdiff
path: root/odb/relational/mssql/schema.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-26 12:43:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-26 12:43:16 +0200
commitaf12ffe836de09ec84f666effa4df347eeb07a43 (patch)
treedc0aec9f8fee545c84be098414772cf2b277c30d /odb/relational/mssql/schema.cxx
parentc1d2ec5bbd5969332f3278f39d2a7a8f0abc0493 (diff)
Implement support for database schema
New pragma qualifier: namespace. New pragma specifier: schema. The table specifier was extended to accept a schema prefix. New option: --default- schema. The common/schema test was extended to cover the new functionality.
Diffstat (limited to 'odb/relational/mssql/schema.cxx')
-rw-r--r--odb/relational/mssql/schema.cxx32
1 files changed, 23 insertions, 9 deletions
diff --git a/odb/relational/mssql/schema.cxx b/odb/relational/mssql/schema.cxx
index 2cbeb5f..66a2278 100644
--- a/odb/relational/mssql/schema.cxx
+++ b/odb/relational/mssql/schema.cxx
@@ -46,15 +46,13 @@ namespace relational
drop_table (base const& x): base (x) {}
virtual void
- drop (string const& table)
+ drop (sema_rel::qname const& table)
{
// SQL Server has no IF EXISTS conditional for dropping table.
// The following approach appears to be the recommended way to
// drop a table if it exists.
//
- string const& qt ();
-
- os << "IF OBJECT_ID(" << quote_string (table) <<
+ os << "IF OBJECT_ID(" << quote_string (table.string ()) <<
", " << quote_string ("U") << ") IS NOT NULL" << endl
<< " DROP TABLE " << quote_id (table) << endl;
}
@@ -88,7 +86,7 @@ namespace relational
private:
friend class create_foreign_key;
- set<string> tables_; // Set of tables we have already defined.
+ set<qname> tables_; // Set of tables we have already defined.
};
entry<create_table> create_table_;
@@ -145,10 +143,12 @@ namespace relational
name (sema_rel::foreign_key& fk)
{
// In SQL Server, foreign key names are schema-global. Make them
- // unique by prefixing the key name with table name.
+ // unique by prefixing the key name with table name. Note, however,
+ // that they cannot have a schema.
//
- return static_cast<sema_rel::table&> (fk.scope ()).name () +
- '_' + fk.name ();
+ return quote_id (
+ static_cast<sema_rel::table&> (fk.scope ()).name ().uname ()
+ + "_" + fk.name ());
}
virtual void
@@ -216,9 +216,23 @@ namespace relational
// Add foreign keys.
//
instance<add_foreign_key> fk (format_, *this);
- trav_rel::names n (*fk);
+ trav_rel::unames n (*fk);
names (t, n);
}
+
+ struct create_index: relational::create_index, context
+ {
+ create_index (base const& x): base (x) {}
+
+ virtual string
+ name (sema_rel::index& in)
+ {
+ // In SQL Server indexes cannot have a schema.
+ //
+ return quote_id (in.name ().uname ());
+ }
+ };
+ entry<create_index> create_index_;
}
}
}