From de130e93d8b2c026732211e67b6f31157f1b7e87 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Aug 2015 17:51:48 +0200 Subject: Fix inconsistent composite value member prefix derivation --- odb/context.cxx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'odb/context.cxx') diff --git a/odb/context.cxx b/odb/context.cxx index 6dcf987..e8dd96a 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -2133,7 +2133,7 @@ table_name (semantics::data_member& m, table_prefix const& p) const // context::column_prefix:: column_prefix (data_member_path const& mp, bool l) - : derived (false) + : derived (false), underscore (false) { if (mp.size () < (l ? 1 : 2)) return; @@ -2157,12 +2157,16 @@ append (semantics::data_member& m, string const& kp, string const& dn) // If the user provided the column prefix, then use it verbatime. // Otherwise, append the underscore, unless it is already there. // + underscore = false; if (d) { size_t n (prefix.size ()); if (n != 0 && prefix[n - 1] != '_') + { prefix += '_'; + underscore = true; + } } derived = derived || d; @@ -2181,8 +2185,13 @@ string context:: column_name (semantics::data_member& m, column_prefix const& cp) const { bool d; - string n (column_name (m, d)); - n = compose_name (cp.prefix, n); + const string& cn (column_name (m, d)); + string n (cp.prefix); + + if (cn.empty () && cp.underscore) + n.resize (n.size () - 1); // Strip underscore that was auto added. + + n += cn; // If any component is derived, then run it through the SQL name regex. // @@ -2228,8 +2237,13 @@ column_name (semantics::data_member& m, column_prefix const& cp) const { bool d; - string n (column_name (m, kp, dn, d)); - n = compose_name (cp.prefix, n); + const string& cn (column_name (m, kp, dn, d)); + string n (cp.prefix); + + if (cn.empty () && cp.underscore) + n.resize (n.size () - 1); // Strip underscore that was auto-added. + + n += cn; // If any component is derived, the run it through the SQL name regex. // -- cgit v1.1