summaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-19 17:55:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-19 17:55:24 +0200
commit92b705cd0de55091bba8186b8598cb226c7e74b9 (patch)
tree28c8b62253f6011e25d3060d3c8ef9cadff7837a /odb
parent53d846e0c6ce605c3bce5c902829e0c0ce70e444 (diff)
Map only continuous, zero-based enums to MySQL ENUM
The others map to INT.
Diffstat (limited to 'odb')
-rw-r--r--odb/relational/mysql/context.cxx53
1 files changed, 39 insertions, 14 deletions
diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx
index b413b85..4e31361 100644
--- a/odb/relational/mysql/context.cxx
+++ b/odb/relational/mysql/context.cxx
@@ -242,29 +242,54 @@ namespace relational
return r;
using semantics::enum_;
+ using semantics::enumerator;
if (enum_* e = dynamic_cast<enum_*> (&t))
{
- enum_::enumerates_iterator b (e->enumerates_begin ()),
- end (e->enumerates_end ());
-
- if (b != end)
+ // We can only map to ENUM if the C++ enumeration is contiguous
+ // and starts with 0.
+ //
+ if (e->unsigned_ ())
{
- r += "ENUM (";
- for (enum_::enumerates_iterator i (b); i != end; ++i)
+ enum_::enumerates_iterator i (e->enumerates_begin ()),
+ end (e->enumerates_end ());
+
+ if (i != end)
{
- if (i != b)
- r += ", ";
+ r += "ENUM (";
+
+ for (unsigned long long j (0); i != end; ++i, ++j)
+ {
+ enumerator const& er (i->enumerator ());
+
+ if (er.value () != j)
+ break;
+
+ if (j != 0)
+ r += ", ";
- r += '\'';
- r += i->enumerator ().name ();
- r += '\'';
+ r += '\'';
+ r += er.name ();
+ r += '\'';
+ }
+
+ if (i == end)
+ r += ")";
+ else
+ r.clear ();
}
- r += ")";
+ }
- if ((f & ctf_default_null) == 0)
- r += " NOT NULL";
+ if (r.empty ())
+ {
+ r = "INT";
+
+ if (e->unsigned_ ())
+ r += " UNSIGNED";
}
+
+ if ((f & ctf_default_null) == 0)
+ r += " NOT NULL";
}
return r;