From aaf47c94726ed05ca8c6790f0946e341125e7eb4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 24 Aug 2011 17:11:43 +0200 Subject: Don't append table prefix to names that already have it (container tables) --- odb/common.cxx | 7 +++++-- odb/context.cxx | 14 +++++++++++--- odb/context.hxx | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/odb/common.cxx b/odb/common.cxx index 2c23e76..130d5ec 100644 --- a/odb/common.cxx +++ b/odb/common.cxx @@ -128,8 +128,8 @@ traverse (semantics::data_member& m) // if (m.count ("table")) { - if (om_.table_prefix_.level == 1) - om_.table_prefix_.prefix.clear (); + if (om_.table_prefix_.level <= 1) + om_.table_prefix_.prefix = om_.options.table_prefix (); om_.table_prefix_.prefix += m.get ("table"); } @@ -141,6 +141,9 @@ traverse (semantics::data_member& m) string name (om_.public_name_db (m)); size_t n (name.size ()); + if (om_.table_prefix_.prefix.empty ()) + om_.table_prefix_.prefix = om_.options.table_prefix (); + om_.table_prefix_.prefix += name; if (n != 0 && name[n - 1] != '_') diff --git a/odb/context.cxx b/odb/context.cxx index 68e3f65..9d89879 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -372,7 +372,13 @@ table_name (semantics::class_& t) const string context:: table_name (semantics::data_member& m, table_prefix const& p) const { - string name (options.table_prefix ()); + // The table prefix passed as the second argument must include + // the table prefix specified with the --table-prefix option. + // + string const& gp (options.table_prefix ()); + assert (p.prefix.compare (0, gp.size (), gp) == 0); + + string name; // If a custom table name was specified, then ignore the top-level // table prefix. @@ -380,13 +386,15 @@ table_name (semantics::data_member& m, table_prefix const& p) const if (m.count ("table")) { if (p.level != 1) - name += p.prefix; + name = p.prefix; + else + name = gp; name += m.get ("table"); } else { - name += p.prefix; + name = p.prefix; name += public_name_db (m); } diff --git a/odb/context.hxx b/odb/context.hxx index 5962133..69c5d48 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -135,7 +135,9 @@ public: string table_name (semantics::class_&) const; - // Table name for the container member. + // Table name for the container member. The table prefix passed as the + // second argument must include the table prefix specified with the + // --table-prefix option. // struct table_prefix { -- cgit v1.1