From 396cad633b6f0559a39e5111827f9b1125c67506 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Aug 2012 11:40:39 +0200 Subject: Factor out check for SQL Server long data --- odb/relational/mssql/common.cxx | 2 ++ odb/relational/mssql/common.hxx | 47 ++-------------------------------------- odb/relational/mssql/context.cxx | 46 +++++++++++++++++++++++++++++++++++++++ odb/relational/mssql/context.hxx | 5 +++++ odb/relational/mssql/source.cxx | 44 +------------------------------------ 5 files changed, 56 insertions(+), 88 deletions(-) diff --git a/odb/relational/mssql/common.cxx b/odb/relational/mssql/common.cxx index a327538..b2f982a 100644 --- a/odb/relational/mssql/common.cxx +++ b/odb/relational/mssql/common.cxx @@ -27,6 +27,8 @@ namespace relational { const sql_type& st (*mi.st); + // The same long/short data test as in context.cxx:long_data(). + // switch (st.type) { // Integral types. diff --git a/odb/relational/mssql/common.hxx b/odb/relational/mssql/common.hxx index a04c9a3..5191f3d 100644 --- a/odb/relational/mssql/common.hxx +++ b/odb/relational/mssql/common.hxx @@ -275,51 +275,8 @@ namespace relational virtual bool traverse_column (semantics::data_member& m, string const&, bool) { - sql_type const& st (parse_sql_type (column_type (), m)); - - switch (st.type) - { - case sql_type::CHAR: - case sql_type::VARCHAR: - { - // Zero precision means max in VARCHAR(max). - // - if (st.prec == 0 || st.prec > options.mssql_short_limit ()) - r_ = true; - - break; - } - case sql_type::NCHAR: - case sql_type::NVARCHAR: - { - // Zero precision means max in NVARCHAR(max). Note that - // the precision is in 2-byte UCS-2 characters, not bytes. - // - if (st.prec == 0 || st.prec * 2 > options.mssql_short_limit ()) - r_ = true; - - break; - } - case sql_type::BINARY: - case sql_type::VARBINARY: - { - // Zero precision means max in VARCHAR(max). - // - if (st.prec == 0 || st.prec > options.mssql_short_limit ()) - r_ = true; - - break; - } - case sql_type::TEXT: - case sql_type::NTEXT: - case sql_type::IMAGE: - { - r_ = true; - break; - } - default: - break; - } + if (long_data (parse_sql_type (column_type (), m))) + r_ = true; return true; } diff --git a/odb/relational/mssql/context.cxx b/odb/relational/mssql/context.cxx index c1fe9cc..efd8f2f 100644 --- a/odb/relational/mssql/context.cxx +++ b/odb/relational/mssql/context.cxx @@ -156,6 +156,52 @@ namespace relational return r; } + bool context:: + long_data (sql_type const& st) + { + bool r (false); + + // The same test as in common.cxx:traverse_simple(). + // + switch (st.type) + { + case sql_type::CHAR: + case sql_type::VARCHAR: + case sql_type::BINARY: + case sql_type::VARBINARY: + { + // Zero precision means max in VARCHAR(max). + // + if (st.prec == 0 || st.prec > options.mssql_short_limit ()) + r = true; + + break; + } + case sql_type::NCHAR: + case sql_type::NVARCHAR: + { + // Zero precision means max in NVARCHAR(max). Note that + // the precision is in 2-byte UCS-2 characters, not bytes. + // + if (st.prec == 0 || st.prec * 2 > options.mssql_short_limit ()) + r = true; + + break; + } + case sql_type::TEXT: + case sql_type::NTEXT: + case sql_type::IMAGE: + { + r = true; + break; + } + default: + break; + } + + return r; + } + // // SQL type parsing. // diff --git a/odb/relational/mssql/context.hxx b/odb/relational/mssql/context.hxx index 00bb806..ea451dc 100644 --- a/odb/relational/mssql/context.hxx +++ b/odb/relational/mssql/context.hxx @@ -94,6 +94,11 @@ namespace relational semantics::data_member&, bool custom = true); + // Return true if this type is long data. + // + bool + long_data (sql_type const&); + public: struct invalid_sql_type { diff --git a/odb/relational/mssql/source.cxx b/odb/relational/mssql/source.cxx index 866d17d..1201c87 100644 --- a/odb/relational/mssql/source.cxx +++ b/odb/relational/mssql/source.cxx @@ -746,49 +746,7 @@ namespace relational size_t n (cols.size ()); for (statement_columns::iterator i (cols.begin ()); n != 0; --n) { - sql_type const& st (parse_sql_type (i->type, *i->member)); - - bool l (false); - - // The same "short/long data" tests as in common.cxx. - // - switch (st.type) - { - case sql_type::CHAR: - case sql_type::VARCHAR: - case sql_type::BINARY: - case sql_type::VARBINARY: - { - // Zero precision means max in VARCHAR(max). - // - if (st.prec == 0 || st.prec > options.mssql_short_limit ()) - l = true; - - break; - } - case sql_type::NCHAR: - case sql_type::NVARCHAR: - { - // Zero precision means max in NVARCHAR(max). Note that - // the precision is in 2-byte UCS-2 characters, not bytes. - // - if (st.prec == 0 || st.prec * 2 > options.mssql_short_limit ()) - l = true; - - break; - } - case sql_type::TEXT: - case sql_type::NTEXT: - case sql_type::IMAGE: - { - l = true; - break; - } - default: - break; - } - - if (l) + if (long_data (parse_sql_type (i->type, *i->member))) { cols.push_back (*i); i = cols.erase (i); -- cgit v1.1