aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-08-24 17:51:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-08-24 17:51:48 +0200
commitde130e93d8b2c026732211e67b6f31157f1b7e87 (patch)
tree898f6bf3f0029565654b044df057789097c86ab0
parent15995637f9cab6a4d92a2383e2afdba2b48d5f7b (diff)
Fix inconsistent composite value member prefix derivation
-rw-r--r--odb/context.cxx24
-rw-r--r--odb/context.hxx5
-rw-r--r--odb/processor.cxx5
-rw-r--r--odb/relational/common-query.cxx2
-rw-r--r--odb/relational/model.hxx2
-rw-r--r--odb/relational/source.hxx4
6 files changed, 30 insertions, 12 deletions
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.
//
diff --git a/odb/context.hxx b/odb/context.hxx
index 7032dcf..002ee6e 100644
--- a/odb/context.hxx
+++ b/odb/context.hxx
@@ -1343,12 +1343,12 @@ public:
//
struct column_prefix
{
- column_prefix (): derived (false) {}
+ column_prefix (): derived (false), underscore (false) {}
column_prefix (semantics::data_member& m,
string const& key_prefix = string (),
string const& default_name = string ())
- : derived (false)
+ : derived (false), underscore (false)
{
append (m, key_prefix, default_name);
}
@@ -1368,6 +1368,7 @@ public:
string prefix;
bool derived; // One of the components in the prefix was derived.
+ bool underscore; // Trailing underscore was automatically added.
};
string
diff --git a/odb/processor.cxx b/odb/processor.cxx
index 5dc49f9..f671e68 100644
--- a/odb/processor.cxx
+++ b/odb/processor.cxx
@@ -2257,7 +2257,10 @@ namespace
// Make sure we also use the same column name as the root.
//
- m.set ("column", table_column (column_name (id)));
+ if (composite_wrapper (utype (id)))
+ m.set ("column", table_column (column_prefix (id, true).prefix));
+ else
+ m.set ("column", table_column (column_name (id)));
}
else
{
diff --git a/odb/relational/common-query.cxx b/odb/relational/common-query.cxx
index 2620e3a..0fd4c58 100644
--- a/odb/relational/common-query.cxx
+++ b/odb/relational/common-query.cxx
@@ -47,7 +47,7 @@ namespace relational
n = column_name (m, key_prefix_, default_name_, dummy);
}
- alias = compose_name (column_prefix_.prefix, n);
+ alias = column_prefix_.prefix + n;
}
generate_def (public_name (m), c, alias);
diff --git a/odb/relational/model.hxx b/odb/relational/model.hxx
index 3b53c67..b776d76 100644
--- a/odb/relational/model.hxx
+++ b/odb/relational/model.hxx
@@ -390,7 +390,7 @@ namespace relational
else if (p[p.size () - 1] == '_')
p.resize (p.size () - 1); // Remove trailing underscore.
- name = compose_name (column_prefix_.prefix, p);
+ name = column_prefix_.prefix + p;
}
model_.new_edge<sema_rel::unames> (
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index 9b23b31..dd6054a 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -294,7 +294,7 @@ namespace relational
n = column_name (m, key_prefix_, default_name_, dummy);
}
- alias = compose_name (column_prefix_.prefix, n);
+ alias = column_prefix_.prefix + n;
if (poly)
{
@@ -981,7 +981,7 @@ namespace relational
n = column_name (m, key_prefix_, default_name_, dummy);
}
- alias = compose_name (column_prefix_.prefix, n);
+ alias = column_prefix_.prefix + n;
}
semantics::class_* poly_root (polymorphic (c));