diff options
Diffstat (limited to 'odb/mysql/query.hxx')
-rw-r--r-- | odb/mysql/query.hxx | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx index c0f812a..732244c 100644 --- a/odb/mysql/query.hxx +++ b/odb/mysql/query.hxx @@ -24,6 +24,7 @@ #include <odb/details/shared-ptr.hxx> #include <odb/mysql/details/export.hxx> +#include <odb/mysql/details/conversion.hxx> namespace odb { @@ -99,7 +100,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; }; @@ -142,7 +143,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> @@ -150,7 +152,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> @@ -221,7 +224,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; } @@ -229,18 +233,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); @@ -250,7 +255,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; @@ -391,10 +396,11 @@ 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 shallow copies of the table, column, and conversion + // expression. The latter can be NULL. // - query_column (const char* table, const char* column) - : table_ (table), column_ (column) + query_column (const char* table, const char* column, const char* conv) + : table_ (table), column_ (column), conversion_ (conv) { } @@ -410,6 +416,14 @@ namespace odb return column_; } + // Can be NULL. + // + const char* + conversion () const + { + return conversion_; + } + // is_null, is_not_null // public: @@ -462,7 +476,7 @@ namespace odb { query q (table_, column_); q += "="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -479,7 +493,7 @@ namespace odb { query q (table_, column_); q += "="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -547,7 +561,7 @@ namespace odb { query q (table_, column_); q += "!="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -564,7 +578,7 @@ namespace odb { query q (table_, column_); q += "!="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -632,7 +646,7 @@ namespace odb { query q (table_, column_); q += "<"; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -649,7 +663,7 @@ namespace odb { query q (table_, column_); q += "<"; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -717,7 +731,7 @@ namespace odb { query q (table_, column_); q += ">"; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -734,7 +748,7 @@ namespace odb { query q (table_, column_); q += ">"; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -802,7 +816,7 @@ namespace odb { query q (table_, column_); q += "<="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -819,7 +833,7 @@ namespace odb { query q (table_, column_); q += "<="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -887,7 +901,7 @@ namespace odb { query q (table_, column_); q += ">="; - q.append<T, ID> (v); + q.append<T, ID> (v, conversion_); return q; } @@ -904,7 +918,7 @@ namespace odb { query q (table_, column_); q += ">="; - q.append<T, ID> (r); + q.append<T, ID> (r, conversion_); return q; } @@ -1048,6 +1062,7 @@ namespace odb private: const char* table_; const char* column_; + const char* conversion_; }; // Provide operator+() for using columns to construct native |