From 1568e64c2135bf245de960ae614bd3533c6d157a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Jul 2012 15:17:14 +0200 Subject: Add support for custom database type mapping New pragma qualifier, map, and specifiers: as, to, from. New tests: /custom. --- odb/sqlite/query.hxx | 62 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'odb/sqlite/query.hxx') diff --git a/odb/sqlite/query.hxx b/odb/sqlite/query.hxx index 54e0b2b..ee05feb 100644 --- a/odb/sqlite/query.hxx +++ b/odb/sqlite/query.hxx @@ -20,7 +20,9 @@ #include #include #include + #include +#include namespace odb { @@ -129,7 +131,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; }; @@ -172,7 +174,8 @@ namespace odb query (val_bind v) : parameters_ (new (details::shared) query_params) { - append::db_type_id> (v); + append::db_type_id> ( + v, details::conversion::to ()); } template @@ -180,7 +183,8 @@ namespace odb query (ref_bind r) : parameters_ (new (details::shared) query_params) { - append::db_type_id> (r); + append::db_type_id> ( + r, details::conversion::to ()); } template @@ -254,7 +258,8 @@ namespace odb query& operator+= (val_bind v) { - append::db_type_id> (v); + append::db_type_id> ( + v, details::conversion::to ()); return *this; } @@ -262,18 +267,19 @@ namespace odb query& operator+= (ref_bind r) { - append::db_type_id> (r); + append::db_type_id> ( + r, details::conversion::to ()); return *this; } public: template void - append (val_bind); + append (val_bind, const char* conv); template void - append (ref_bind); + append (ref_bind, const char* conv); void append (const std::string& native); @@ -283,7 +289,7 @@ namespace odb private: void - add (details::shared_ptr); + add (details::shared_ptr, const char* conv); private: typedef std::vector clause_type; @@ -421,10 +427,11 @@ namespace odb template 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) { } @@ -440,6 +447,14 @@ namespace odb return column_; } + // Can be NULL. + // + const char* + conversion () const + { + return conversion_; + } + // is_null, is_not_null // public: @@ -492,7 +507,7 @@ namespace odb { query q (table_, column_); q += "="; - q.append (v); + q.append (v, conversion_); return q; } @@ -509,7 +524,7 @@ namespace odb { query q (table_, column_); q += "="; - q.append (r); + q.append (r, conversion_); return q; } @@ -577,7 +592,7 @@ namespace odb { query q (table_, column_); q += "!="; - q.append (v); + q.append (v, conversion_); return q; } @@ -594,7 +609,7 @@ namespace odb { query q (table_, column_); q += "!="; - q.append (r); + q.append (r, conversion_); return q; } @@ -662,7 +677,7 @@ namespace odb { query q (table_, column_); q += "<"; - q.append (v); + q.append (v, conversion_); return q; } @@ -679,7 +694,7 @@ namespace odb { query q (table_, column_); q += "<"; - q.append (r); + q.append (r, conversion_); return q; } @@ -747,7 +762,7 @@ namespace odb { query q (table_, column_); q += ">"; - q.append (v); + q.append (v, conversion_); return q; } @@ -764,7 +779,7 @@ namespace odb { query q (table_, column_); q += ">"; - q.append (r); + q.append (r, conversion_); return q; } @@ -832,7 +847,7 @@ namespace odb { query q (table_, column_); q += "<="; - q.append (v); + q.append (v, conversion_); return q; } @@ -849,7 +864,7 @@ namespace odb { query q (table_, column_); q += "<="; - q.append (r); + q.append (r, conversion_); return q; } @@ -917,7 +932,7 @@ namespace odb { query q (table_, column_); q += ">="; - q.append (v); + q.append (v, conversion_); return q; } @@ -934,7 +949,7 @@ namespace odb { query q (table_, column_); q += ">="; - q.append (r); + q.append (r, conversion_); return q; } @@ -1078,6 +1093,7 @@ namespace odb private: const char* table_; const char* column_; + const char* conversion_; }; // Provide operator+() for using columns to construct native -- cgit v1.1