| query.hxx | | query.hxx | |
| | | | |
| skipping to change at line 92 | | skipping to change at line 92 | |
| }; | | }; | |
| | | | |
| // | | // | |
| // | | // | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| struct query_column; | | struct query_column; | |
| | | | |
| class LIBODB_PGSQL_EXPORT query | | class LIBODB_PGSQL_EXPORT query | |
| { | | { | |
| public: | | public: | |
|
| | | struct clause_part | |
| | | { | |
| | | enum kind_type | |
| | | { | |
| | | column, | |
| | | param, | |
| | | native, | |
| | | boolean | |
| | | }; | |
| | | | |
| | | clause_part (kind_type k): kind (k) {} | |
| | | clause_part (kind_type k, const std::string& p): kind (k), part (p) | |
| | | {} | |
| | | clause_part (bool p): kind (boolean), bool_part (p) {} | |
| | | | |
| | | kind_type kind; | |
| | | std::string part; | |
| | | bool bool_part; | |
| | | }; | |
| | | | |
| query () | | query () | |
| : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| { | | { | |
| } | | } | |
| | | | |
|
| | | // True or false literal. | |
| | | // | |
| | | explicit | |
| | | query (bool v) | |
| | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| | | { | |
| | | clause_.push_back (clause_part (v)); | |
| | | } | |
| | | | |
| explicit | | explicit | |
|
| query (const std::string& q) | | query (const char* native) | |
| : clause_ (q), binding_ (0, 0), native_binding_ (0, 0, 0, 0) | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| { | | { | |
|
| | | clause_.push_back (clause_part (clause_part::native, native)); | |
| | | } | |
| | | | |
| | | explicit | |
| | | query (const std::string& native) | |
| | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| | | { | |
| | | clause_.push_back (clause_part (clause_part::native, native)); | |
| | | } | |
| | | | |
| | | query (const char* table, const char* column) | |
| | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| | | { | |
| | | append (table, column); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| explicit | | explicit | |
| query (val_bind<T> v) | | query (val_bind<T> v) | |
| : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| { | | { | |
| append<T, type_traits<T>::db_type_id> (v); | | append<T, type_traits<T>::db_type_id> (v); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 131 | | skipping to change at line 173 | |
| | | | |
| query (const query&); | | query (const query&); | |
| | | | |
| query& | | query& | |
| operator= (const query&); | | operator= (const query&); | |
| | | | |
| public: | | public: | |
| std::string | | std::string | |
| clause () const; | | clause () const; | |
| | | | |
|
| | | const char* | |
| | | clause_prefix () const; | |
| | | | |
| native_binding& | | native_binding& | |
| parameters_binding () const; | | parameters_binding () const; | |
| | | | |
| const unsigned int* | | const unsigned int* | |
| parameter_types () const | | parameter_types () const | |
| { | | { | |
| return types_.empty () ? 0 : &types_[0]; | | return types_.empty () ? 0 : &types_[0]; | |
| } | | } | |
| | | | |
| std::size_t | | std::size_t | |
| parameter_count () const | | parameter_count () const | |
| { | | { | |
| return parameters_.size (); | | return parameters_.size (); | |
| } | | } | |
| | | | |
| public: | | public: | |
|
| | | bool | |
| | | empty () const | |
| | | { | |
| | | return clause_.empty (); | |
| | | } | |
| | | | |
| | | static const query true_expr; | |
| | | | |
| | | bool | |
| | | const_true () const | |
| | | { | |
| | | return clause_.size () == 1 && | |
| | | clause_.front ().kind == clause_part::boolean && | |
| | | clause_.front ().bool_part; | |
| | | } | |
| | | | |
| | | void | |
| | | optimize (); | |
| | | | |
| | | public: | |
| template <typename T> | | template <typename T> | |
| static val_bind<T> | | static val_bind<T> | |
| _val (const T& x) | | _val (const T& x) | |
| { | | { | |
| return val_bind<T> (x); | | return val_bind<T> (x); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| static ref_bind<T> | | static ref_bind<T> | |
| _ref (const T& x) | | _ref (const T& x) | |
| | | | |
| skipping to change at line 168 | | skipping to change at line 233 | |
| return ref_bind<T> (x); | | return ref_bind<T> (x); | |
| } | | } | |
| | | | |
| public: | | public: | |
| query& | | query& | |
| operator+= (const query&); | | operator+= (const query&); | |
| | | | |
| query& | | query& | |
| operator+= (const std::string& q) | | operator+= (const std::string& q) | |
| { | | { | |
|
| size_t n (clause_.size ()); | | append (q); | |
| | | | |
| if (n != 0 && clause_[n - 1] != ' ' && !q.empty () && q[0] != ' ') | | | |
| clause_ += ' '; | | | |
| | | | |
| clause_ += q; | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| query& | | query& | |
| operator+= (val_bind<T> v) | | operator+= (val_bind<T> v) | |
| { | | { | |
| append<T, type_traits<T>::db_type_id> (v); | | append<T, type_traits<T>::db_type_id> (v); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| skipping to change at line 202 | | skipping to change at line 262 | |
| | | | |
| public: | | public: | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| void | | void | |
| append (val_bind<T>); | | append (val_bind<T>); | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| void | | void | |
| append (ref_bind<T>); | | append (ref_bind<T>); | |
| | | | |
|
| | | void | |
| | | append (const std::string& native); | |
| | | | |
| | | void | |
| | | append (const char* table, const char* column); | |
| | | | |
| private: | | private: | |
| void | | void | |
| add (details::shared_ptr<query_param>); | | add (details::shared_ptr<query_param>); | |
| | | | |
| private: | | private: | |
|
| | | typedef std::vector<clause_part> clause_type; | |
| typedef std::vector<details::shared_ptr<query_param> > parameters_typ
e; | | typedef std::vector<details::shared_ptr<query_param> > parameters_typ
e; | |
| | | | |
|
| std::string clause_; | | clause_type clause_; | |
| parameters_type parameters_; | | parameters_type parameters_; | |
| | | | |
|
| typedef std::pair<std::size_t, std::size_t> parameter_offset; | | | |
| std::vector<parameter_offset> parameter_offsets_; | | | |
| | | | |
| mutable std::vector<bind> bind_; | | mutable std::vector<bind> bind_; | |
| mutable binding binding_; | | mutable binding binding_; | |
| | | | |
| std::vector<char*> values_; | | std::vector<char*> values_; | |
| std::vector<int> lengths_; | | std::vector<int> lengths_; | |
| std::vector<int> formats_; | | std::vector<int> formats_; | |
| std::vector<unsigned int> types_; | | std::vector<unsigned int> types_; | |
| mutable native_binding native_binding_; | | mutable native_binding native_binding_; | |
| }; | | }; | |
| | | | |
| | | | |
| skipping to change at line 325 | | skipping to change at line 389 | |
| template <typename T> | | template <typename T> | |
| inline query | | inline query | |
| operator+ (ref_bind<T> b, const std::string& s) | | operator+ (ref_bind<T> b, const std::string& s) | |
| { | | { | |
| query r; | | query r; | |
| r += b; | | r += b; | |
| r += s; | | r += s; | |
| return r; | | return r; | |
| } | | } | |
| | | | |
|
| inline query | | LIBODB_PGSQL_EXPORT query | |
| operator&& (const query& x, const query& y) | | operator&& (const query&, const query&); | |
| { | | | |
| query r ("("); | | | |
| r += x; | | | |
| r += ") AND ("; | | | |
| r += y; | | | |
| r += ")"; | | | |
| return r; | | | |
| } | | | |
| | | | |
|
| inline query | | LIBODB_PGSQL_EXPORT query | |
| operator|| (const query& x, const query& y) | | operator|| (const query&, const query&); | |
| { | | | |
| query r ("("); | | | |
| r += x; | | | |
| r += ") OR ("; | | | |
| r += y; | | | |
| r += ")"; | | | |
| return r; | | | |
| } | | | |
| | | | |
|
| inline query | | LIBODB_PGSQL_EXPORT query | |
| operator! (const query& x) | | operator! (const query&); | |
| { | | | |
| query r ("NOT ("); | | | |
| r += x; | | | |
| r += ")"; | | | |
| return r; | | | |
| } | | | |
| | | | |
| // query_column | | // query_column | |
| // | | // | |
| | | | |
| template <typename T, typename T2> | | template <typename T, typename T2> | |
| class copy_bind: public val_bind<T> | | class copy_bind: public val_bind<T> | |
| { | | { | |
| public: | | public: | |
| explicit | | explicit | |
| copy_bind (const T2& v): val_bind<T> (val), val (v) {} | | copy_bind (const T2& v): val_bind<T> (val), val (v) {} | |
| | | | |
| skipping to change at line 376 | | skipping to change at line 418 | |
| const T val; | | const T val; | |
| }; | | }; | |
| | | | |
| template <typename T> | | template <typename T> | |
| const T& | | const T& | |
| type_instance (); | | type_instance (); | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| struct query_column | | struct query_column | |
| { | | { | |
|
| explicit | | // Note that we keep shalow copies of the table and column names. | |
| query_column (const char* name) | | // | |
| : name_ (name) | | query_column (const char* table, const char* column) | |
| | | : table_ (table), column_ (column) | |
| { | | { | |
| } | | } | |
| | | | |
| const char* | | const char* | |
|
| name () const | | table () const | |
| { | | { | |
|
| return name_; | | return table_; | |
| | | } | |
| | | | |
| | | const char* | |
| | | column () const | |
| | | { | |
| | | return column_; | |
| } | | } | |
| | | | |
| // is_null, is_not_null | | // is_null, is_not_null | |
| // | | // | |
| public: | | public: | |
| query | | query | |
| is_null () const | | is_null () const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IS NULL"; | | q += "IS NULL"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| query | | query | |
| is_not_null () const | | is_not_null () const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IS NOT NULL"; | | q += "IS NOT NULL"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| // in | | // in | |
| // | | // | |
| public: | | public: | |
| query | | query | |
| in (const T&, const T&) const; | | in (const T&, const T&) const; | |
| | | | |
| | | | |
| skipping to change at line 438 | | skipping to change at line 487 | |
| public: | | public: | |
| query | | query | |
| equal (const T& v) const | | equal (const T& v) const | |
| { | | { | |
| return equal (val_bind<T> (v)); | | return equal (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| equal (val_bind<T> v) const | | equal (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "="; | | q += "="; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| equal (val_bind<T2> v) const | | equal (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return equal (c); | | return equal (c); | |
| } | | } | |
| | | | |
| query | | query | |
| equal (ref_bind<T> r) const | | equal (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "="; | | q += "="; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator== (const query_column& c, const T& v) | | operator== (const query_column& c, const T& v) | |
| { | | { | |
| return c.equal (v); | | return c.equal (v); | |
| } | | } | |
| | | | |
| skipping to change at line 523 | | skipping to change at line 572 | |
| public: | | public: | |
| query | | query | |
| unequal (const T& v) const | | unequal (const T& v) const | |
| { | | { | |
| return unequal (val_bind<T> (v)); | | return unequal (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| unequal (val_bind<T> v) const | | unequal (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "!="; | | q += "!="; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| unequal (val_bind<T2> v) const | | unequal (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return unequal (c); | | return unequal (c); | |
| } | | } | |
| | | | |
| query | | query | |
| unequal (ref_bind<T> r) const | | unequal (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "!="; | | q += "!="; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator!= (const query_column& c, const T& v) | | operator!= (const query_column& c, const T& v) | |
| { | | { | |
| return c.unequal (v); | | return c.unequal (v); | |
| } | | } | |
| | | | |
| skipping to change at line 608 | | skipping to change at line 657 | |
| public: | | public: | |
| query | | query | |
| less (const T& v) const | | less (const T& v) const | |
| { | | { | |
| return less (val_bind<T> (v)); | | return less (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| less (val_bind<T> v) const | | less (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<"; | | q += "<"; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| less (val_bind<T2> v) const | | less (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return less (c); | | return less (c); | |
| } | | } | |
| | | | |
| query | | query | |
| less (ref_bind<T> r) const | | less (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<"; | | q += "<"; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator< (const query_column& c, const T& v) | | operator< (const query_column& c, const T& v) | |
| { | | { | |
| return c.less (v); | | return c.less (v); | |
| } | | } | |
| | | | |
| skipping to change at line 693 | | skipping to change at line 742 | |
| public: | | public: | |
| query | | query | |
| greater (const T& v) const | | greater (const T& v) const | |
| { | | { | |
| return greater (val_bind<T> (v)); | | return greater (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| greater (val_bind<T> v) const | | greater (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">"; | | q += ">"; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| greater (val_bind<T2> v) const | | greater (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return greater (c); | | return greater (c); | |
| } | | } | |
| | | | |
| query | | query | |
| greater (ref_bind<T> r) const | | greater (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">"; | | q += ">"; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator> (const query_column& c, const T& v) | | operator> (const query_column& c, const T& v) | |
| { | | { | |
| return c.greater (v); | | return c.greater (v); | |
| } | | } | |
| | | | |
| skipping to change at line 778 | | skipping to change at line 827 | |
| public: | | public: | |
| query | | query | |
| less_equal (const T& v) const | | less_equal (const T& v) const | |
| { | | { | |
| return less_equal (val_bind<T> (v)); | | return less_equal (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| less_equal (val_bind<T> v) const | | less_equal (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<="; | | q += "<="; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| less_equal (val_bind<T2> v) const | | less_equal (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return less_equal (c); | | return less_equal (c); | |
| } | | } | |
| | | | |
| query | | query | |
| less_equal (ref_bind<T> r) const | | less_equal (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<="; | | q += "<="; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator<= (const query_column& c, const T& v) | | operator<= (const query_column& c, const T& v) | |
| { | | { | |
| return c.less_equal (v); | | return c.less_equal (v); | |
| } | | } | |
| | | | |
| skipping to change at line 863 | | skipping to change at line 912 | |
| public: | | public: | |
| query | | query | |
| greater_equal (const T& v) const | | greater_equal (const T& v) const | |
| { | | { | |
| return greater_equal (val_bind<T> (v)); | | return greater_equal (val_bind<T> (v)); | |
| } | | } | |
| | | | |
| query | | query | |
| greater_equal (val_bind<T> v) const | | greater_equal (val_bind<T> v) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
| q.append<T, ID> (v); | | q.append<T, ID> (v); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| query | | query | |
| greater_equal (val_bind<T2> v) const | | greater_equal (val_bind<T2> v) const | |
| { | | { | |
| copy_bind<T, T2> c (v.val); | | copy_bind<T, T2> c (v.val); | |
| return greater_equal (c); | | return greater_equal (c); | |
| } | | } | |
| | | | |
| query | | query | |
| greater_equal (ref_bind<T> r) const | | greater_equal (ref_bind<T> r) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
| q.append<T, ID> (r); | | q.append<T, ID> (r); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| operator>= (const query_column& c, const T& v) | | operator>= (const query_column& c, const T& v) | |
| { | | { | |
| return c.greater_equal (v); | | return c.greater_equal (v); | |
| } | | } | |
| | | | |
| skipping to change at line 947 | | skipping to change at line 996 | |
| // | | // | |
| public: | | public: | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator== (const query_column<T2, ID2>& c) const | | operator== (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () == type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () == type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "="; | | q += "="; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator!= (const query_column<T2, ID2>& c) const | | operator!= (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () != type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () != type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "!="; | | q += "!="; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator< (const query_column<T2, ID2>& c) const | | operator< (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () < type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () < type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<"; | | q += "<"; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator> (const query_column<T2, ID2>& c) const | | operator> (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () > type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () > type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">"; | | q += ">"; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator<= (const query_column<T2, ID2>& c) const | | operator<= (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () <= type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () <= type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "<="; | | q += "<="; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T2, database_type_id ID2> | | template <typename T2, database_type_id ID2> | |
| query | | query | |
| operator>= (const query_column<T2, ID2>& c) const | | operator>= (const query_column<T2, ID2>& c) const | |
| { | | { | |
| // We can compare columns only if we can compare their C++ types. | | // We can compare columns only if we can compare their C++ types. | |
| // | | // | |
| (void) (sizeof (type_instance<T> () >= type_instance<T2> ())); | | (void) (sizeof (type_instance<T> () >= type_instance<T2> ())); | |
| | | | |
|
| query q (name_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
|
| q += c.name (); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| private: | | private: | |
|
| const char* name_; | | const char* table_; | |
| | | const char* column_; | |
| }; | | }; | |
| | | | |
|
| | | // Provide operator+() for using columns to construct native | |
| | | // query fragments (e.g., ORDER BY). | |
| | | // | |
| | | template <typename T, database_type_id ID> | |
| | | inline query | |
| | | operator+ (const query_column<T, ID>& c, const std::string& s) | |
| | | { | |
| | | query q (c.table (), c.column ()); | |
| | | q += s; | |
| | | return q; | |
| | | } | |
| | | | |
| | | template <typename T, database_type_id ID> | |
| | | inline query | |
| | | operator+ (const std::string& s, const query_column<T, ID>& c) | |
| | | { | |
| | | query q (s); | |
| | | q.append (c.table (), c.column ()); | |
| | | return q; | |
| | | } | |
| | | | |
| | | template <typename T, database_type_id ID> | |
| | | inline query | |
| | | operator+ (const query_column<T, ID>& c, const query& q) | |
| | | { | |
| | | query r (c.table (), c.column ()); | |
| | | r += q; | |
| | | return r; | |
| | | } | |
| | | | |
| | | template <typename T, database_type_id ID> | |
| | | inline query | |
| | | operator+ (const query& q, const query_column<T, ID>& c) | |
| | | { | |
| | | query r (q); | |
| | | r.append (c.table (), c.column ()); | |
| | | return r; | |
| | | } | |
| | | | |
| // | | // | |
| // | | // | |
| template <typename T, database_type_id> | | template <typename T, database_type_id> | |
| struct query_param_impl; | | struct query_param_impl; | |
| | | | |
| // BOOLEAN | | // BOOLEAN | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| struct query_param_impl<T, id_boolean>: query_param | | struct query_param_impl<T, id_boolean>: query_param | |
| { | | { | |
| | | | |
| skipping to change at line 1663 | | skipping to change at line 1752 | |
| unsigned char buffer_[16]; | | unsigned char buffer_[16]; | |
| }; | | }; | |
| } | | } | |
| } | | } | |
| | | | |
| // odb::query specialization for PostgreSQL. | | // odb::query specialization for PostgreSQL. | |
| // | | // | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename T> | | template <typename T> | |
|
| class query<T, pgsql::query>: public object_traits<T>::query_type | | class query<T, pgsql::query>: public query_selector<T>::type | |
| { | | { | |
| public: | | public: | |
| // We don't define any typedefs here since they may clash with | | // We don't define any typedefs here since they may clash with | |
| // column names defined by our base type. | | // column names defined by our base type. | |
| // | | // | |
| | | | |
| query () | | query () | |
| { | | { | |
| } | | } | |
| | | | |
| explicit | | explicit | |
|
| | | query (bool v) | |
| | | : query_selector<T>::type (v) | |
| | | { | |
| | | } | |
| | | | |
| | | explicit | |
| | | query (const char* q) | |
| | | : query_selector<T>::type (q) | |
| | | { | |
| | | } | |
| | | | |
| | | explicit | |
| query (const std::string& q) | | query (const std::string& q) | |
|
| : object_traits<T>::query_type (q) | | : query_selector<T>::type (q) | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| explicit | | explicit | |
| query (pgsql::val_bind<T2> v) | | query (pgsql::val_bind<T2> v) | |
|
| : object_traits<T>::query_type (pgsql::query (v)) | | : query_selector<T>::type (pgsql::query (v)) | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| explicit | | explicit | |
| query (pgsql::ref_bind<T2> r) | | query (pgsql::ref_bind<T2> r) | |
|
| : object_traits<T>::query_type (pgsql::query (r)) | | : query_selector<T>::type (pgsql::query (r)) | |
| { | | { | |
| } | | } | |
| | | | |
| query (const pgsql::query& q) | | query (const pgsql::query& q) | |
|
| : object_traits<T>::query_type (q) | | : query_selector<T>::type (q) | |
| { | | { | |
| } | | } | |
| | | | |
| template <pgsql::database_type_id ID> | | template <pgsql::database_type_id ID> | |
| query (const pgsql::query_column<bool, ID>& qc) | | query (const pgsql::query_column<bool, ID>& qc) | |
|
| : object_traits<T>::query_type (qc) | | : query_selector<T>::type (qc) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/pgsql/query.ixx> | | #include <odb/pgsql/query.ixx> | |
| #include <odb/pgsql/query.txx> | | #include <odb/pgsql/query.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| | | | |
End of changes. 52 change blocks. |
| 78 lines changed or deleted | | 180 lines changed or added | |
|
| query.txx | | query.txx | |
| | | | |
| skipping to change at line 16 | | skipping to change at line 16 | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace pgsql | | namespace pgsql | |
| { | | { | |
| // query | | // query | |
| // | | // | |
| | | | |
| template <database_type_id ID> | | template <database_type_id ID> | |
| query:: | | query:: | |
| query (const query_column<bool, ID>& c) | | query (const query_column<bool, ID>& c) | |
|
| : clause_ (c.name ()), binding_ (0, 0), native_binding_ (0, 0, 0, 0
) | | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |
| { | | { | |
| // Cannot use IS TRUE here since database type can be a non- | | // Cannot use IS TRUE here since database type can be a non- | |
| // integral type. | | // integral type. | |
| // | | // | |
|
| clause_ += " = "; | | append (c.table (), c.column ()); | |
| | | append ("="); | |
| append<bool, ID> (val_bind<bool> (true)); | | append<bool, ID> (val_bind<bool> (true)); | |
| } | | } | |
| | | | |
| // query_column | | // query_column | |
| // | | // | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| query query_column<T, ID>:: | | query query_column<T, ID>:: | |
| in (const T& v1, const T& v2) const | | in (const T& v1, const T& v2) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2)); | |
| q += ")"; | | q += ")"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| query query_column<T, ID>:: | | query query_column<T, ID>:: | |
| in (const T& v1, const T& v2, const T& v3) const | | in (const T& v1, const T& v2, const T& v3) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3)); | |
| q += ")"; | | q += ")"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| query query_column<T, ID>:: | | query query_column<T, ID>:: | |
| in (const T& v1, const T& v2, const T& v3, const T& v4) const | | in (const T& v1, const T& v2, const T& v3, const T& v4) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v4)); | | q.append<T, ID> (val_bind<T> (v4)); | |
| q += ")"; | | q += ")"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| query query_column<T, ID>:: | | query query_column<T, ID>:: | |
| in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) co
nst | | in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) co
nst | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v4)); | | q.append<T, ID> (val_bind<T> (v4)); | |
| q += ","; | | q += ","; | |
| q.append<T, ID> (val_bind<T> (v5)); | | q.append<T, ID> (val_bind<T> (v5)); | |
| q += ")"; | | q += ")"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| template <typename I> | | template <typename I> | |
| query query_column<T, ID>:: | | query query_column<T, ID>:: | |
| in_range (I begin, I end) const | | in_range (I begin, I end) const | |
| { | | { | |
|
| query q (name_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
| | | | |
| for (I i (begin); i != end; ++i) | | for (I i (begin); i != end; ++i) | |
| { | | { | |
| if (i != begin) | | if (i != begin) | |
| q += ","; | | q += ","; | |
| | | | |
| q.append<T, ID> (val_bind<T> (*i)); | | q.append<T, ID> (val_bind<T> (*i)); | |
| } | | } | |
| q += ")"; | | q += ")"; | |
| | | | |
End of changes. 7 change blocks. |
| 7 lines changed or deleted | | 8 lines changed or added | |
|
| traits.hxx | | traits.hxx | |
| | | | |
| skipping to change at line 12 | | skipping to change at line 12 | |
| // author : Constantin Michael <constantin@codesynthesis.com> | | // author : Constantin Michael <constantin@codesynthesis.com> | |
| // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_PGSQL_TRAITS_HXX | | #ifndef ODB_PGSQL_TRAITS_HXX | |
| #define ODB_PGSQL_TRAITS_HXX | | #define ODB_PGSQL_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
| #include <string> | | #include <string> | |
|
| | | #include <vector> | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| | | | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
|
| | | #include <odb/wrapper-traits.hxx> | |
| | | | |
| #include <odb/details/buffer.hxx> | | #include <odb/details/buffer.hxx> | |
|
| | | #include <odb/details/wrapper-p.hxx> | |
| | | | |
| #include <odb/pgsql/version.hxx> | | #include <odb/pgsql/version.hxx> | |
| #include <odb/pgsql/pgsql-types.hxx> | | #include <odb/pgsql/pgsql-types.hxx> | |
| | | | |
| #include <odb/pgsql/details/export.hxx> | | #include <odb/pgsql/details/export.hxx> | |
| #include <odb/pgsql/details/endian-traits.hxx> | | #include <odb/pgsql/details/endian-traits.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace pgsql | | namespace pgsql | |
| | | | |
| skipping to change at line 110 | | skipping to change at line 113 | |
| | | | |
| // UUID image is a 16-byte sequence. | | // UUID image is a 16-byte sequence. | |
| // | | // | |
| template <> | | template <> | |
| struct image_traits<id_uuid> {typedef unsigned char* image_type;}; | | struct image_traits<id_uuid> {typedef unsigned char* image_type;}; | |
| | | | |
| // | | // | |
| // value_traits | | // value_traits | |
| // | | // | |
| | | | |
|
| | | template <typename W, database_type_id, bool null_handler> | |
| | | struct wrapped_value_traits; | |
| | | | |
| template <typename T, database_type_id> | | template <typename T, database_type_id> | |
| struct default_value_traits; | | struct default_value_traits; | |
| | | | |
|
| | | template <typename T, database_type_id, bool w = details::wrapper_p<T>: | |
| | | :r> | |
| | | struct select_traits; | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
|
| class value_traits: public default_value_traits<T, ID> | | struct select_traits<T, ID, false> | |
| | | { | |
| | | typedef default_value_traits<T, ID> type; | |
| | | }; | |
| | | | |
| | | template <typename W, database_type_id ID> | |
| | | struct select_traits<W, ID, true> | |
| | | { | |
| | | typedef | |
| | | wrapped_value_traits<W, ID, wrapper_traits<W>::null_handler> | |
| | | type; | |
| | | }; | |
| | | | |
| | | template <typename T, database_type_id ID> | |
| | | class value_traits: public select_traits<T, ID>::type | |
| | | { | |
| | | }; | |
| | | | |
| | | // The wrapped_value_traits specializations should be able to handle | |
| | | // any value type which means we have to have every possible signature | |
| | | // of the set_value() and set_image() functions. | |
| | | // | |
| | | template <typename W, database_type_id ID> | |
| | | struct wrapped_value_traits<W, ID, false> | |
| | | { | |
| | | typedef wrapper_traits<W> wtraits; | |
| | | typedef typename wtraits::wrapped_type wrapped_type; | |
| | | | |
| | | typedef W value_type; | |
| | | typedef wrapped_type query_type; | |
| | | typedef typename image_traits<ID>::image_type image_type; | |
| | | | |
| | | typedef value_traits<wrapped_type, ID> vtraits; | |
| | | | |
| | | static void | |
| | | set_value (W& v, const image_type& i, bool is_null) | |
| | | { | |
| | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (image_type& i, bool& is_null, const W& v) | |
| | | { | |
| | | vtraits::set_image (i, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // String, BYTEA, and NUMERIC. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const details::buffer& b, std::size_t n, bool is_nul | |
| | | l) | |
| | | { | |
| | | vtraits::set_value (wtraits::set_ref (v), b, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer& b, std::size_t& n, bool& is_null, const W | |
| | | & v) | |
| | | { | |
| | | vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // BIT. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) | |
| | | { | |
| | | vtraits::set_value (wtraits::set_ref (v), i, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (unsigned char* i, | |
| | | std::size_t c, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const W& v) | |
| | | { | |
| | | vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // VARBIT. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_nu | |
| | | ll) | |
| | | { | |
| | | vtraits::set_value (wtraits::set_ref (v), b, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::ubuffer& b, std::size_t& n, bool& is_null, const | |
| | | W& v) | |
| | | { | |
| | | vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // UUID. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const unsigned char* i, bool is_null) | |
| | | { | |
| | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (unsigned char* i, bool& is_null, const W& v) | |
| | | { | |
| | | vtraits::set_image (i, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | }; | |
| | | | |
| | | template <typename W, database_type_id ID> | |
| | | struct wrapped_value_traits<W, ID, true> | |
| { | | { | |
|
| | | typedef wrapper_traits<W> wtraits; | |
| | | typedef typename wtraits::wrapped_type wrapped_type; | |
| | | | |
| | | typedef W value_type; | |
| | | typedef wrapped_type query_type; | |
| | | typedef typename image_traits<ID>::image_type image_type; | |
| | | | |
| | | typedef value_traits<wrapped_type, ID> vtraits; | |
| | | | |
| | | static void | |
| | | set_value (W& v, const image_type& i, bool is_null) | |
| | | { | |
| | | if (is_null) | |
| | | wtraits::set_null (v); | |
| | | else | |
| | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (image_type& i, bool& is_null, const W& v) | |
| | | { | |
| | | is_null = wtraits::get_null (v); | |
| | | | |
| | | if (!is_null) | |
| | | vtraits::set_image (i, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // String, BYTEA, and NUMERIC. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const details::buffer& b, std::size_t n, bool is_nul | |
| | | l) | |
| | | { | |
| | | if (is_null) | |
| | | wtraits::set_null (v); | |
| | | else | |
| | | vtraits::set_value (wtraits::set_ref (v), b, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer& b, std::size_t& n, bool& is_null, const W | |
| | | & v) | |
| | | { | |
| | | is_null = wtraits::get_null (v); | |
| | | | |
| | | if (!is_null) | |
| | | vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // BIT. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) | |
| | | { | |
| | | if (is_null) | |
| | | wtraits::set_null (v); | |
| | | else | |
| | | vtraits::set_value (wtraits::set_ref (v), i, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (unsigned char* i, | |
| | | std::size_t c, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const W& v) | |
| | | { | |
| | | is_null = wtraits::get_null (v); | |
| | | | |
| | | if (!is_null) | |
| | | vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // VARBIT. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_nu | |
| | | ll) | |
| | | { | |
| | | if (is_null) | |
| | | wtraits::set_null (v); | |
| | | else | |
| | | vtraits::set_value (wtraits::set_ref (v), b, n, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::ubuffer& b, std::size_t& n, bool& is_null, const | |
| | | W& v) | |
| | | { | |
| | | is_null = wtraits::get_null (v); | |
| | | | |
| | | if (!is_null) | |
| | | vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); | |
| | | } | |
| | | | |
| | | // UUID. | |
| | | // | |
| | | static void | |
| | | set_value (W& v, const unsigned char* i, bool is_null) | |
| | | { | |
| | | if (is_null) | |
| | | wtraits::set_null (v); | |
| | | else | |
| | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (unsigned char* i, bool& is_null, const W& v) | |
| | | { | |
| | | is_null = wtraits::get_null (v); | |
| | | | |
| | | if (!is_null) | |
| | | vtraits::set_image (i, is_null, wtraits::get_ref (v)); | |
| | | } | |
| }; | | }; | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| struct default_value_traits | | struct default_value_traits | |
| { | | { | |
| typedef T value_type; | | typedef T value_type; | |
| typedef T query_type; | | typedef T query_type; | |
| typedef typename image_traits<ID>::image_type image_type; | | typedef typename image_traits<ID>::image_type image_type; | |
| | | | |
| static void | | static void | |
| | | | |
| skipping to change at line 214 | | skipping to change at line 441 | |
| c_string_value_traits | | c_string_value_traits | |
| { | | { | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct LIBODB_PGSQL_EXPORT default_value_traits<const char*, id_string>
: | | struct LIBODB_PGSQL_EXPORT default_value_traits<const char*, id_string>
: | |
| c_string_value_traits | | c_string_value_traits | |
| { | | { | |
| }; | | }; | |
| | | | |
|
| | | template <std::size_t n> | |
| | | struct default_value_traits<char[n], id_numeric>: c_string_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | template <std::size_t n> | |
| | | struct default_value_traits<const char[n], id_numeric>: | |
| | | c_string_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | template <std::size_t n> | |
| | | struct default_value_traits<char[n], id_string>: c_string_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | template <std::size_t n> | |
| | | struct default_value_traits<const char[n], id_string>: | |
| | | c_string_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | // std::vector<char> (buffer) specialization. | |
| | | // | |
| | | template <> | |
| | | struct LIBODB_PGSQL_EXPORT default_value_traits<std::vector<char>, id_b | |
| | | ytea> | |
| | | { | |
| | | public: | |
| | | typedef std::vector<char> value_type; | |
| | | typedef std::vector<char> query_type; | |
| | | typedef details::buffer image_type; | |
| | | | |
| | | static void | |
| | | set_value (value_type& v, | |
| | | const details::buffer& b, | |
| | | std::size_t n, | |
| | | bool is_null) | |
| | | { | |
| | | if (!is_null) | |
| | | v.assign (b.data (), b.data () + n); | |
| | | else | |
| | | v.clear (); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer&, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const value_type&); | |
| | | }; | |
| | | | |
| // | | // | |
| // type_traits | | // type_traits | |
| // | | // | |
| | | | |
| template <typename T> | | template <typename T> | |
| struct default_type_traits; | | struct default_type_traits; | |
| | | | |
| template <typename T> | | template <typename T> | |
| class type_traits: public default_type_traits<T> | | class type_traits: public default_type_traits<T> | |
| { | | { | |
| | | | |
| skipping to change at line 321 | | skipping to change at line 599 | |
| struct default_type_traits<std::string> | | struct default_type_traits<std::string> | |
| { | | { | |
| static const database_type_id db_type_id = id_string; | | static const database_type_id db_type_id = id_string; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct default_type_traits<const char*> | | struct default_type_traits<const char*> | |
| { | | { | |
| static const database_type_id db_type_id = id_string; | | static const database_type_id db_type_id = id_string; | |
| }; | | }; | |
|
| | | | |
| | | template <std::size_t n> | |
| | | struct default_type_traits<char[n]> | |
| | | { | |
| | | static const database_type_id db_type_id = id_string; | |
| | | }; | |
| | | | |
| | | template <std::size_t n> | |
| | | struct default_type_traits<const char[n]> | |
| | | { | |
| | | static const database_type_id db_type_id = id_string; | |
| | | }; | |
| } | | } | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_PGSQL_TRAITS_HXX | | #endif // ODB_PGSQL_TRAITS_HXX | |
| | | | |
End of changes. 9 change blocks. |
| 1 lines changed or deleted | | 301 lines changed or added | |
|