From ce03afff5ef2e8da677def73079864c31c6618d8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Jan 2013 15:10:22 +0200 Subject: Add support for mapping char[N] to CHAR/VARCHAR database types Also improve query support for arrays (decaying). --- odb/relational/mssql/context.cxx | 47 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'odb/relational/mssql/context.cxx') diff --git a/odb/relational/mssql/context.cxx b/odb/relational/mssql/context.cxx index c64ae57..d615a1c 100644 --- a/odb/relational/mssql/context.cxx +++ b/odb/relational/mssql/context.cxx @@ -30,7 +30,8 @@ namespace relational { {"bool", "BIT", 0, false}, - {"char", "TINYINT", 0, false}, + {"char", "CHAR(1)", 0, false}, + {"wchar_t", "NCHAR(1)", 0, false}, {"signed char", "TINYINT", 0, false}, {"unsigned char", "TINYINT", 0, false}, @@ -145,17 +146,57 @@ 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::array; + // Enum mapping. + // if (t.is_a ()) + { r = "INT"; + } + // char[N] mapping. + // + else if (array* a = dynamic_cast (&t)) + { + semantics::type& bt (a->base_type ()); + bool c (bt.is_a ()); + + if (c || bt.is_a ()) + { + unsigned long long n (a->size ()); + + if (n == 0) + return r; + if (n == 1) + r = c ? "CHAR(" : "NCHAR("; + else + { + r = c ? "VARCHAR(" : "NVARCHAR("; + n--; + } + + if (n > (c ? 8000 : 4000)) + r += "max)"; + else + { + ostringstream ostr; + ostr << n; + r += ostr.str (); + r += ')'; + } + } + } return r; } -- cgit v1.1