| options.hxx | | options.hxx | |
| // This code was generated by CLI, a command line interface | | // This code was generated by CLI, a command line interface | |
| // compiler for C++. | | // compiler for C++. | |
| // | | // | |
| | | | |
| #ifndef LIBODB_SQLITE_DETAILS_OPTIONS_HXX | | #ifndef LIBODB_SQLITE_DETAILS_OPTIONS_HXX | |
| #define LIBODB_SQLITE_DETAILS_OPTIONS_HXX | | #define LIBODB_SQLITE_DETAILS_OPTIONS_HXX | |
| | | | |
|
| | | // Begin prologue. | |
| | | // | |
| | | // | |
| | | // End prologue. | |
| | | | |
| #include <deque> | | #include <deque> | |
| #include <iosfwd> | | #include <iosfwd> | |
| #include <string> | | #include <string> | |
| #include <cstddef> | | #include <cstddef> | |
| #include <exception> | | #include <exception> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace sqlite | | namespace sqlite | |
| { | | { | |
| | | | |
| skipping to change at line 50 | | skipping to change at line 55 | |
| value v_; | | value v_; | |
| }; | | }; | |
| | | | |
| // Exceptions. | | // Exceptions. | |
| // | | // | |
| | | | |
| class exception: public std::exception | | class exception: public std::exception | |
| { | | { | |
| public: | | public: | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const = 0; | | print (::std::ostream&) const = 0; | |
| }; | | }; | |
| | | | |
|
| std::ostream& | | ::std::ostream& | |
| operator<< (std::ostream&, const exception&); | | operator<< (::std::ostream&, const exception&); | |
| | | | |
| class unknown_option: public exception | | class unknown_option: public exception | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~unknown_option () throw (); | | ~unknown_option () throw (); | |
| | | | |
| unknown_option (const std::string& option); | | unknown_option (const std::string& option); | |
| | | | |
| const std::string& | | const std::string& | |
| option () const; | | option () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string option_; | | std::string option_; | |
| }; | | }; | |
| | | | |
| class unknown_argument: public exception | | class unknown_argument: public exception | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~unknown_argument () throw (); | | ~unknown_argument () throw (); | |
| | | | |
| unknown_argument (const std::string& argument); | | unknown_argument (const std::string& argument); | |
| | | | |
| const std::string& | | const std::string& | |
| argument () const; | | argument () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string argument_; | | std::string argument_; | |
| }; | | }; | |
| | | | |
| class missing_value: public exception | | class missing_value: public exception | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~missing_value () throw (); | | ~missing_value () throw (); | |
| | | | |
| missing_value (const std::string& option); | | missing_value (const std::string& option); | |
| | | | |
| const std::string& | | const std::string& | |
| option () const; | | option () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string option_; | | std::string option_; | |
| }; | | }; | |
| | | | |
| class invalid_value: public exception | | class invalid_value: public exception | |
| { | | { | |
| | | | |
| skipping to change at line 135 | | skipping to change at line 140 | |
| invalid_value (const std::string& option, | | invalid_value (const std::string& option, | |
| const std::string& value); | | const std::string& value); | |
| | | | |
| const std::string& | | const std::string& | |
| option () const; | | option () const; | |
| | | | |
| const std::string& | | const std::string& | |
| value () const; | | value () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string option_; | | std::string option_; | |
| std::string value_; | | std::string value_; | |
| }; | | }; | |
| | | | |
| class eos_reached: public exception | | class eos_reached: public exception | |
| { | | { | |
| public: | | public: | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| }; | | }; | |
| | | | |
| class file_io_failure: public exception | | class file_io_failure: public exception | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~file_io_failure () throw (); | | ~file_io_failure () throw (); | |
| | | | |
| file_io_failure (const std::string& file); | | file_io_failure (const std::string& file); | |
| | | | |
| const std::string& | | const std::string& | |
| file () const; | | file () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string file_; | | std::string file_; | |
| }; | | }; | |
| | | | |
| class unmatched_quote: public exception | | class unmatched_quote: public exception | |
| { | | { | |
| public: | | public: | |
| virtual | | virtual | |
| ~unmatched_quote () throw (); | | ~unmatched_quote () throw (); | |
| | | | |
| unmatched_quote (const std::string& argument); | | unmatched_quote (const std::string& argument); | |
| | | | |
| const std::string& | | const std::string& | |
| argument () const; | | argument () const; | |
| | | | |
| virtual void | | virtual void | |
|
| print (std::ostream&) const; | | print (::std::ostream&) const; | |
| | | | |
| virtual const char* | | virtual const char* | |
| what () const throw (); | | what () const throw (); | |
| | | | |
| private: | | private: | |
| std::string argument_; | | std::string argument_; | |
| }; | | }; | |
| | | | |
| class scanner | | class scanner | |
| { | | { | |
| | | | |
| skipping to change at line 312 | | skipping to change at line 317 | |
| | | | |
| const std::string option_; | | const std::string option_; | |
| option_info option_info_; | | option_info option_info_; | |
| const option_info* options_; | | const option_info* options_; | |
| std::size_t options_count_; | | std::size_t options_count_; | |
| | | | |
| std::string hold_; | | std::string hold_; | |
| std::deque<std::string> args_; | | std::deque<std::string> args_; | |
| bool skip_; | | bool skip_; | |
| }; | | }; | |
|
| | | | |
| | | template <typename X> | |
| | | struct parser; | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| #include <string> | | #include <string> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace sqlite | | namespace sqlite | |
| { | | { | |
| namespace details | | namespace details | |
| { | | { | |
| class options | | class options | |
| { | | { | |
| public: | | public: | |
|
| | | | |
| options (int& argc, | | options (int& argc, | |
| char** argv, | | char** argv, | |
| bool erase = false, | | bool erase = false, | |
| ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | | ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | |
| ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | | ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | |
| | | | |
| options (int start, | | options (int start, | |
| int& argc, | | int& argc, | |
| char** argv, | | char** argv, | |
| bool erase = false, | | bool erase = false, | |
| | | | |
| skipping to change at line 361 | | skipping to change at line 368 | |
| char** argv, | | char** argv, | |
| int& end, | | int& end, | |
| bool erase = false, | | bool erase = false, | |
| ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | | ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | |
| ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | | ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | |
| | | | |
| options (::odb::sqlite::details::cli::scanner&, | | options (::odb::sqlite::details::cli::scanner&, | |
| ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | | ::odb::sqlite::details::cli::unknown_mode option = ::odb::
sqlite::details::cli::unknown_mode::fail, | |
| ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | | ::odb::sqlite::details::cli::unknown_mode argument = ::odb
::sqlite::details::cli::unknown_mode::stop); | |
| | | | |
|
| | | options (); | |
| | | | |
| // Option accessors. | | // Option accessors. | |
| // | | // | |
|
| | | | |
| const std::string& | | const std::string& | |
| database () const; | | database () const; | |
| | | | |
| const bool& | | const bool& | |
| create () const; | | create () const; | |
| | | | |
| const bool& | | const bool& | |
| read_only () const; | | read_only () const; | |
| | | | |
| const std::string& | | const std::string& | |
| options_file () const; | | options_file () const; | |
| | | | |
| // Print usage information. | | // Print usage information. | |
| // | | // | |
| static void | | static void | |
| print_usage (::std::ostream&); | | print_usage (::std::ostream&); | |
| | | | |
|
| | | // Implementation details. | |
| | | // | |
| | | protected: | |
| | | bool | |
| | | _parse (const char*, ::odb::sqlite::details::cli::scanner&); | |
| | | | |
| private: | | private: | |
| void | | void | |
| _parse (::odb::sqlite::details::cli::scanner&, | | _parse (::odb::sqlite::details::cli::scanner&, | |
| ::odb::sqlite::details::cli::unknown_mode option, | | ::odb::sqlite::details::cli::unknown_mode option, | |
| ::odb::sqlite::details::cli::unknown_mode argument); | | ::odb::sqlite::details::cli::unknown_mode argument); | |
| | | | |
| public: | | public: | |
| std::string database_; | | std::string database_; | |
| bool create_; | | bool create_; | |
| bool read_only_; | | bool read_only_; | |
| std::string options_file_; | | std::string options_file_; | |
| }; | | }; | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| #include "options.ixx" | | #include "options.ixx" | |
| | | | |
|
| | | // Begin epilogue. | |
| | | // | |
| | | // | |
| | | // End epilogue. | |
| | | | |
| #endif // LIBODB_SQLITE_DETAILS_OPTIONS_HXX | | #endif // LIBODB_SQLITE_DETAILS_OPTIONS_HXX | |
| | | | |
End of changes. 16 change blocks. |
| 12 lines changed or deleted | | 31 lines changed or added | |
|
| query.hxx | | query.hxx | |
| | | | |
| skipping to change at line 23 | | skipping to change at line 23 | |
| | | | |
| #include <odb/query.hxx> | | #include <odb/query.hxx> | |
| #include <odb/details/buffer.hxx> | | #include <odb/details/buffer.hxx> | |
| #include <odb/details/shared-ptr.hxx> | | #include <odb/details/shared-ptr.hxx> | |
| | | | |
| #include <odb/sqlite/version.hxx> | | #include <odb/sqlite/version.hxx> | |
| #include <odb/sqlite/forward.hxx> | | #include <odb/sqlite/forward.hxx> | |
| #include <odb/sqlite/traits.hxx> | | #include <odb/sqlite/traits.hxx> | |
| #include <odb/sqlite/sqlite-types.hxx> | | #include <odb/sqlite/sqlite-types.hxx> | |
| #include <odb/sqlite/binding.hxx> | | #include <odb/sqlite/binding.hxx> | |
|
| | | | |
| #include <odb/sqlite/details/export.hxx> | | #include <odb/sqlite/details/export.hxx> | |
|
| | | #include <odb/sqlite/details/conversion.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace sqlite | | namespace sqlite | |
| { | | { | |
| template <typename T> | | template <typename T> | |
| class val_bind | | class val_bind | |
| { | | { | |
| public: | | public: | |
| explicit | | explicit | |
| | | | |
| skipping to change at line 132 | | skipping to change at line 134 | |
| param, | | param, | |
| native, | | native, | |
| boolean | | boolean | |
| }; | | }; | |
| | | | |
| clause_part (kind_type k): kind (k) {} | | clause_part (kind_type k): kind (k) {} | |
| clause_part (kind_type k, const std::string& p): kind (k), part (p)
{} | | clause_part (kind_type k, const std::string& p): kind (k), part (p)
{} | |
| clause_part (bool p): kind (boolean), bool_part (p) {} | | clause_part (bool p): kind (boolean), bool_part (p) {} | |
| | | | |
| kind_type kind; | | kind_type kind; | |
|
| std::string part; | | std::string part; // If kind is param, then part is conversion expr
. | |
| bool bool_part; | | bool bool_part; | |
| }; | | }; | |
| | | | |
| query () | | query () | |
| : parameters_ (new (details::shared) query_params) | | : parameters_ (new (details::shared) query_params) | |
| { | | { | |
| } | | } | |
| | | | |
| // True or false literal. | | // True or false literal. | |
| // | | // | |
| | | | |
| skipping to change at line 175 | | skipping to change at line 177 | |
| : parameters_ (new (details::shared) query_params) | | : parameters_ (new (details::shared) query_params) | |
| { | | { | |
| append (table, column); | | append (table, column); | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| explicit | | explicit | |
| query (val_bind<T> v) | | query (val_bind<T> v) | |
| : parameters_ (new (details::shared) query_params) | | : parameters_ (new (details::shared) query_params) | |
| { | | { | |
|
| 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> | | template <typename T> | |
| explicit | | explicit | |
| query (ref_bind<T> r) | | query (ref_bind<T> r) | |
| : parameters_ (new (details::shared) query_params) | | : parameters_ (new (details::shared) query_params) | |
| { | | { | |
|
| 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> | | template <database_type_id ID> | |
| query (const query_column<bool, ID>&); | | query (const query_column<bool, ID>&); | |
| | | | |
| query (const query&); | | query (const query&); | |
| | | | |
| query& | | query& | |
| operator= (const query&); | | operator= (const query&); | |
| | | | |
| | | | |
| skipping to change at line 257 | | skipping to change at line 261 | |
| operator+= (const std::string& q) | | operator+= (const std::string& q) | |
| { | | { | |
| append (q); | | append (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, details::conversion<T>::to ()); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template <typename T> | | template <typename T> | |
| query& | | query& | |
| operator+= (ref_bind<T> r) | | 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; | | return *this; | |
| } | | } | |
| | | | |
| 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>, const char* conv); | |
| | | | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| void | | void | |
|
| append (ref_bind<T>); | | append (ref_bind<T>, const char* conv); | |
| | | | |
| void | | void | |
| append (const std::string& native); | | append (const std::string& native); | |
| | | | |
| void | | void | |
| append (const char* table, const char* column); | | append (const char* table, const char* column); | |
| | | | |
| private: | | private: | |
| void | | void | |
|
| add (details::shared_ptr<query_param>); | | add (details::shared_ptr<query_param>, const char* conv); | |
| | | | |
| private: | | private: | |
| typedef std::vector<clause_part> clause_type; | | typedef std::vector<clause_part> clause_type; | |
| | | | |
| clause_type clause_; | | clause_type clause_; | |
| details::shared_ptr<query_params> parameters_; | | details::shared_ptr<query_params> parameters_; | |
| }; | | }; | |
| | | | |
| inline query | | inline query | |
| operator+ (const query& x, const query& y) | | operator+ (const query& x, const query& y) | |
| | | | |
| skipping to change at line 424 | | skipping to change at line 430 | |
| 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 | |
| { | | { | |
|
| // Note that we keep shalow copies of the table and column names. | | // Note that we keep shallow copies of the table, column, and convers | |
| | | ion | |
| | | // expression. The latter can be NULL. | |
| // | | // | |
|
| query_column (const char* table, const char* column) | | query_column (const char* table, const char* column, const char* conv | |
| : table_ (table), column_ (column) | | ) | |
| | | : table_ (table), column_ (column), conversion_ (conv) | |
| { | | { | |
| } | | } | |
| | | | |
| const char* | | const char* | |
| table () const | | table () const | |
| { | | { | |
| return table_; | | return table_; | |
| } | | } | |
| | | | |
| const char* | | const char* | |
| column () const | | column () const | |
| { | | { | |
| return column_; | | return column_; | |
| } | | } | |
| | | | |
|
| | | // Can be NULL. | |
| | | // | |
| | | const char* | |
| | | conversion () const | |
| | | { | |
| | | return conversion_; | |
| | | } | |
| | | | |
| // is_null, is_not_null | | // is_null, is_not_null | |
| // | | // | |
| public: | | public: | |
| query | | query | |
| is_null () const | | is_null () const | |
| { | | { | |
| query q (table_, column_); | | query q (table_, column_); | |
| q += "IS NULL"; | | q += "IS NULL"; | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| skipping to change at line 495 | | skipping to change at line 510 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "="; | | q += "="; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "="; | | q += "="; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 580 | | skipping to change at line 595 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "!="; | | q += "!="; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "!="; | | q += "!="; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 665 | | skipping to change at line 680 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "<"; | | q += "<"; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "<"; | | q += "<"; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 750 | | skipping to change at line 765 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += ">"; | | q += ">"; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += ">"; | | q += ">"; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 835 | | skipping to change at line 850 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "<="; | | q += "<="; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "<="; | | q += "<="; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 920 | | skipping to change at line 935 | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
|
| q.append<T, ID> (v); | | q.append<T, ID> (v, conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
|
| q.append<T, ID> (r); | | q.append<T, ID> (r, conversion_); | |
| 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); | |
| } | | } | |
| | | | |
| friend query | | friend query | |
| | | | |
| skipping to change at line 1081 | | skipping to change at line 1096 | |
| | | | |
| query q (table_, column_); | | query q (table_, column_); | |
| q += ">="; | | q += ">="; | |
| q.append (c.table (), c.column ()); | | q.append (c.table (), c.column ()); | |
| return q; | | return q; | |
| } | | } | |
| | | | |
| private: | | private: | |
| const char* table_; | | const char* table_; | |
| const char* column_; | | const char* column_; | |
|
| | | const char* conversion_; | |
| }; | | }; | |
| | | | |
| // Provide operator+() for using columns to construct native | | // Provide operator+() for using columns to construct native | |
| // query fragments (e.g., ORDER BY). | | // query fragments (e.g., ORDER BY). | |
| // | | // | |
| template <typename T, database_type_id ID> | | template <typename T, database_type_id ID> | |
| inline query | | inline query | |
| operator+ (const query_column<T, ID>& c, const std::string& s) | | operator+ (const query_column<T, ID>& c, const std::string& s) | |
| { | | { | |
| query q (c.table (), c.column ()); | | query q (c.table (), c.column ()); | |
| | | | |
| skipping to change at line 1153 | | skipping to change at line 1169 | |
| bind (sqlite::bind* b) | | bind (sqlite::bind* b) | |
| { | | { | |
| b->type = sqlite::bind::integer; | | b->type = sqlite::bind::integer; | |
| b->buffer = &image_; | | b->buffer = &image_; | |
| } | | } | |
| | | | |
| private: | | private: | |
| void | | void | |
| init (const T& v) | | init (const T& v) | |
| { | | { | |
|
| bool dummy; | | bool is_null (false); // Can't be NULL. | |
| value_traits<T, id_integer>::set_image (image_, dummy, v); | | value_traits<T, id_integer>::set_image (image_, is_null, v); | |
| } | | } | |
| | | | |
| private: | | private: | |
| long long image_; | | long long image_; | |
| }; | | }; | |
| | | | |
| // REAL | | // REAL | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| struct query_param_impl<T, id_real>: query_param | | struct query_param_impl<T, id_real>: query_param | |
| | | | |
| skipping to change at line 1187 | | skipping to change at line 1203 | |
| bind (sqlite::bind* b) | | bind (sqlite::bind* b) | |
| { | | { | |
| b->type = sqlite::bind::real; | | b->type = sqlite::bind::real; | |
| b->buffer = &image_; | | b->buffer = &image_; | |
| } | | } | |
| | | | |
| private: | | private: | |
| void | | void | |
| init (const T& v) | | init (const T& v) | |
| { | | { | |
|
| bool dummy; | | bool is_null (false); // Can't be NULL. | |
| value_traits<T, id_real>::set_image (image_, dummy, v); | | value_traits<T, id_real>::set_image (image_, is_null, v); | |
| } | | } | |
| | | | |
| private: | | private: | |
| double image_; | | double image_; | |
| }; | | }; | |
| | | | |
| // TEXT | | // TEXT | |
| // | | // | |
| template <typename T> | | template <typename T> | |
| struct query_param_impl<T, id_text>: query_param | | struct query_param_impl<T, id_text>: query_param | |
| | | | |
| skipping to change at line 1212 | | skipping to change at line 1228 | |
| | | | |
| virtual bool | | virtual bool | |
| init () | | init () | |
| { | | { | |
| return init (*static_cast<const T*> (value_)); | | return init (*static_cast<const T*> (value_)); | |
| } | | } | |
| | | | |
| virtual void | | virtual void | |
| bind (sqlite::bind* b) | | bind (sqlite::bind* b) | |
| { | | { | |
|
| b->type = sqlite::bind::text; | | b->type = image_traits<T, id_text>::bind_value; | |
| b->buffer = buffer_.data (); | | b->buffer = buffer_.data (); | |
| b->size = &size_; | | b->size = &size_; | |
| } | | } | |
| | | | |
| private: | | private: | |
| bool | | bool | |
| init (const T& v) | | init (const T& v) | |
| { | | { | |
|
| bool dummy; | | bool is_null (false); // Can't be NULL. | |
| std::size_t cap (buffer_.capacity ()); | | std::size_t cap (buffer_.capacity ()); | |
|
| value_traits<T, id_text>::set_image (buffer_, size_, dummy, v); | | value_traits<T, id_text>::set_image (buffer_, size_, is_null, v); | |
| return cap != buffer_.capacity (); | | return cap != buffer_.capacity (); | |
| } | | } | |
| | | | |
| private: | | private: | |
| details::buffer buffer_; | | details::buffer buffer_; | |
| std::size_t size_; | | std::size_t size_; | |
| }; | | }; | |
| | | | |
| // BLOB | | // BLOB | |
| // | | // | |
| | | | |
| skipping to change at line 1258 | | skipping to change at line 1274 | |
| { | | { | |
| b->type = sqlite::bind::blob; | | b->type = sqlite::bind::blob; | |
| b->buffer = buffer_.data (); | | b->buffer = buffer_.data (); | |
| b->size = &size_; | | b->size = &size_; | |
| } | | } | |
| | | | |
| private: | | private: | |
| bool | | bool | |
| init (const T& v) | | init (const T& v) | |
| { | | { | |
|
| bool dummy; | | bool is_null (false); // Can't be NULL. | |
| std::size_t cap (buffer_.capacity ()); | | std::size_t cap (buffer_.capacity ()); | |
|
| value_traits<T, id_blob>::set_image (buffer_, size_, dummy, v); | | value_traits<T, id_blob>::set_image (buffer_, size_, is_null, v); | |
| return cap != buffer_.capacity (); | | return cap != buffer_.capacity (); | |
| } | | } | |
| | | | |
| private: | | private: | |
| details::buffer buffer_; | | details::buffer buffer_; | |
| std::size_t size_; | | std::size_t size_; | |
| }; | | }; | |
| } | | } | |
| } | | } | |
| | | | |
| // odb::query specialization for SQLite. | | // odb::query specialization for SQLite. | |
| // | | // | |
| namespace odb | | namespace odb | |
| { | | { | |
| template <typename T> | | template <typename T> | |
|
| class query<T, sqlite::query>: public query_selector<T>::type | | class query<T, sqlite::query>: public sqlite::query, | |
| | | public query_selector<T>::columns_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 (bool v) | |
|
| : query_selector<T>::type (v) | | : sqlite::query (v) | |
| { | | { | |
| } | | } | |
| | | | |
| explicit | | explicit | |
| query (const char* q) | | query (const char* q) | |
|
| : query_selector<T>::type (q) | | : sqlite::query (q) | |
| { | | { | |
| } | | } | |
| | | | |
| explicit | | explicit | |
| query (const std::string& q) | | query (const std::string& q) | |
|
| : query_selector<T>::type (q) | | : sqlite::query (q) | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| explicit | | explicit | |
| query (sqlite::val_bind<T2> v) | | query (sqlite::val_bind<T2> v) | |
|
| : query_selector<T>::type (sqlite::query (v)) | | : sqlite::query (sqlite::query (v)) | |
| { | | { | |
| } | | } | |
| | | | |
| template <typename T2> | | template <typename T2> | |
| explicit | | explicit | |
| query (sqlite::ref_bind<T2> r) | | query (sqlite::ref_bind<T2> r) | |
|
| : query_selector<T>::type (sqlite::query (r)) | | : sqlite::query (sqlite::query (r)) | |
| { | | { | |
| } | | } | |
| | | | |
| query (const sqlite::query& q) | | query (const sqlite::query& q) | |
|
| : query_selector<T>::type (q) | | : sqlite::query (q) | |
| { | | { | |
| } | | } | |
| | | | |
| template <sqlite::database_type_id ID> | | template <sqlite::database_type_id ID> | |
| query (const sqlite::query_column<bool, ID>& qc) | | query (const sqlite::query_column<bool, ID>& qc) | |
|
| : query_selector<T>::type (qc) | | : sqlite::query (qc) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| } | | } | |
| | | | |
| #include <odb/sqlite/query.ixx> | | #include <odb/sqlite/query.ixx> | |
| #include <odb/sqlite/query.txx> | | #include <odb/sqlite/query.txx> | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| | | | |
End of changes. 41 change blocks. |
| 40 lines changed or deleted | | 59 lines changed or added | |
|
| query.txx | | query.txx | |
| | | | |
| skipping to change at line 22 | | skipping to change at line 22 | |
| 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) | |
| : parameters_ (new (details::shared) query_params) | | : parameters_ (new (details::shared) query_params) | |
| { | | { | |
| // 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. | |
| // | | // | |
| append (c.table (), c.column ()); | | append (c.table (), c.column ()); | |
| append ("="); | | append ("="); | |
|
| append<bool, ID> (val_bind<bool> (true)); | | append<bool, ID> (val_bind<bool> (true), c.conversion ()); | |
| } | | } | |
| | | | |
| // 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 (table_, column_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
|
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2), conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
|
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3), conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
|
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v4)); | | q.append<T, ID> (val_bind<T> (v4), conversion_); | |
| 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 (table_, column_); | | query q (table_, column_); | |
| q += "IN ("; | | q += "IN ("; | |
|
| q.append<T, ID> (val_bind<T> (v1)); | | q.append<T, ID> (val_bind<T> (v1), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v2)); | | q.append<T, ID> (val_bind<T> (v2), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v3)); | | q.append<T, ID> (val_bind<T> (v3), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v4)); | | q.append<T, ID> (val_bind<T> (v4), conversion_); | |
| q += ","; | | q += ","; | |
|
| q.append<T, ID> (val_bind<T> (v5)); | | q.append<T, ID> (val_bind<T> (v5), conversion_); | |
| 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 (table_, column_); | | 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), conversion_); | |
| } | | } | |
| q += ")"; | | q += ")"; | |
| return q; | | return q; | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
End of changes. 16 change blocks. |
| 16 lines changed or deleted | | 16 lines changed or added | |
|
| traits.hxx | | traits.hxx | |
| // file : odb/sqlite/traits.hxx | | // file : odb/sqlite/traits.hxx | |
| // copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | | // copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | |
| // license : GNU GPL v2; see accompanying LICENSE file | | // license : GNU GPL v2; see accompanying LICENSE file | |
| | | | |
| #ifndef ODB_SQLITE_TRAITS_HXX | | #ifndef ODB_SQLITE_TRAITS_HXX | |
| #define ODB_SQLITE_TRAITS_HXX | | #define ODB_SQLITE_TRAITS_HXX | |
| | | | |
| #include <odb/pre.hxx> | | #include <odb/pre.hxx> | |
| | | | |
|
| | | #include <odb/details/config.hxx> // ODB_CXX11 | |
| | | | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
|
| | | #include <limits> // std::numeric_limits | |
| #include <cstddef> // std::size_t | | #include <cstddef> // std::size_t | |
| #include <cstring> // std::memcpy, std::memset, std::strlen | | #include <cstring> // std::memcpy, std::memset, std::strlen | |
| | | | |
|
| | | #ifdef ODB_CXX11 | |
| | | # include <array> | |
| | | #endif | |
| | | | |
| #include <odb/traits.hxx> | | #include <odb/traits.hxx> | |
| #include <odb/wrapper-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/details/wrapper-p.hxx> | |
| | | | |
| #include <odb/sqlite/version.hxx> | | #include <odb/sqlite/version.hxx> | |
|
| | | #include <odb/sqlite/sqlite-types.hxx> | |
| #include <odb/sqlite/details/export.hxx> | | #include <odb/sqlite/details/export.hxx> | |
| | | | |
| namespace odb | | namespace odb | |
| { | | { | |
| namespace sqlite | | namespace sqlite | |
| { | | { | |
| enum database_type_id | | enum database_type_id | |
| { | | { | |
| id_integer, | | id_integer, | |
| id_real, | | id_real, | |
| id_text, | | id_text, | |
| id_blob | | id_blob | |
| }; | | }; | |
| | | | |
| // | | // | |
| // image_traits | | // image_traits | |
| // | | // | |
| | | | |
|
| template <database_type_id> | | template <typename T, database_type_id> | |
| struct image_traits; | | struct image_traits; | |
| | | | |
|
| template <> | | template <typename T> | |
| struct image_traits<id_integer> {typedef long long image_type;}; | | struct image_traits<T, id_integer> {typedef long long image_type;}; | |
| | | | |
|
| template <> | | template <typename T> | |
| struct image_traits<id_real> {typedef double image_type;}; | | struct image_traits<T, id_real> {typedef double image_type;}; | |
| | | | |
|
| template <> | | template <typename T> | |
| struct image_traits<id_text> {typedef details::buffer image_type;}; | | struct image_traits<T, id_text> | |
| | | { | |
| | | typedef details::buffer image_type; | |
| | | | |
|
| template <> | | // By default the text is in UTF-8. | |
| struct image_traits<id_blob> {typedef details::buffer image_type;}; | | // | |
| | | static const bind::buffer_type bind_value = bind::text; | |
| | | }; | |
| | | | |
| | | template <typename T> | |
| | | struct image_traits<T, id_blob> {typedef details::buffer image_type;}; | |
| | | | |
| // | | // | |
| // value_traits | | // value_traits | |
| // | | // | |
| | | | |
| template <typename W, database_type_id, bool null_handler> | | template <typename W, database_type_id, bool null_handler> | |
| struct wrapped_value_traits; | | struct wrapped_value_traits; | |
| | | | |
| template <typename T, database_type_id> | | template <typename T, database_type_id> | |
| struct default_value_traits; | | struct default_value_traits; | |
| | | | |
| skipping to change at line 99 | | skipping to change at line 114 | |
| // of the set_value() and set_image() functions. | | // of the set_value() and set_image() functions. | |
| // | | // | |
| template <typename W, database_type_id ID> | | template <typename W, database_type_id ID> | |
| struct wrapped_value_traits<W, ID, false> | | struct wrapped_value_traits<W, ID, false> | |
| { | | { | |
| typedef wrapper_traits<W> wtraits; | | typedef wrapper_traits<W> wtraits; | |
| typedef typename wtraits::unrestricted_wrapped_type wrapped_type; | | typedef typename wtraits::unrestricted_wrapped_type wrapped_type; | |
| | | | |
| typedef W value_type; | | typedef W value_type; | |
| typedef wrapped_type query_type; | | typedef wrapped_type query_type; | |
|
| typedef typename image_traits<ID>::image_type image_type; | | typedef typename image_traits<wrapped_type, ID>::image_type image_typ
e; | |
| | | | |
| typedef value_traits<wrapped_type, ID> vtraits; | | typedef value_traits<wrapped_type, ID> vtraits; | |
| | | | |
| static void | | static void | |
| set_value (W& v, const image_type& i, bool is_null) | | set_value (W& v, const image_type& i, bool is_null) | |
| { | | { | |
| vtraits::set_value (wtraits::set_ref (v), i, is_null); | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| } | | } | |
| | | | |
| static void | | static void | |
| | | | |
| skipping to change at line 138 | | skipping to change at line 153 | |
| }; | | }; | |
| | | | |
| template <typename W, database_type_id ID> | | template <typename W, database_type_id ID> | |
| struct wrapped_value_traits<W, ID, true> | | struct wrapped_value_traits<W, ID, true> | |
| { | | { | |
| typedef wrapper_traits<W> wtraits; | | typedef wrapper_traits<W> wtraits; | |
| typedef typename wtraits::unrestricted_wrapped_type wrapped_type; | | typedef typename wtraits::unrestricted_wrapped_type wrapped_type; | |
| | | | |
| typedef W value_type; | | typedef W value_type; | |
| typedef wrapped_type query_type; | | typedef wrapped_type query_type; | |
|
| typedef typename image_traits<ID>::image_type image_type; | | typedef typename image_traits<wrapped_type, ID>::image_type image_typ
e; | |
| | | | |
| typedef value_traits<wrapped_type, ID> vtraits; | | typedef value_traits<wrapped_type, ID> vtraits; | |
| | | | |
| static void | | static void | |
| set_value (W& v, const image_type& i, bool is_null) | | set_value (W& v, const image_type& i, bool is_null) | |
| { | | { | |
| if (is_null) | | if (is_null) | |
| wtraits::set_null (v); | | wtraits::set_null (v); | |
| else | | else | |
| vtraits::set_value (wtraits::set_ref (v), i, is_null); | | vtraits::set_value (wtraits::set_ref (v), i, is_null); | |
| | | | |
| skipping to change at line 186 | | skipping to change at line 201 | |
| if (!is_null) | | if (!is_null) | |
| vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); | | vtraits::set_image (b, n, 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<T, ID>::image_type image_type; | |
| | | | |
| static void | | static void | |
| set_value (T& v, const image_type& i, bool is_null) | | set_value (T& v, const image_type& i, bool is_null) | |
| { | | { | |
| if (!is_null) | | if (!is_null) | |
| v = T (i); | | v = T (i); | |
| else | | else | |
| v = T (); | | v = T (); | |
| } | | } | |
| | | | |
| static void | | static void | |
| set_image (image_type& i, bool& is_null, T v) | | set_image (image_type& i, bool& is_null, T v) | |
| { | | { | |
| is_null = false; | | is_null = false; | |
| i = image_type (v); | | i = image_type (v); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| | | // Float & double specialization. SQLite converts NaNs to NULLs so | |
| | | // we convert NULLs to NaNs for consistency. | |
| | | // | |
| | | template <typename T> | |
| | | struct real_value_traits | |
| | | { | |
| | | typedef T value_type; | |
| | | typedef T query_type; | |
| | | typedef double image_type; | |
| | | | |
| | | static void | |
| | | set_value (T& v, double i, bool is_null) | |
| | | { | |
| | | if (!is_null) | |
| | | v = T (i); | |
| | | else | |
| | | v = std::numeric_limits<T>::quiet_NaN (); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (double& i, bool& is_null, T v) | |
| | | { | |
| | | is_null = false; | |
| | | i = image_type (v); | |
| | | } | |
| | | }; | |
| | | | |
| | | template <> | |
| | | struct LIBODB_SQLITE_EXPORT default_value_traits<float, id_real>: | |
| | | real_value_traits<float> | |
| | | { | |
| | | }; | |
| | | | |
| | | template <> | |
| | | struct LIBODB_SQLITE_EXPORT default_value_traits<double, id_real>: | |
| | | real_value_traits<double> | |
| | | { | |
| | | }; | |
| | | | |
| // std::string specialization. | | // std::string specialization. | |
| // | | // | |
| template <> | | template <> | |
| struct LIBODB_SQLITE_EXPORT default_value_traits<std::string, id_text> | | struct LIBODB_SQLITE_EXPORT default_value_traits<std::string, id_text> | |
| { | | { | |
| typedef std::string value_type; | | typedef std::string value_type; | |
| typedef std::string query_type; | | typedef std::string query_type; | |
| typedef details::buffer image_type; | | typedef details::buffer image_type; | |
| | | | |
| static void | | static void | |
| | | | |
| skipping to change at line 258 | | skipping to change at line 312 | |
| bool& is_null, | | bool& is_null, | |
| const char*); | | const char*); | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct LIBODB_SQLITE_EXPORT default_value_traits<const char*, id_text>: | | struct LIBODB_SQLITE_EXPORT default_value_traits<const char*, id_text>: | |
| c_string_value_traits | | c_string_value_traits | |
| { | | { | |
| }; | | }; | |
| | | | |
|
| template <std::size_t n> | | template <std::size_t N> | |
| struct default_value_traits<char[n], id_text>: c_string_value_traits | | struct default_value_traits<char[N], id_text>: c_string_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | template <std::size_t N> | |
| | | struct default_value_traits<const char[N], id_text>: c_string_value_tra | |
| | | its | |
| | | { | |
| | | }; | |
| | | | |
| | | #ifdef _WIN32 | |
| | | // std::wstring specialization. Using UTF-16 binding. | |
| | | // | |
| | | template <> | |
| | | struct image_traits<std::wstring, id_text> | |
| | | { | |
| | | typedef details::buffer image_type; | |
| | | static const bind::buffer_type bind_value = bind::text16; | |
| | | }; | |
| | | | |
| | | template <> | |
| | | struct LIBODB_SQLITE_EXPORT default_value_traits<std::wstring, id_text> | |
| | | { | |
| | | typedef std::wstring value_type; | |
| | | typedef std::wstring query_type; | |
| | | typedef details::buffer image_type; | |
| | | | |
| | | static void | |
| | | set_value (std::wstring& v, | |
| | | const details::buffer& b, | |
| | | std::size_t n, | |
| | | bool is_null) | |
| | | { | |
| | | if (!is_null) | |
| | | v.assign (reinterpret_cast<const wchar_t*> (b.data ()), n / 2); | |
| | | else | |
| | | v.erase (); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer&, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const std::wstring&); | |
| | | }; | |
| | | | |
| | | // const wchar_t* specialization | |
| | | // | |
| | | struct c_wstring_image_traits | |
| | | { | |
| | | typedef details::buffer image_type; | |
| | | static const bind::buffer_type bind_value = bind::text16; | |
| | | }; | |
| | | | |
| | | struct LIBODB_SQLITE_EXPORT c_wstring_value_traits | |
| { | | { | |
|
| | | typedef const wchar_t* value_type; | |
| | | typedef const wchar_t* query_type; | |
| | | typedef details::buffer image_type; | |
| | | | |
| | | static void | |
| | | set_image (details::buffer&, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const wchar_t*); | |
| }; | | }; | |
| | | | |
|
| template <std::size_t n> | | template <> | |
| struct default_value_traits<const char[n], id_text>: c_string_value_tra | | struct image_traits<const wchar_t*, id_text>: c_wstring_image_traits {} | |
| its | | ; | |
| | | | |
| | | template <> | |
| | | struct LIBODB_SQLITE_EXPORT default_value_traits<const wchar_t*, id_tex | |
| | | t>: | |
| | | c_wstring_value_traits | |
| { | | { | |
| }; | | }; | |
| | | | |
|
| | | template <std::size_t N> | |
| | | struct image_traits<wchar_t[N], id_text>: c_wstring_image_traits {}; | |
| | | | |
| | | template <std::size_t N> | |
| | | struct default_value_traits<wchar_t[N], id_text>: | |
| | | c_wstring_value_traits | |
| | | { | |
| | | }; | |
| | | | |
| | | template <std::size_t N> | |
| | | struct image_traits<const wchar_t[N], id_text>: c_wstring_image_traits | |
| | | {}; | |
| | | | |
| | | template <std::size_t N> | |
| | | struct default_value_traits<const wchar_t[N], id_text>: | |
| | | c_wstring_value_traits | |
| | | { | |
| | | }; | |
| | | #endif // _WIN32 | |
| | | | |
| // std::vector<char> (buffer) specialization. | | // std::vector<char> (buffer) specialization. | |
| // | | // | |
| template <> | | template <> | |
| struct LIBODB_SQLITE_EXPORT default_value_traits< | | struct LIBODB_SQLITE_EXPORT default_value_traits< | |
| std::vector<char>, id_blob> | | std::vector<char>, id_blob> | |
| { | | { | |
| public: | | public: | |
| typedef std::vector<char> value_type; | | typedef std::vector<char> value_type; | |
| typedef std::vector<char> query_type; | | typedef std::vector<char> query_type; | |
| typedef details::buffer image_type; | | typedef details::buffer image_type; | |
| | | | |
| skipping to change at line 332 | | skipping to change at line 471 | |
| v.clear (); | | v.clear (); | |
| } | | } | |
| | | | |
| static void | | static void | |
| set_image (details::buffer&, | | set_image (details::buffer&, | |
| std::size_t& n, | | std::size_t& n, | |
| bool& is_null, | | bool& is_null, | |
| const value_type&); | | const value_type&); | |
| }; | | }; | |
| | | | |
|
| // char[n] (buffer) specialization. | | // char[N] (buffer) specialization. | |
| // | | // | |
| template <std::size_t N> | | template <std::size_t N> | |
| struct default_value_traits<char[N], id_blob> | | struct default_value_traits<char[N], id_blob> | |
| { | | { | |
| public: | | public: | |
| typedef char* value_type; | | typedef char* value_type; | |
| typedef const char* query_type; | | typedef const char* query_type; | |
| typedef details::buffer image_type; | | typedef details::buffer image_type; | |
| | | | |
| static void | | static void | |
| | | | |
| skipping to change at line 370 | | skipping to change at line 509 | |
| is_null = false; | | is_null = false; | |
| n = N; | | n = N; | |
| | | | |
| if (n > b.capacity ()) | | if (n > b.capacity ()) | |
| b.capacity (n); | | b.capacity (n); | |
| | | | |
| std::memcpy (b.data (), v, n); | | std::memcpy (b.data (), v, n); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| // unsigned char[n] (buffer) specialization. | | // unsigned char[N] (buffer) specialization. | |
| // | | // | |
| template <std::size_t N> | | template <std::size_t N> | |
| struct default_value_traits<unsigned char[N], id_blob> | | struct default_value_traits<unsigned char[N], id_blob> | |
| { | | { | |
| public: | | public: | |
| typedef unsigned char* value_type; | | typedef unsigned char* value_type; | |
| typedef const unsigned char* query_type; | | typedef const unsigned char* query_type; | |
| typedef details::buffer image_type; | | typedef details::buffer image_type; | |
| | | | |
| static void | | static void | |
| | | | |
| skipping to change at line 408 | | skipping to change at line 547 | |
| is_null = false; | | is_null = false; | |
| n = N; | | n = N; | |
| | | | |
| if (n > b.capacity ()) | | if (n > b.capacity ()) | |
| b.capacity (n); | | b.capacity (n); | |
| | | | |
| std::memcpy (b.data (), v, n); | | std::memcpy (b.data (), v, n); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| | | #ifdef ODB_CXX11 | |
| | | // std::array<char, N> (buffer) specialization. | |
| | | // | |
| | | template <std::size_t N> | |
| | | struct default_value_traits<std::array<char, N>, id_blob> | |
| | | { | |
| | | public: | |
| | | typedef std::array<char, N> value_type; | |
| | | typedef value_type 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) | |
| | | std::memcpy (v.data (), b.data (), (n < N ? n : N)); | |
| | | else | |
| | | std::memset (v.data (), 0, N); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer& b, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const value_type& v) | |
| | | { | |
| | | is_null = false; | |
| | | n = N; | |
| | | | |
| | | if (n > b.capacity ()) | |
| | | b.capacity (n); | |
| | | | |
| | | std::memcpy (b.data (), v.data (), n); | |
| | | } | |
| | | }; | |
| | | | |
| | | // std::array<unsigned char, N> (buffer) specialization. | |
| | | // | |
| | | template <std::size_t N> | |
| | | struct default_value_traits<std::array<unsigned char, N>, id_blob> | |
| | | { | |
| | | public: | |
| | | typedef std::array<unsigned char, N> value_type; | |
| | | typedef value_type 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) | |
| | | std::memcpy (v.data (), b.data (), (n < N ? n : N)); | |
| | | else | |
| | | std::memset (v.data (), 0, N); | |
| | | } | |
| | | | |
| | | static void | |
| | | set_image (details::buffer& b, | |
| | | std::size_t& n, | |
| | | bool& is_null, | |
| | | const value_type& v) | |
| | | { | |
| | | is_null = false; | |
| | | n = N; | |
| | | | |
| | | if (n > b.capacity ()) | |
| | | b.capacity (n); | |
| | | | |
| | | std::memcpy (b.data (), v.data (), n); | |
| | | } | |
| | | }; | |
| | | #endif | |
| | | | |
| // | | // | |
| // 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 502 | | skipping to change at line 719 | |
| { | | { | |
| static const database_type_id db_type_id = id_real; | | static const database_type_id db_type_id = id_real; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct default_type_traits<double> | | struct default_type_traits<double> | |
| { | | { | |
| static const database_type_id db_type_id = id_real; | | static const database_type_id db_type_id = id_real; | |
| }; | | }; | |
| | | | |
|
| // String type. | | // String types. | |
| // | | // | |
| template <> | | template <> | |
| struct default_type_traits<std::string> | | struct default_type_traits<std::string> | |
| { | | { | |
| static const database_type_id db_type_id = id_text; | | static const database_type_id db_type_id = id_text; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct default_type_traits<const char*> | | struct default_type_traits<const char*> | |
| { | | { | |
| static const database_type_id db_type_id = id_text; | | static const database_type_id db_type_id = id_text; | |
| }; | | }; | |
| | | | |
|
| template <std::size_t n> | | template <std::size_t N> | |
| struct default_type_traits<char[n]> | | struct default_type_traits<char[N]> | |
| { | | { | |
| static const database_type_id db_type_id = id_text; | | static const database_type_id db_type_id = id_text; | |
| }; | | }; | |
| | | | |
|
| template <std::size_t n> | | template <std::size_t N> | |
| struct default_type_traits<const char[n]> | | struct default_type_traits<const char[N]> | |
| { | | { | |
| static const database_type_id db_type_id = id_text; | | static const database_type_id db_type_id = id_text; | |
| }; | | }; | |
|
| | | | |
| | | // Binary types. | |
| | | // | |
| | | template <> | |
| | | struct default_type_traits<std::vector<char> > | |
| | | { | |
| | | static const database_type_id db_type_id = id_blob; | |
| | | }; | |
| | | | |
| | | template <> | |
| | | struct default_type_traits<std::vector<unsigned char> > | |
| | | { | |
| | | static const database_type_id db_type_id = id_blob; | |
| | | }; | |
| | | | |
| | | #ifdef ODB_CXX11 | |
| | | template <std::size_t N> | |
| | | struct default_type_traits<std::array<char, N> > | |
| | | { | |
| | | static const database_type_id db_type_id = id_blob; | |
| | | }; | |
| | | | |
| | | template <std::size_t N> | |
| | | struct default_type_traits<std::array<unsigned char, N> > | |
| | | { | |
| | | static const database_type_id db_type_id = id_blob; | |
| | | }; | |
| | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| #include <odb/post.hxx> | | #include <odb/post.hxx> | |
| | | | |
| #endif // ODB_SQLITE_TRAITS_HXX | | #endif // ODB_SQLITE_TRAITS_HXX | |
| | | | |
End of changes. 24 change blocks. |
| 24 lines changed or deleted | | 272 lines changed or added | |
|