From b904af7d7a716d243fb73e75b4a1cc404c9455f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2011 18:50:04 +0200 Subject: Implement automatic mapping for C++ enums --- odb/relational/mysql/context.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'odb/relational/mysql/context.cxx') diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index 11b5290..b413b85 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -230,6 +230,46 @@ namespace relational return r; } + string context:: + database_type_impl (semantics::type& t, + string const& type, + semantics::context& ctx, + column_type_flags f) + { + string r (base_context::database_type_impl (t, type, ctx, f)); + + if (!r.empty ()) + return r; + + using semantics::enum_; + + if (enum_* e = dynamic_cast (&t)) + { + enum_::enumerates_iterator b (e->enumerates_begin ()), + end (e->enumerates_end ()); + + if (b != end) + { + r += "ENUM ("; + for (enum_::enumerates_iterator i (b); i != end; ++i) + { + if (i != b) + r += ", "; + + r += '\''; + r += i->enumerator ().name (); + r += '\''; + } + r += ")"; + + if ((f & ctf_default_null) == 0) + r += " NOT NULL"; + } + } + + return r; + } + // // SQL type parsing. // -- cgit v1.1