summaryrefslogtreecommitdiff
path: root/odb/common.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/common.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/common.cxx')
-rw-r--r--odb/common.cxx31
1 files changed, 22 insertions, 9 deletions
diff --git a/odb/common.cxx b/odb/common.cxx
index 379c769..fe77b2c 100644
--- a/odb/common.cxx
+++ b/odb/common.cxx
@@ -120,7 +120,7 @@ traverse (semantics::class_& c)
if (table_prefix_.level == 0)
{
table_prefix_.prefix = table_name (c);
- table_prefix_.prefix += '_';
+ table_prefix_.prefix += "_";
table_prefix_.level = 1;
tb = true;
}
@@ -170,7 +170,8 @@ traverse (semantics::data_member& m)
om_.member_scope_.push_back (class_inheritance_chain ());
om_.member_scope_.back ().push_back (comp);
- string old_flat_prefix, old_table_prefix, old_member_prefix;
+ qname old_table_prefix;
+ string old_flat_prefix, old_member_prefix;
if (om_.build_flat_prefix_)
{
@@ -225,15 +226,27 @@ append (semantics::data_member& m, table_prefix& tp)
{
context& ctx (context::current ());
- // If the user provided a table prefix, then use it verbatim. Also
- // drop the top-level table prefix in this case.
+ // If a custom table prefix was specified, then ignore the top-level
+ // table prefix (this corresponds to a container directly inside an
+ // object) but keep the schema unless the alternative schema is fully
+ // qualified.
//
if (m.count ("table"))
{
- if (tp.level <= 1)
- tp.prefix = ctx.options.table_prefix ();
+ qname p, n (m.get<qname> ("table"));
- tp.prefix += m.get<string> ("table");
+ if (n.fully_qualified ())
+ p = n.qualifier ();
+ else
+ {
+ p = tp.prefix.qualifier ();
+ p.append (n.qualifier ());
+ }
+
+ p.append (tp.level <= 1 ? ctx.options.table_prefix () : tp.prefix.uname ());
+ p += n.uname ();
+
+ tp.prefix.swap (p);
}
// Otherwise use the member name and add an underscore unless it is
// already there.
@@ -244,12 +257,12 @@ append (semantics::data_member& m, table_prefix& tp)
size_t n (name.size ());
if (tp.prefix.empty ())
- tp.prefix = ctx.options.table_prefix ();
+ tp.prefix.append (ctx.options.table_prefix ());
tp.prefix += name;
if (n != 0 && name[n - 1] != '_')
- tp.prefix += '_';
+ tp.prefix += "_";
}
tp.level++;