diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-24 15:10:22 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-24 15:10:22 +0200 |
commit | ce03afff5ef2e8da677def73079864c31c6618d8 (patch) | |
tree | f0dd5ace26fcfb5c16dee9930a70cf274a80cfc0 /odb/relational/mysql | |
parent | 7c9d4543838490670b632c7049bea53d58d78487 (diff) |
Add support for mapping char[N] to CHAR/VARCHAR database types
Also improve query support for arrays (decaying).
Diffstat (limited to 'odb/relational/mysql')
-rw-r--r-- | odb/relational/mysql/context.cxx | 37 | ||||
-rw-r--r-- | odb/relational/mysql/context.hxx | 2 |
2 files changed, 35 insertions, 4 deletions
diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index ba22733..4045f9c 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -31,7 +31,7 @@ namespace relational { {"bool", "TINYINT(1)", 0, false}, - {"char", "TINYINT", 0, false}, + {"char", "CHAR(1)", 0, false}, {"signed char", "TINYINT", 0, false}, {"unsigned char", "TINYINT UNSIGNED", 0, false}, @@ -269,16 +269,22 @@ namespace relational } string context:: - database_type_impl (semantics::type& t, semantics::names* hint, bool id) + database_type_impl (semantics::type& t, + semantics::names* hint, + bool id, + bool* null) { - string r (base_context::database_type_impl (t, hint, id)); + string r (base_context::database_type_impl (t, hint, id, null)); if (!r.empty ()) return r; using semantics::enum_; using semantics::enumerator; + using semantics::array; + // Enum mapping. + // if (enum_* e = dynamic_cast<enum_*> (&t)) { // We can only map to ENUM if the C++ enumeration is contiguous @@ -321,6 +327,31 @@ namespace relational r += " UNSIGNED"; } } + // char[N] mapping. + // + else if (array* a = dynamic_cast<array*> (&t)) + { + semantics::type& bt (a->base_type ()); + if (bt.is_a<semantics::fund_char> ()) + { + unsigned long long n (a->size ()); + + if (n == 0) + return r; + else if (n == 1) + r = "CHAR("; + else + { + r = "VARCHAR("; + n--; + } + + ostringstream ostr; + ostr << n; + r += ostr.str (); + r += ')'; + } + } return r; } diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index 0d76b04..fdcc8f6 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -127,7 +127,7 @@ namespace relational protected: virtual string - database_type_impl (semantics::type&, semantics::names*, bool); + database_type_impl (semantics::type&, semantics::names*, bool, bool*); public: virtual |