From af12ffe836de09ec84f666effa4df347eeb07a43 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Jan 2012 12:43:16 +0200 Subject: 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. --- odb/relational/mysql/context.cxx | 23 ++++++++++++++++++----- odb/relational/mysql/context.hxx | 2 +- odb/relational/mysql/schema.cxx | 22 +++++++++++++++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) (limited to 'odb/relational/mysql') diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index e7fd790..9ee0843 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -105,13 +105,26 @@ namespace relational } string context:: - quote_id_impl (string const& id) const + quote_id_impl (qname const& id) const { string r; - r.reserve (id.size () + 2); - r += '`'; - r += id; - r += '`'; + + bool f (true); + for (qname::iterator i (id.begin ()); i < id.end (); ++i) + { + if (i->empty ()) + continue; + + if (f) + f = false; + else + r += '.'; + + r += '`'; + r += *i; + r += '`'; + } + return r; } diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index 2615397..c88a525 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -111,7 +111,7 @@ namespace relational protected: virtual string - quote_id_impl (string const&) const; + quote_id_impl (qname const&) const; protected: virtual string diff --git a/odb/relational/mysql/schema.cxx b/odb/relational/mysql/schema.cxx index 428db1c..1bdb6dd 100644 --- a/odb/relational/mysql/schema.cxx +++ b/odb/relational/mysql/schema.cxx @@ -91,10 +91,12 @@ namespace relational name (sema_rel::foreign_key& fk) { // In MySQL, foreign key names are database-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 be prefixed with the database name. // - return static_cast (fk.scope ()).name () + - '_' + fk.name (); + return quote_id ( + static_cast (fk.scope ()).name ().uname () + + "_" + fk.name ()); } virtual void @@ -124,6 +126,20 @@ namespace relational } }; entry create_table_; + + struct create_index: relational::create_index, context + { + create_index (base const& x): base (x) {} + + virtual string + name (sema_rel::index& in) + { + // In MySQL an index cannot be qualified with the database name. + // + return quote_id (in.name ().uname ()); + } + }; + entry create_index_; } } } -- cgit v1.1