From 4cde011f27cd406804f05aa8fd1d28ed91a26738 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 1 Aug 2012 11:16:20 +0200 Subject: Add support for empty column names in composite value types --- odb/context.cxx | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'odb/context.cxx') diff --git a/odb/context.cxx b/odb/context.cxx index 8335ec4..df94dfb 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -897,7 +897,7 @@ column_name (data_member_path const& mp) const if (composite_wrapper (utype (m))) r += object_columns_base::column_prefix (m); else - r += column_name (m); + r = compose_name (r, column_name (m)); } return r; @@ -928,6 +928,34 @@ column_name (semantics::data_member& m, string const& p, string const& d) const } string context:: +compose_name (string const& prefix, string const& name) +{ + string r (prefix); + size_t n (r.size ()); + + // Add an underscore unless one is already in the prefix or + // the name is empty. Similarly, remove it if it is there but + // the name is empty. + // + if (n != 0) + { + if (r[n - 1] != '_') + { + if (!name.empty ()) + r += '_'; + } + else + { + if (name.empty ()) + r.resize (n - 1); + } + } + + r += name; + return r; +} + +string context:: column_type (const data_member_path& mp, string const& kp, bool id) { if (kp.empty ()) -- cgit v1.1