summaryrefslogtreecommitdiff
path: root/odb/relational/mysql/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-18 18:50:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-19 08:39:02 +0200
commitb904af7d7a716d243fb73e75b4a1cc404c9455f3 (patch)
tree75bfb4f9773623a50c6dcd4d6bdec53b0efba128 /odb/relational/mysql/context.cxx
parentcdb791febe6c9ab2cfa36b1a07dfc71548674cf1 (diff)
Implement automatic mapping for C++ enums
Diffstat (limited to 'odb/relational/mysql/context.cxx')
-rw-r--r--odb/relational/mysql/context.cxx40
1 files changed, 40 insertions, 0 deletions
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<enum_*> (&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.
//