diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-10 15:17:12 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-10 15:17:12 +0200 |
commit | f3f9389365a03603c6f9bcc4d502ff4049c72fe2 (patch) | |
tree | ef7bfa4d1c2791e5bc3365649552b12c6820a1d8 /odb/mssql/query.hxx | |
parent | 7ed3669ac5c5efb5cc05ee777ed0ca1f52f0e69d (diff) |
Add support for custom database type mapping
New pragma qualifier, map, and specifiers: as, to, from. New tests:
<database>/custom.
Diffstat (limited to 'odb/mssql/query.hxx')
-rw-r--r-- | odb/mssql/query.hxx | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/odb/mssql/query.hxx b/odb/mssql/query.hxx index 5b5ea57..4844463 100644 --- a/odb/mssql/query.hxx +++ b/odb/mssql/query.hxx @@ -24,6 +24,7 @@ #include <odb/details/shared-ptr.hxx> #include <odb/mssql/details/export.hxx> +#include <odb/mssql/details/conversion.hxx> namespace odb { @@ -121,7 +122,7 @@ namespace odb clause_part (bool p): kind (boolean), bool_part (p) {} kind_type kind; - std::string part; + std::string part; // If kind is param, then part is conversion expr. bool bool_part; }; @@ -164,7 +165,8 @@ namespace odb query (val_bind<T> v) : binding_ (0, 0) { - append<T, type_traits<T>::db_type_id> (v); + append<T, type_traits<T>::db_type_id> ( + v, details::conversion<T>::to ()); } template <typename T> @@ -172,7 +174,8 @@ namespace odb query (ref_bind<T> r) : binding_ (0, 0) { - append<T, type_traits<T>::db_type_id> (r); + append<T, type_traits<T>::db_type_id> ( + r, details::conversion<T>::to ()); } template <database_type_id ID> @@ -243,7 +246,8 @@ namespace odb query& operator+= (val_bind<T> v) { - append<T, type_traits<T>::db_type_id> (v); + append<T, type_traits<T>::db_type_id> ( + v, details::conversion<T>::to ()); return *this; } @@ -251,18 +255,19 @@ namespace odb query& operator+= (ref_bind<T> r) { - append<T, type_traits<T>::db_type_id> (r); + append<T, type_traits<T>::db_type_id> ( + r, details::conversion<T>::to ()); return *this; } public: template <typename T, database_type_id ID> void - append (val_bind<T>); + append (val_bind<T>, const char* conv); template <typename T, database_type_id ID> void - append (ref_bind<T>); + append (ref_bind<T>, const char* conv); void append (const std::string& native); @@ -272,7 +277,7 @@ namespace odb private: void - add (details::shared_ptr<query_param>); + add (details::shared_ptr<query_param>, const char* conv); private: typedef std::vector<clause_part> clause_type; @@ -413,13 +418,16 @@ namespace odb template <typename T, database_type_id ID> struct query_column { - // Note that we keep shalow copies of the table and column names. + // Note that we keep shalow copies of the table, column, and conversion + // expression. The latter can be NULL. // query_column (const char* table, const char* column, + const char* conv, unsigned short prec = 0, unsigned short scale = 0xFFFF) - : table_ (table), column_ (column), prec_ (prec), scale_ (scale) + : table_ (table), column_ (column), conversion_ (conv), + prec_ (prec), scale_ (scale) { } @@ -435,6 +443,14 @@ namespace odb return column_; } + // Can be NULL. + // + const char* + conversion () const + { + return conversion_; + } + unsigned short prec () const { @@ -502,7 +518,7 @@ namespace odb query q (table_, column_); q += "="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -522,7 +538,7 @@ namespace odb query q (table_, column_); q += "="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -593,7 +609,7 @@ namespace odb query q (table_, column_); q += "!="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -613,7 +629,7 @@ namespace odb query q (table_, column_); q += "!="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -684,7 +700,7 @@ namespace odb query q (table_, column_); q += "<"; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -704,7 +720,7 @@ namespace odb query q (table_, column_); q += "<"; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -775,7 +791,7 @@ namespace odb query q (table_, column_); q += ">"; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -795,7 +811,7 @@ namespace odb query q (table_, column_); q += ">"; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -866,7 +882,7 @@ namespace odb query q (table_, column_); q += "<="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -886,7 +902,7 @@ namespace odb query q (table_, column_); q += "<="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -957,7 +973,7 @@ namespace odb query q (table_, column_); q += ">="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -977,7 +993,7 @@ namespace odb query q (table_, column_); q += ">="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -1121,6 +1137,7 @@ namespace odb private: const char* table_; const char* column_; + const char* conversion_; unsigned short prec_; unsigned short scale_; |