From a1638d19a9088a3488b80163afe414a5355debd9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 22 Sep 2010 18:40:58 +0200 Subject: Add database type id as value_traits template argument --- odb/mysql/query.hxx | 243 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 203 insertions(+), 40 deletions(-) (limited to 'odb/mysql/query.hxx') diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx index 5fd89ec..e0a6884 100644 --- a/odb/mysql/query.hxx +++ b/odb/mysql/query.hxx @@ -77,7 +77,7 @@ namespace odb // // - template + template struct query_column; class LIBODB_MYSQL_EXPORT query @@ -97,17 +97,17 @@ namespace odb explicit query (val_bind v) { - append::image_id> (v); + append::db_type_id> (v); } template explicit query (ref_bind r) { - append::image_id> (r); + append::db_type_id> (r); } - template + template query (const query_column&); query (const query&); @@ -157,7 +157,7 @@ namespace odb query& operator+= (val_bind v) { - append::image_id> (v); + append::db_type_id> (v); return *this; } @@ -165,16 +165,16 @@ namespace odb query& operator+= (ref_bind r) { - append::image_id> (r); + append::db_type_id> (r); return *this; } public: - template + template void append (val_bind); - template + template void append (ref_bind); @@ -338,7 +338,7 @@ namespace odb const T& type_instance (); - template + template struct query_column { explicit @@ -904,9 +904,9 @@ namespace odb // Column comparison. // public: - template + template query - operator== (const query_column& c) const + operator== (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -918,9 +918,9 @@ namespace odb return q; } - template + template query - operator!= (const query_column& c) const + operator!= (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -932,9 +932,9 @@ namespace odb return q; } - template + template query - operator< (const query_column& c) const + operator< (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -946,9 +946,9 @@ namespace odb return q; } - template + template query - operator> (const query_column& c) const + operator> (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -960,9 +960,9 @@ namespace odb return q; } - template + template query - operator<= (const query_column& c) const + operator<= (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -974,9 +974,9 @@ namespace odb return q; } - template + template query - operator>= (const query_column& c) const + operator>= (const query_column& c) const { // We can compare columns only if we can compare their C++ types. // @@ -994,7 +994,7 @@ namespace odb // // - template + template struct query_param_impl; // TINY @@ -1024,7 +1024,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1056,7 +1056,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1090,7 +1090,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1122,7 +1122,8 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image ( + image_, dummy, v); } private: @@ -1156,7 +1157,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1188,7 +1189,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1222,7 +1223,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1254,7 +1255,8 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image ( + image_, dummy, v); } private: @@ -1288,7 +1290,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1322,13 +1324,52 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: double image_; }; + // DECIMAL + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (&r.ref) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual void + init () + { + init (*static_cast (value_)); + } + + virtual void + bind (MYSQL_BIND* b) + { + b->buffer_type = MYSQL_TYPE_NEWDECIMAL; + b->buffer = buffer_.data (); + b->buffer_length = static_cast (buffer_.capacity ()); + b->length = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size; + value_traits::set_image ( + buffer_, size, dummy, v); + size_ = static_cast (size); + } + + private: + details::buffer buffer_; + unsigned long size_; + }; + // DATE // template @@ -1355,7 +1396,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1388,7 +1429,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1421,7 +1462,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1454,7 +1495,8 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image ( + image_, dummy, v); } private: @@ -1488,7 +1530,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1524,7 +1566,8 @@ namespace odb { bool dummy; std::size_t size; - value_traits::set_image (buffer_, size, dummy, v); + value_traits::set_image ( + buffer_, size, dummy, v); size_ = static_cast (size); } @@ -1562,7 +1605,127 @@ namespace odb { bool dummy; std::size_t size; - value_traits::set_image (buffer_, size, dummy, v); + value_traits::set_image ( + buffer_, size, dummy, v); + size_ = static_cast (size); + } + + private: + details::buffer buffer_; + unsigned long size_; + }; + + // BIT + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (&r.ref) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual void + init () + { + init (*static_cast (value_)); + } + + virtual void + bind (MYSQL_BIND* b) + { + b->buffer_type = MYSQL_TYPE_BLOB; + b->buffer = buffer_; + b->buffer_length = static_cast (sizeof (buffer_)); + b->length = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size; + value_traits::set_image ( + buffer_, sizeof (buffer_), size, dummy, v); + size_ = static_cast (size); + } + + private: + // Max 64 bit. + // + unsigned char buffer_[8]; + unsigned long size_; + }; + + // ENUM + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (&r.ref) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual void + init () + { + init (*static_cast (value_)); + } + + virtual void + bind (MYSQL_BIND* b) + { + b->buffer_type = MYSQL_TYPE_STRING; + b->buffer = buffer_.data (); + b->buffer_length = static_cast (buffer_.capacity ()); + b->length = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size; + value_traits::set_image ( + buffer_, size, dummy, v); + size_ = static_cast (size); + } + + private: + details::buffer buffer_; + unsigned long size_; + }; + + // SET + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (&r.ref) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual void + init () + { + init (*static_cast (value_)); + } + + virtual void + bind (MYSQL_BIND* b) + { + b->buffer_type = MYSQL_TYPE_STRING; + b->buffer = buffer_.data (); + b->buffer_length = static_cast (buffer_.capacity ()); + b->length = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size; + value_traits::set_image ( + buffer_, size, dummy, v); size_ = static_cast (size); } @@ -1614,7 +1777,7 @@ namespace odb { } - template + template query (const mysql::query_column& qc) : object_traits::query_type (qc) { -- cgit v1.1