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/oracle/context.cxx | 23 ++++++++++++++++++----- odb/relational/oracle/context.hxx | 2 +- odb/relational/oracle/schema.cxx | 20 +++++++++++--------- 3 files changed, 30 insertions(+), 15 deletions(-) (limited to 'odb/relational/oracle') diff --git a/odb/relational/oracle/context.cxx b/odb/relational/oracle/context.cxx index d477a19..bb76ee7 100644 --- a/odb/relational/oracle/context.cxx +++ b/odb/relational/oracle/context.cxx @@ -103,13 +103,26 @@ namespace relational } string context:: - quote_id_impl (string const& id) const + quote_id_impl (qname const& id) const { string r; - r.reserve (32); - r += '"'; - r.append (id, 0, 30); - 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.append (*i, 0, 30); // Max identifier length is 30. + r += '"'; + } + return r; } diff --git a/odb/relational/oracle/context.hxx b/odb/relational/oracle/context.hxx index ea81136..e19264a 100644 --- a/odb/relational/oracle/context.hxx +++ b/odb/relational/oracle/context.hxx @@ -98,7 +98,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/oracle/schema.cxx b/odb/relational/oracle/schema.cxx index a371235..b98facc 100644 --- a/odb/relational/oracle/schema.cxx +++ b/odb/relational/oracle/schema.cxx @@ -94,7 +94,7 @@ namespace relational drop_table (base const& x): base (x) {} virtual void - drop (string const& table) + drop (sema_rel::qname const& table) { // Oracle has no IF EXISTS conditional for dropping objects. The // PL/SQL approach below seems to be the least error-prone and the @@ -142,7 +142,7 @@ namespace relational private: friend class create_foreign_key; - set tables_; // Set of tables we have already defined. + set tables_; // Set of tables we have already defined. }; entry create_table_; @@ -203,10 +203,12 @@ namespace relational name (sema_rel::foreign_key& fk) { // In Oracle, 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 (fk.scope ()).name () + - '_' + fk.name (); + return quote_id ( + static_cast (fk.scope ()).name ().uname () + + "_" + fk.name ()); } }; entry create_foreign_key_; @@ -256,11 +258,11 @@ namespace relational if (pk != 0 && pk->auto_ ()) { - string const& tname (t.name ()); + qname const& tname (t.name ()); string const& cname (pk->contains_begin ()->column ().name ()); - string seq_name (tname + "_seq"); - string trg_name (tname + "_trg"); + qname seq_name (tname + "_seq"); + qname trg_name (tname + "_trg"); // Sequence. // @@ -292,7 +294,7 @@ namespace relational // Add foreign keys. // instance fk (format_, *this); - trav_rel::names n (*fk); + trav_rel::unames n (*fk); names (t, n); } } -- cgit v1.1