auto-handle.hxx | auto-handle.hxx | |||
---|---|---|---|---|
// file : odb/mysql/auto-handle.hxx | // file : odb/mysql/auto-handle.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_AUTO_HANDLE_HXX | #ifndef ODB_MYSQL_AUTO_HANDLE_HXX | |||
#define ODB_MYSQL_AUTO_HANDLE_HXX | #define ODB_MYSQL_AUTO_HANDLE_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
binding.hxx | binding.hxx | |||
---|---|---|---|---|
// file : odb/mysql/binding.hxx | // file : odb/mysql/binding.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_BINDING_HXX | #ifndef ODB_MYSQL_BINDING_HXX | |||
#define ODB_MYSQL_BINDING_HXX | #define ODB_MYSQL_BINDING_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
config.h | config.h | |||
---|---|---|---|---|
/* odb/mysql/details/config.h. Generated from config.h.in by configure. * / | /* odb/mysql/details/config.h. Generated from config.h.in by configure. * / | |||
/* file : odb/mysql/details/config.h.in | /* file : odb/mysql/details/config.h.in | |||
* copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | * copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
* license : GNU GPL v2; see accompanying LICENSE file | * license : GNU GPL v2; see accompanying LICENSE file | |||
*/ | */ | |||
/* This file is automatically processed by configure. */ | /* This file is automatically processed by configure. */ | |||
#ifndef ODB_MYSQL_DETAILS_CONFIG_H | #ifndef ODB_MYSQL_DETAILS_CONFIG_H | |||
#define ODB_MYSQL_DETAILS_CONFIG_H | #define ODB_MYSQL_DETAILS_CONFIG_H | |||
/* #undef LIBODB_MYSQL_STATIC_LIB */ | /* #undef LIBODB_MYSQL_STATIC_LIB */ | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
config.hxx | config.hxx | |||
---|---|---|---|---|
// file : odb/mysql/details/config.hxx | // file : odb/mysql/details/config.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_DETAILS_CONFIG_HXX | #ifndef ODB_MYSQL_DETAILS_CONFIG_HXX | |||
#define ODB_MYSQL_DETAILS_CONFIG_HXX | #define ODB_MYSQL_DETAILS_CONFIG_HXX | |||
// no pre | // no pre | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
# if !defined(LIBODB_MYSQL_INCLUDE_SHORT) && !defined (LIBODB_MYSQL_INCLUD E_LONG) | # if !defined(LIBODB_MYSQL_INCLUDE_SHORT) && !defined (LIBODB_MYSQL_INCLUD E_LONG) | |||
# define LIBODB_MYSQL_INCLUDE_SHORT 1 | # define LIBODB_MYSQL_INCLUDE_SHORT 1 | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
connection-factory.hxx | connection-factory.hxx | |||
---|---|---|---|---|
// file : odb/mysql/connection-factory.hxx | // file : odb/mysql/connection-factory.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_CONNECTION_FACTORY_HXX | #ifndef ODB_MYSQL_CONNECTION_FACTORY_HXX | |||
#define ODB_MYSQL_CONNECTION_FACTORY_HXX | #define ODB_MYSQL_CONNECTION_FACTORY_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <vector> | #include <vector> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <cassert> | ||||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | #include <odb/mysql/forward.hxx> | |||
#include <odb/mysql/connection.hxx> | #include <odb/mysql/connection.hxx> | |||
#include <odb/details/mutex.hxx> | #include <odb/details/mutex.hxx> | |||
#include <odb/details/condition.hxx> | #include <odb/details/condition.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
skipping to change at line 96 | skipping to change at line 97 | |||
std::size_t min_connections = 0, | std::size_t min_connections = 0, | |||
bool ping = true) | bool ping = true) | |||
: max_ (max_connections), | : max_ (max_connections), | |||
min_ (min_connections), | min_ (min_connections), | |||
ping_ (ping), | ping_ (ping), | |||
in_use_ (0), | in_use_ (0), | |||
waiters_ (0), | waiters_ (0), | |||
db_ (0), | db_ (0), | |||
cond_ (mutex_) | cond_ (mutex_) | |||
{ | { | |||
// @@ check min_ <= max_ | // max_connections == 0 means unlimited. | |||
// | ||||
assert (max_connections == 0 || max_connections >= min_connections) | ||||
; | ||||
} | } | |||
virtual connection_ptr | virtual connection_ptr | |||
connect (); | connect (); | |||
virtual void | virtual void | |||
database (database_type&); | database (database_type&); | |||
virtual | virtual | |||
~connection_pool_factory (); | ~connection_pool_factory (); | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 6 lines changed or added | |||
connection.hxx | connection.hxx | |||
---|---|---|---|---|
// file : odb/mysql/connection.hxx | // file : odb/mysql/connection.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_CONNECTION_HXX | #ifndef ODB_MYSQL_CONNECTION_HXX | |||
#define ODB_MYSQL_CONNECTION_HXX | #define ODB_MYSQL_CONNECTION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <vector> | #include <vector> | |||
#include <odb/forward.hxx> | ||||
#include <odb/connection.hxx> | #include <odb/connection.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | #include <odb/mysql/forward.hxx> | |||
#include <odb/mysql/query.hxx> | ||||
#include <odb/mysql/tracer.hxx> | #include <odb/mysql/tracer.hxx> | |||
#include <odb/mysql/transaction-impl.hxx> | #include <odb/mysql/transaction-impl.hxx> | |||
#include <odb/mysql/auto-handle.hxx> | #include <odb/mysql/auto-handle.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/details/unique-ptr.hxx> | #include <odb/details/unique-ptr.hxx> | |||
#include <odb/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
namespace odb | namespace odb | |||
skipping to change at line 64 | skipping to change at line 64 | |||
public: | public: | |||
virtual transaction_impl* | virtual transaction_impl* | |||
begin (); | begin (); | |||
public: | public: | |||
using odb::connection::execute; | using odb::connection::execute; | |||
virtual unsigned long long | virtual unsigned long long | |||
execute (const char* statement, std::size_t length); | execute (const char* statement, std::size_t length); | |||
// Query preparation. | ||||
// | ||||
public: | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const char*); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const std::string&); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const mysql::query_base&); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const odb::query_base&); | ||||
// SQL statement tracing. | // SQL statement tracing. | |||
// | // | |||
public: | public: | |||
typedef mysql::tracer tracer_type; | typedef mysql::tracer tracer_type; | |||
void | void | |||
tracer (tracer_type& t) | tracer (tracer_type& t) | |||
{ | { | |||
odb::connection::tracer (t); | odb::connection::tracer (t); | |||
} | } | |||
skipping to change at line 160 | skipping to change at line 179 | |||
connection& operator= (const connection&); | connection& operator= (const connection&); | |||
private: | private: | |||
void | void | |||
free_stmt_handles (); | free_stmt_handles (); | |||
void | void | |||
clear_ (); | clear_ (); | |||
private: | private: | |||
friend class transaction_impl; // invalidate_results() | ||||
private: | ||||
// Needed to break the circular connection-database dependency | // Needed to break the circular connection-database dependency | |||
// (odb::connection has the odb::database member). | // (odb::connection has the odb::database member). | |||
// | // | |||
database_type& db_; | database_type& db_; | |||
bool failed_; | bool failed_; | |||
MYSQL mysql_; | MYSQL mysql_; | |||
auto_handle<MYSQL> handle_; | auto_handle<MYSQL> handle_; | |||
skipping to change at line 186 | skipping to change at line 208 | |||
// List of "delayed" statement handles to be freed next time there | // List of "delayed" statement handles to be freed next time there | |||
// is no active statement. | // is no active statement. | |||
// | // | |||
typedef std::vector<MYSQL_STMT*> stmt_handles; | typedef std::vector<MYSQL_STMT*> stmt_handles; | |||
stmt_handles stmt_handles_; | stmt_handles stmt_handles_; | |||
}; | }; | |||
} | } | |||
} | } | |||
#include <odb/mysql/connection.ixx> | ||||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_MYSQL_CONNECTION_HXX | #endif // ODB_MYSQL_CONNECTION_HXX | |||
End of changes. 6 change blocks. | ||||
2 lines changed or deleted | 26 lines changed or added | |||
container-statements.hxx | container-statements.hxx | |||
---|---|---|---|---|
// file : odb/mysql/container-statements.hxx | // file : odb/mysql/container-statements.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_CONTAINER_STATEMENTS_HXX | #ifndef ODB_MYSQL_CONTAINER_STATEMENTS_HXX | |||
#define ODB_MYSQL_CONTAINER_STATEMENTS_HXX | #define ODB_MYSQL_CONTAINER_STATEMENTS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
skipping to change at line 37 | skipping to change at line 37 | |||
// Template argument is the generated abstract container traits type. | // Template argument is the generated abstract container traits type. | |||
// That is, it doesn't need to provide column counts and statements. | // That is, it doesn't need to provide column counts and statements. | |||
// | // | |||
template <typename T> | template <typename T> | |||
class container_statements | class container_statements | |||
{ | { | |||
public: | public: | |||
typedef T traits; | typedef T traits; | |||
typedef typename traits::data_image_type data_image_type; | typedef typename traits::data_image_type data_image_type; | |||
typedef typename traits::cond_image_type cond_image_type; | ||||
typedef typename traits::functions_type functions_type; | typedef typename traits::functions_type functions_type; | |||
typedef mysql::insert_statement insert_statement_type; | typedef mysql::insert_statement insert_statement_type; | |||
typedef mysql::select_statement select_statement_type; | typedef mysql::select_statement select_statement_type; | |||
typedef mysql::delete_statement delete_statement_type; | typedef mysql::delete_statement delete_statement_type; | |||
typedef mysql::connection connection_type; | typedef mysql::connection connection_type; | |||
container_statements (connection_type&); | container_statements (connection_type&, binding& id_binding); | |||
connection_type& | connection_type& | |||
connection () | connection () | |||
{ | { | |||
return conn_; | return conn_; | |||
} | } | |||
// Functions. | // Functions. | |||
// | // | |||
functions_type& | functions_type& | |||
functions () | functions () | |||
{ | { | |||
return functions_; | return functions_; | |||
} | } | |||
// Id image binding (external). | // Id image binding (external). | |||
// | // | |||
const binding& | const binding& | |||
id_binding () | id_binding () | |||
{ | { | |||
return *id_binding_; | return id_binding_; | |||
} | } | |||
void | // Data image. The image is split into the id (that comes as a | |||
id_binding (const binding& b) | // binding) and index/key plus value which are in data_image_type. | |||
// The select binding is a subset of the full binding (no id). | ||||
// | ||||
data_image_type& | ||||
data_image () | ||||
{ | { | |||
id_binding_ = &b; | return data_image_; | |||
} | } | |||
// Condition image. | MYSQL_BIND* | |||
// | data_bind () | |||
cond_image_type& | ||||
cond_image () | ||||
{ | { | |||
return cond_image_; | return insert_image_binding_.bind; | |||
} | } | |||
std::size_t | bool | |||
cond_image_version () const | data_binding_test_version () const | |||
{ | { | |||
return cond_image_version_; | return data_id_binding_version_ != id_binding_.version || | |||
data_image_version_ != data_image_.version || | ||||
insert_image_binding_.version == 0; | ||||
} | } | |||
void | void | |||
cond_image_version (std::size_t v) | data_binding_update_version () | |||
{ | { | |||
cond_image_version_ = v; | data_id_binding_version_ = id_binding_.version; | |||
data_image_version_ = data_image_.version; | ||||
insert_image_binding_.version++; | ||||
select_image_binding_.version++; | ||||
} | } | |||
std::size_t | my_bool* | |||
cond_id_binding_version () const | select_image_truncated () | |||
{ | { | |||
return cond_id_binding_version_; | return select_image_truncated_; | |||
} | } | |||
void | // | |||
cond_id_binding_version (std::size_t v) | // Statements. | |||
// | ||||
insert_statement_type& | ||||
insert_statement () | ||||
{ | { | |||
cond_id_binding_version_ = v; | if (insert_ == 0) | |||
insert_.reset ( | ||||
new (details::shared) insert_statement_type ( | ||||
conn_, insert_text_, insert_image_binding_, false)); | ||||
return *insert_; | ||||
} | } | |||
binding& | select_statement_type& | |||
cond_image_binding () | select_statement () | |||
{ | { | |||
return cond_image_binding_; | if (select_ == 0) | |||
select_.reset ( | ||||
new (details::shared) select_statement_type ( | ||||
conn_, | ||||
select_text_, | ||||
id_binding_, | ||||
select_image_binding_, | ||||
false)); | ||||
return *select_; | ||||
} | } | |||
// Data image. | delete_statement_type& | |||
// | delete_statement () | |||
data_image_type& | ||||
data_image () | ||||
{ | { | |||
return data_image_; | if (delete_ == 0) | |||
delete_.reset ( | ||||
new (details::shared) delete_statement_type ( | ||||
conn_, delete_text_, id_binding_, false)); | ||||
return *delete_; | ||||
} | } | |||
std::size_t | private: | |||
data_image_version () const | container_statements (const container_statements&); | |||
container_statements& operator= (const container_statements&); | ||||
protected: | ||||
connection_type& conn_; | ||||
binding& id_binding_; | ||||
functions_type functions_; | ||||
data_image_type data_image_; | ||||
std::size_t data_image_version_; | ||||
std::size_t data_id_binding_version_; | ||||
binding insert_image_binding_; | ||||
binding select_image_binding_; | ||||
my_bool* select_image_truncated_; | ||||
const char* insert_text_; | ||||
const char* select_text_; | ||||
const char* delete_text_; | ||||
details::shared_ptr<insert_statement_type> insert_; | ||||
details::shared_ptr<select_statement_type> select_; | ||||
details::shared_ptr<delete_statement_type> delete_; | ||||
}; | ||||
template <typename T> | ||||
class smart_container_statements: public container_statements<T> | ||||
{ | ||||
public: | ||||
typedef T traits; | ||||
typedef typename traits::cond_image_type cond_image_type; | ||||
typedef mysql::update_statement update_statement_type; | ||||
typedef mysql::delete_statement delete_statement_type; | ||||
typedef mysql::connection connection_type; | ||||
smart_container_statements (connection_type&, binding& id_binding); | ||||
// Condition image. The image is split into the id (that comes as | ||||
// a binding) and index/key/value which is in cond_image_type. | ||||
// | ||||
cond_image_type& | ||||
cond_image () | ||||
{ | { | |||
return data_image_version_; | return cond_image_; | |||
} | } | |||
void | MYSQL_BIND* | |||
data_image_version (std::size_t v) | cond_bind () | |||
{ | { | |||
data_image_version_ = v; | return cond_image_binding_.bind; | |||
} | } | |||
std::size_t | bool | |||
data_id_binding_version () const | cond_binding_test_version () const | |||
{ | { | |||
return data_id_binding_version_; | return cond_id_binding_version_ != this->id_binding_.version || | |||
cond_image_version_ != cond_image_.version || | ||||
cond_image_binding_.version == 0; | ||||
} | } | |||
void | void | |||
data_id_binding_version (std::size_t v) | cond_binding_update_version () | |||
{ | { | |||
data_id_binding_version_ = v; | cond_id_binding_version_ = this->id_binding_.version; | |||
cond_image_version_ = cond_image_.version; | ||||
cond_image_binding_.version++; | ||||
} | } | |||
binding& | // Update image. The image is split as follows: value comes | |||
data_image_binding () | // from the data image, id comes as binding, and index/key | |||
// comes from the condition image. | ||||
// | ||||
MYSQL_BIND* | ||||
update_bind () | ||||
{ | { | |||
return data_image_binding_; | return update_image_binding_.bind; | |||
} | } | |||
binding& | bool | |||
select_image_binding () | update_binding_test_version () const | |||
{ | { | |||
return select_image_binding_; | return update_id_binding_version_ != this->id_binding_.version || | |||
update_cond_image_version_ != cond_image_.version || | ||||
update_data_image_version_ != this->data_image_.version || | ||||
update_image_binding_.version == 0; | ||||
} | } | |||
my_bool* | void | |||
select_image_truncated () | update_binding_update_version () | |||
{ | { | |||
return select_image_truncated_; | update_id_binding_version_ = this->id_binding_.version; | |||
update_cond_image_version_ = cond_image_.version; | ||||
update_data_image_version_ = this->data_image_.version; | ||||
update_image_binding_.version++; | ||||
} | } | |||
// | // | |||
// Statements. | // Statements. | |||
// | // | |||
insert_statement_type& | delete_statement_type& | |||
insert_one_statement () | delete_statement () | |||
{ | ||||
if (insert_one_ == 0) | ||||
insert_one_.reset ( | ||||
new (details::shared) insert_statement_type ( | ||||
conn_, insert_one_text_, data_image_binding_, false)); | ||||
return *insert_one_; | ||||
} | ||||
select_statement_type& | ||||
select_all_statement () | ||||
{ | { | |||
if (select_all_ == 0) | if (this->delete_ == 0) | |||
select_all_.reset ( | this->delete_.reset ( | |||
new (details::shared) select_statement_type ( | new (details::shared) delete_statement_type ( | |||
conn_, | this->conn_, | |||
select_all_text_, | this->delete_text_, | |||
cond_image_binding_, | this->cond_image_binding_, | |||
select_image_binding_, | ||||
false)); | false)); | |||
return *select_all_; | return *this->delete_; | |||
} | } | |||
delete_statement_type& | update_statement_type& | |||
delete_all_statement () | update_statement () | |||
{ | { | |||
if (delete_all_ == 0) | if (update_ == 0) | |||
delete_all_.reset ( | update_.reset ( | |||
new (details::shared) delete_statement_type ( | new (details::shared) update_statement_type ( | |||
conn_, delete_all_text_, cond_image_binding_, false)); | this->conn_, | |||
update_text_, | ||||
update_image_binding_, | ||||
false)); | ||||
return *delete_all_; | return *update_; | |||
} | } | |||
private: | ||||
container_statements (const container_statements&); | ||||
container_statements& operator= (const container_statements&); | ||||
protected: | protected: | |||
connection_type& conn_; | ||||
functions_type functions_; | ||||
const binding* id_binding_; | ||||
cond_image_type cond_image_; | cond_image_type cond_image_; | |||
std::size_t cond_image_version_; | std::size_t cond_image_version_; | |||
std::size_t cond_id_binding_version_; | std::size_t cond_id_binding_version_; | |||
binding cond_image_binding_; | binding cond_image_binding_; | |||
data_image_type data_image_; | std::size_t update_id_binding_version_; | |||
std::size_t data_image_version_; | std::size_t update_cond_image_version_; | |||
std::size_t data_id_binding_version_; | std::size_t update_data_image_version_; | |||
binding update_image_binding_; | ||||
binding data_image_binding_; | const char* update_text_; | |||
// Skips the id from data_image_binding. | details::shared_ptr<update_statement_type> update_; | |||
// | ||||
binding select_image_binding_; | ||||
my_bool* select_image_truncated_; | ||||
const char* insert_one_text_; | ||||
const char* select_all_text_; | ||||
const char* delete_all_text_; | ||||
details::shared_ptr<insert_statement_type> insert_one_; | ||||
details::shared_ptr<select_statement_type> select_all_; | ||||
details::shared_ptr<delete_statement_type> delete_all_; | ||||
}; | }; | |||
// Template argument is the generated concrete container traits type. | // Template argument is the generated concrete container traits type. | |||
// | // | |||
template <typename T> | template <typename T> | |||
class container_statements_impl: public T::statements_type | class container_statements_impl: public T::statements_type | |||
{ | { | |||
public: | public: | |||
typedef T traits; | typedef T traits; | |||
typedef typename T::statements_type base; | typedef typename T::statements_type base; | |||
typedef mysql::connection connection_type; | typedef mysql::connection connection_type; | |||
container_statements_impl (connection_type&); | container_statements_impl (connection_type&, binding&); | |||
private: | private: | |||
container_statements_impl (const container_statements_impl&); | container_statements_impl (const container_statements_impl&); | |||
container_statements_impl& operator= (const container_statements_impl &); | container_statements_impl& operator= (const container_statements_impl &); | |||
private: | private: | |||
MYSQL_BIND cond_image_bind_[traits::cond_column_count]; | ||||
MYSQL_BIND data_image_bind_[traits::data_column_count]; | MYSQL_BIND data_image_bind_[traits::data_column_count]; | |||
my_bool select_image_truncated_array_[traits::data_column_count - | my_bool select_image_truncated_array_[traits::data_column_count - | |||
traits::id_column_count]; | traits::id_column_count]; | |||
}; | }; | |||
template <typename T> | ||||
class smart_container_statements_impl: public container_statements_impl | ||||
<T> | ||||
{ | ||||
public: | ||||
typedef T traits; | ||||
typedef mysql::connection connection_type; | ||||
smart_container_statements_impl (connection_type&, binding&); | ||||
private: | ||||
MYSQL_BIND cond_image_bind_[traits::cond_column_count]; | ||||
MYSQL_BIND update_image_bind_[traits::value_column_count + | ||||
traits::cond_column_count]; | ||||
}; | ||||
} | } | |||
} | } | |||
#include <odb/mysql/container-statements.txx> | #include <odb/mysql/container-statements.txx> | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_MYSQL_CONTAINER_STATEMENTS_HXX | #endif // ODB_MYSQL_CONTAINER_STATEMENTS_HXX | |||
End of changes. 48 change blocks. | ||||
107 lines changed or deleted | 179 lines changed or added | |||
container-statements.txx | container-statements.txx | |||
---|---|---|---|---|
// file : odb/mysql/container-statements.txx | // file : odb/mysql/container-statements.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <cstring> // std::memset | #include <cstring> // std::memset | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
// container_statements | // container_statements | |||
// | // | |||
template <typename T> | template <typename T> | |||
container_statements<T>:: | container_statements<T>:: | |||
container_statements (connection_type& conn) | container_statements (connection_type& conn, binding& id) | |||
: conn_ (conn), | : conn_ (conn), | |||
functions_ (this, | id_binding_ (id), | |||
&traits::insert_one, | functions_ (this), | |||
&traits::load_all, | insert_image_binding_ (0, 0), // Initialized by impl. | |||
&traits::delete_all), | select_image_binding_ (0, 0) // Initialized by impl. | |||
id_binding_ (0), | { | |||
functions_.insert_ = &traits::insert; | ||||
functions_.select_ = &traits::select; | ||||
functions_.delete__ = &traits::delete_; | ||||
data_image_.version = 0; | ||||
data_image_version_ = 0; | ||||
data_id_binding_version_ = 0; | ||||
} | ||||
// smart_container_statements | ||||
// | ||||
template <typename T> | ||||
smart_container_statements<T>:: | ||||
smart_container_statements (connection_type& conn, binding& id) | ||||
: container_statements<T> (conn, id), | ||||
cond_image_binding_ (0, 0), // Initialized by impl. | cond_image_binding_ (0, 0), // Initialized by impl. | |||
data_image_binding_ (0, 0), // Initialized by impl. | update_image_binding_ (0, 0) // Initialized by impl. | |||
select_image_binding_ (0, 0) // Initialized by impl. | ||||
{ | { | |||
this->functions_.update_ = &traits::update; | ||||
cond_image_.version = 0; | cond_image_.version = 0; | |||
cond_image_version_ = 0; | cond_image_version_ = 0; | |||
cond_id_binding_version_ = 0; | cond_id_binding_version_ = 0; | |||
data_image_.version = 0; | update_id_binding_version_ = 0; | |||
data_image_version_ = 0; | update_cond_image_version_ = 0; | |||
data_id_binding_version_ = 0; | update_data_image_version_ = 0; | |||
} | } | |||
// container_statements_impl | ||||
// | ||||
template <typename T> | template <typename T> | |||
container_statements_impl<T>:: | container_statements_impl<T>:: | |||
container_statements_impl (connection_type& conn) | container_statements_impl (connection_type& conn, binding& id) | |||
: base (conn) | : base (conn, id) | |||
{ | { | |||
this->select_image_truncated_ = select_image_truncated_array_; | this->select_image_truncated_ = select_image_truncated_array_; | |||
this->cond_image_binding_.bind = cond_image_bind_; | this->insert_image_binding_.bind = data_image_bind_; | |||
this->cond_image_binding_.count = traits::cond_column_count; | this->insert_image_binding_.count = traits::data_column_count; | |||
this->data_image_binding_.bind = data_image_bind_; | ||||
this->data_image_binding_.count = traits::data_column_count; | ||||
this->select_image_binding_.bind = data_image_bind_ + | this->select_image_binding_.bind = data_image_bind_ + | |||
traits::id_column_count; | traits::id_column_count; | |||
this->select_image_binding_.count = traits::data_column_count - | this->select_image_binding_.count = traits::data_column_count - | |||
traits::id_column_count; | traits::id_column_count; | |||
std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); | ||||
std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); | std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); | |||
std::memset (select_image_truncated_array_, | std::memset (select_image_truncated_array_, | |||
0, | 0, | |||
sizeof (select_image_truncated_array_)); | sizeof (select_image_truncated_array_)); | |||
for (std::size_t i (0); | for (std::size_t i (0); | |||
i < traits::data_column_count - traits::id_column_count; | i < traits::data_column_count - traits::id_column_count; | |||
++i) | ++i) | |||
data_image_bind_[i + traits::id_column_count].error = | data_image_bind_[i + traits::id_column_count].error = | |||
select_image_truncated_array_ + i; | select_image_truncated_array_ + i; | |||
this->insert_one_text_ = traits::insert_one_statement; | this->insert_text_ = traits::insert_statement; | |||
this->select_all_text_ = traits::select_all_statement; | this->select_text_ = traits::select_statement; | |||
this->delete_all_text_ = traits::delete_all_statement; | this->delete_text_ = traits::delete_statement; | |||
} | ||||
// smart_container_statements_impl | ||||
// | ||||
template <typename T> | ||||
smart_container_statements_impl<T>:: | ||||
smart_container_statements_impl (connection_type& conn, binding& id) | ||||
: container_statements_impl<T> (conn, id) | ||||
{ | ||||
this->cond_image_binding_.bind = cond_image_bind_; | ||||
this->cond_image_binding_.count = traits::cond_column_count; | ||||
this->update_image_binding_.bind = update_image_bind_; | ||||
this->update_image_binding_.count = traits::value_column_count + | ||||
traits::cond_column_count; | ||||
std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); | ||||
std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); | ||||
this->update_text_ = traits::update_statement; | ||||
} | } | |||
} | } | |||
} | } | |||
End of changes. 12 change blocks. | ||||
24 lines changed or deleted | 57 lines changed or added | |||
conversion.hxx | conversion.hxx | |||
---|---|---|---|---|
// file : odb/mysql/details/conversion.hxx | // file : odb/mysql/details/conversion.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_DETAILS_CONVERSION_HXX | #ifndef ODB_MYSQL_DETAILS_CONVERSION_HXX | |||
#define ODB_MYSQL_DETAILS_CONVERSION_HXX | #define ODB_MYSQL_DETAILS_CONVERSION_HXX | |||
#include <odb/mysql/traits.hxx> | #include <odb/mysql/traits.hxx> | |||
#include <odb/details/meta/answer.hxx> | #include <odb/details/meta/answer.hxx> | |||
namespace odb | namespace odb | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
database.hxx | database.hxx | |||
---|---|---|---|---|
// file : odb/mysql/database.hxx | // file : odb/mysql/database.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_DATABASE_HXX | #ifndef ODB_MYSQL_DATABASE_HXX | |||
#define ODB_MYSQL_DATABASE_HXX | #define ODB_MYSQL_DATABASE_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <string> | #include <string> | |||
#include <memory> // std::auto_ptr, std::unique_ptr | #include <memory> // std::auto_ptr, std::unique_ptr | |||
#include <iosfwd> // std::ostream | #include <iosfwd> // std::ostream | |||
#include <odb/database.hxx> | #include <odb/database.hxx> | |||
#include <odb/details/unique-ptr.hxx> | #include <odb/details/unique-ptr.hxx> | |||
#include <odb/details/transfer-ptr.hxx> | #include <odb/details/transfer-ptr.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | #include <odb/mysql/forward.hxx> | |||
#include <odb/mysql/query.hxx> | ||||
#include <odb/mysql/tracer.hxx> | #include <odb/mysql/tracer.hxx> | |||
#include <odb/mysql/connection.hxx> | #include <odb/mysql/connection.hxx> | |||
#include <odb/mysql/connection-factory.hxx> | #include <odb/mysql/connection-factory.hxx> | |||
#include <odb/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
skipping to change at line 170 | skipping to change at line 171 | |||
{ | { | |||
return charset_.c_str (); | return charset_.c_str (); | |||
} | } | |||
unsigned long | unsigned long | |||
client_flags () const | client_flags () const | |||
{ | { | |||
return client_flags_; | return client_flags_; | |||
} | } | |||
// Object persistence API. | ||||
// | ||||
public: | ||||
// Make the object persistent. | ||||
// | ||||
template <typename T> | ||||
typename object_traits<T>::id_type | ||||
persist (T& object); | ||||
template <typename T> | ||||
typename object_traits<T>::id_type | ||||
persist (T* obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
typename object_traits<T>::id_type | ||||
persist (const P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
typename object_traits<T>::id_type | ||||
persist (const P<T, A1>& obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
typename object_traits<T>::id_type | ||||
persist (P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
typename object_traits<T>::id_type | ||||
persist (P<T, A1>& obj_ptr); | ||||
template <typename T> | ||||
typename object_traits<T>::id_type | ||||
persist (const typename object_traits<T>::pointer_type& obj_ptr); | ||||
// Load an object. Throw object_not_persistent if not found. | ||||
// | ||||
template <typename T> | ||||
typename object_traits<T>::pointer_type | ||||
load (const typename object_traits<T>::id_type& id); | ||||
template <typename T> | ||||
void | ||||
load (const typename object_traits<T>::id_type& id, T& object); | ||||
// Reload an object. | ||||
// | ||||
template <typename T> | ||||
void | ||||
reload (T& object); | ||||
template <typename T> | ||||
void | ||||
reload (T* obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
reload (const P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
reload (const P<T, A1>& obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
reload (P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
reload (P<T, A1>& obj_ptr); | ||||
template <typename T> | ||||
void | ||||
reload (const typename object_traits<T>::pointer_type& obj_ptr); | ||||
// Loan an object if found. Return NULL/false if not found. | ||||
// | ||||
template <typename T> | ||||
typename object_traits<T>::pointer_type | ||||
find (const typename object_traits<T>::id_type& id); | ||||
template <typename T> | ||||
bool | ||||
find (const typename object_traits<T>::id_type& id, T& object); | ||||
// Update the state of a modified objects. | ||||
// | ||||
template <typename T> | ||||
void | ||||
update (T& object); | ||||
template <typename T> | ||||
void | ||||
update (T* obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
update (const P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
update (const P<T, A1>& obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
update (P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
update (P<T, A1>& obj_ptr); | ||||
template <typename T> | ||||
void | ||||
update (const typename object_traits<T>::pointer_type& obj_ptr); | ||||
// Make the object transient. Throw object_not_persistent if not | ||||
// found. | ||||
// | ||||
template <typename T> | ||||
void | ||||
erase (const typename object_traits<T>::id_type& id); | ||||
template <typename T> | ||||
void | ||||
erase (T& object); | ||||
template <typename T> | ||||
void | ||||
erase (T* obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
erase (const P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
erase (const P<T, A1>& obj_ptr); | ||||
template <typename T, template <typename> class P> | ||||
void | ||||
erase (P<T>& obj_ptr); | ||||
template <typename T, typename A1, template <typename, typename> clas | ||||
s P> | ||||
void | ||||
erase (P<T, A1>& obj_ptr); | ||||
template <typename T> | ||||
void | ||||
erase (const typename object_traits<T>::pointer_type& obj_ptr); | ||||
// Erase multiple objects matching a query predicate. | ||||
// | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (); | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (const char*); | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (const std::string&); | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (const mysql::query_base&); | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (const odb::query_base&); | ||||
// Query API. | ||||
// | ||||
template <typename T> | ||||
result<T> | ||||
query (bool cache = true); | ||||
template <typename T> | ||||
result<T> | ||||
query (const char*, bool cache = true); | ||||
template <typename T> | ||||
result<T> | ||||
query (const std::string&, bool cache = true); | ||||
template <typename T> | ||||
result<T> | ||||
query (const mysql::query_base&, bool cache = true); | ||||
template <typename T> | ||||
result<T> | ||||
query (const odb::query_base&, bool cache = true); | ||||
// Query preparation. | ||||
// | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const char*); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const std::string&); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const mysql::query_base&); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const odb::query_base&); | ||||
// Transactions. | ||||
// | ||||
public: | public: | |||
virtual transaction_impl* | virtual transaction_impl* | |||
begin (); | begin (); | |||
public: | public: | |||
connection_ptr | connection_ptr | |||
connection (); | connection (); | |||
// SQL statement tracing. | // SQL statement tracing. | |||
// | // | |||
skipping to change at line 198 | skipping to change at line 412 | |||
void | void | |||
tracer (tracer_type* t) | tracer (tracer_type* t) | |||
{ | { | |||
odb::database::tracer (t); | odb::database::tracer (t); | |||
} | } | |||
using odb::database::tracer; | using odb::database::tracer; | |||
public: | public: | |||
// Database id constant (useful for meta-programming). | ||||
// | ||||
static const odb::database_id database_id = id_mysql; | ||||
public: | ||||
virtual | virtual | |||
~database (); | ~database (); | |||
protected: | protected: | |||
virtual odb::connection* | virtual odb::connection* | |||
connection_ (); | connection_ (); | |||
private: | private: | |||
std::string user_; | std::string user_; | |||
std::string passwd_str_; | std::string passwd_str_; | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 228 lines changed or added | |||
database.ixx | database.ixx | |||
---|---|---|---|---|
// file : odb/mysql/database.ixx | // file : odb/mysql/database.ixx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <odb/mysql/transaction.hxx> | ||||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
inline connection_ptr database:: | inline connection_ptr database:: | |||
connection () | connection () | |||
{ | { | |||
// Go through the virtual connection_() function instead of | // Go through the virtual connection_() function instead of | |||
// directly to allow overriding. | // directly to allow overriding. | |||
// | // | |||
return connection_ptr ( | return connection_ptr ( | |||
static_cast<mysql::connection*> (connection_ ())); | static_cast<mysql::connection*> (connection_ ())); | |||
} | } | |||
template <typename T> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (T& obj) | ||||
{ | ||||
return persist_<T, id_mysql> (obj); | ||||
} | ||||
template <typename T> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (T* p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
return persist_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (const P<T>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
return persist_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (const P<T, A1>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
return persist_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (P<T>& p) | ||||
{ | ||||
const P<T>& cr (p); | ||||
return persist<T, P> (cr); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (P<T, A1>& p) | ||||
{ | ||||
const P<T, A1>& cr (p); | ||||
return persist<T, A1, P> (cr); | ||||
} | ||||
template <typename T> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (const typename object_traits<T>::pointer_type& pobj) | ||||
{ | ||||
return persist_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T> | ||||
inline typename object_traits<T>::pointer_type database:: | ||||
load (const typename object_traits<T>::id_type& id) | ||||
{ | ||||
return load_<T, id_mysql> (id); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
load (const typename object_traits<T>::id_type& id, T& obj) | ||||
{ | ||||
return load_<T, id_mysql> (id, obj); | ||||
} | ||||
template <typename T> | ||||
inline typename object_traits<T>::pointer_type database:: | ||||
find (const typename object_traits<T>::id_type& id) | ||||
{ | ||||
return find_<T, id_mysql> (id); | ||||
} | ||||
template <typename T> | ||||
inline bool database:: | ||||
find (const typename object_traits<T>::id_type& id, T& obj) | ||||
{ | ||||
return find_<T, id_mysql> (id, obj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
reload (T& obj) | ||||
{ | ||||
reload_<T, id_mysql> (obj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
reload (T* p) | ||||
{ | ||||
reload<T> (*p); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
reload (const P<T>& p) | ||||
{ | ||||
reload (odb::pointer_traits< P<T> >::get_ref (p)); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
reload (const P<T, A1>& p) | ||||
{ | ||||
reload (odb::pointer_traits< P<T, A1> >::get_ref (p)); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
reload (P<T>& p) | ||||
{ | ||||
reload (odb::pointer_traits< P<T> >::get_ref (p)); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
reload (P<T, A1>& p) | ||||
{ | ||||
reload (odb::pointer_traits< P<T, A1> >::get_ref (p)); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
reload (const typename object_traits<T>::pointer_type& pobj) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type pointer_type; | ||||
reload (odb::pointer_traits<pointer_type>::get_ref (pobj)); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
update (T& obj) | ||||
{ | ||||
update_<T, id_mysql> (obj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
update (T* p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
update_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
update (const P<T>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
update_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
update (const P<T, A1>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
update_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
update (P<T>& p) | ||||
{ | ||||
const P<T>& cr (p); | ||||
update<T, P> (cr); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
update (P<T, A1>& p) | ||||
{ | ||||
const P<T, A1>& cr (p); | ||||
update<T, A1, P> (cr); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
update (const typename object_traits<T>::pointer_type& pobj) | ||||
{ | ||||
update_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (const typename object_traits<T>::id_type& id) | ||||
{ | ||||
return erase_<T, id_mysql> (id); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (T& obj) | ||||
{ | ||||
return erase_<T, id_mysql> (obj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (T* p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
erase_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
erase (const P<T>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
erase_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
erase (const P<T, A1>& p) | ||||
{ | ||||
typedef typename object_traits<T>::pointer_type object_pointer; | ||||
// The passed pointer should be the same or implicit-convertible | ||||
// to the object pointer. This way we make sure the object pointer | ||||
// does not assume ownership of the passed object. | ||||
// | ||||
const object_pointer& pobj (p); | ||||
erase_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T, template <typename> class P> | ||||
inline void database:: | ||||
erase (P<T>& p) | ||||
{ | ||||
const P<T>& cr (p); | ||||
erase<T, P> (cr); | ||||
} | ||||
template <typename T, typename A1, template <typename, typename> class | ||||
P> | ||||
inline void database:: | ||||
erase (P<T, A1>& p) | ||||
{ | ||||
const P<T, A1>& cr (p); | ||||
erase<T, A1, P> (cr); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (const typename object_traits<T>::pointer_type& pobj) | ||||
{ | ||||
erase_<T, id_mysql> (pobj); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query () | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return erase_query<T> (mysql::query_base ()); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const char* q) | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return erase_query<T> (mysql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const std::string& q) | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return erase_query<T> (mysql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const mysql::query_base& q) | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return object_traits_impl<T, id_mysql>::erase_query (*this, q); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const odb::query_base& q) | ||||
{ | ||||
// Translate to native query. | ||||
// | ||||
return erase_query<T> (mysql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (bool cache) | ||||
{ | ||||
return query<T> (mysql::query_base (), cache); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const char* q, bool cache) | ||||
{ | ||||
return query<T> (mysql::query_base (q), cache); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const std::string& q, bool cache) | ||||
{ | ||||
return query<T> (mysql::query_base (q), cache); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const mysql::query_base& q, bool cache) | ||||
{ | ||||
// T is always object_type. We also don't need to check for transacti | ||||
on | ||||
// here; object_traits::query () does this. | ||||
// | ||||
result<T> r (query_<T, id_mysql>::call (*this, q)); | ||||
if (cache) | ||||
r.cache (); | ||||
return r; | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const odb::query_base& q, bool cache) | ||||
{ | ||||
// Translate to native query. | ||||
// | ||||
return query<T> (mysql::query_base (q), cache); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const char* q) | ||||
{ | ||||
return prepare_query<T> (n, mysql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const std::string& q) | ||||
{ | ||||
return prepare_query<T> (n, mysql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const mysql::query_base& q) | ||||
{ | ||||
// Throws if not in transaction. | ||||
// | ||||
mysql::connection& c (transaction::current ().connection ()); | ||||
return c.prepare_query<T> (n, q); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const odb::query_base& q) | ||||
{ | ||||
// Translate to native query. | ||||
// | ||||
return prepare_query<T> (n, mysql::query_base (q)); | ||||
} | ||||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 446 lines changed or added | |||
enum.hxx | enum.hxx | |||
---|---|---|---|---|
// file : odb/mysql/enums.hxx | // file : odb/mysql/enums.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_ENUMS_HXX | #ifndef ODB_MYSQL_ENUMS_HXX | |||
#define ODB_MYSQL_ENUMS_HXX | #define ODB_MYSQL_ENUMS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <cstring> // std::memmove | #include <cstring> // std::memmove | |||
#include <cassert> | #include <cassert> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
error.hxx | error.hxx | |||
---|---|---|---|---|
// file : odb/mysql/error.hxx | // file : odb/mysql/error.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_ERROR_HXX | #ifndef ODB_MYSQL_ERROR_HXX | |||
#define ODB_MYSQL_ERROR_HXX | #define ODB_MYSQL_ERROR_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
exceptions.hxx | exceptions.hxx | |||
---|---|---|---|---|
// file : odb/mysql/exceptions.hxx | // file : odb/mysql/exceptions.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_EXCEPTIONS_HXX | #ifndef ODB_MYSQL_EXCEPTIONS_HXX | |||
#define ODB_MYSQL_EXCEPTIONS_HXX | #define ODB_MYSQL_EXCEPTIONS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <string> | #include <string> | |||
#include <odb/exceptions.hxx> | #include <odb/exceptions.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | ||||
#include <odb/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
struct LIBODB_MYSQL_EXPORT database_exception: odb::database_exception | struct LIBODB_MYSQL_EXPORT database_exception: odb::database_exception | |||
{ | { | |||
database_exception (unsigned int, | database_exception (unsigned int, | |||
skipping to change at line 69 | skipping to change at line 70 | |||
{ | { | |||
cli_exception (const std::string& what); | cli_exception (const std::string& what); | |||
~cli_exception () throw (); | ~cli_exception () throw (); | |||
virtual const char* | virtual const char* | |||
what () const throw (); | what () const throw (); | |||
private: | private: | |||
std::string what_; | std::string what_; | |||
}; | }; | |||
namespace core | ||||
{ | ||||
using mysql::database_exception; | ||||
using mysql::cli_exception; | ||||
} | ||||
} | } | |||
} | } | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_MYSQL_EXCEPTIONS_HXX | #endif // ODB_MYSQL_EXCEPTIONS_HXX | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 8 lines changed or added | |||
export.hxx | export.hxx | |||
---|---|---|---|---|
// file : odb/mysql/details/export.hxx | // file : odb/mysql/details/export.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_DETAILS_EXPORT_HXX | #ifndef ODB_MYSQL_DETAILS_EXPORT_HXX | |||
#define ODB_MYSQL_DETAILS_EXPORT_HXX | #define ODB_MYSQL_DETAILS_EXPORT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/mysql/details/config.hxx> | #include <odb/mysql/details/config.hxx> | |||
#ifdef LIBODB_MYSQL_STATIC_LIB | #ifdef LIBODB_MYSQL_STATIC_LIB | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
forward.hxx | forward.hxx | |||
---|---|---|---|---|
// file : odb/mysql/forward.hxx | // file : odb/mysql/forward.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_FORWARD_HXX | #ifndef ODB_MYSQL_FORWARD_HXX | |||
#define ODB_MYSQL_FORWARD_HXX | #define ODB_MYSQL_FORWARD_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
namespace core | ||||
{ | ||||
using namespace odb::common; | ||||
} | ||||
// | ||||
// | ||||
class database; | class database; | |||
class connection; | class connection; | |||
typedef details::shared_ptr<connection> connection_ptr; | typedef details::shared_ptr<connection> connection_ptr; | |||
class connection_factory; | class connection_factory; | |||
class statement; | class statement; | |||
class transaction; | class transaction; | |||
class tracer; | class tracer; | |||
class query; | ||||
namespace core | ||||
{ | ||||
using mysql::database; | ||||
using mysql::connection; | ||||
using mysql::connection_ptr; | ||||
using mysql::transaction; | ||||
using mysql::statement; | ||||
} | ||||
// Implementation details. | // Implementation details. | |||
// | // | |||
enum statement_kind | enum statement_kind | |||
{ | { | |||
statement_select, | statement_select, | |||
statement_insert, | statement_insert, | |||
statement_update | statement_update | |||
}; | }; | |||
skipping to change at line 54 | skipping to change at line 69 | |||
class polymorphic_derived_object_statements; | class polymorphic_derived_object_statements; | |||
template <typename T> | template <typename T> | |||
class no_id_object_statements; | class no_id_object_statements; | |||
template <typename T> | template <typename T> | |||
class view_statements; | class view_statements; | |||
template <typename T> | template <typename T> | |||
class container_statements; | class container_statements; | |||
template <typename T> | ||||
class smart_container_statements; | ||||
class query_base; | ||||
} | } | |||
namespace details | namespace details | |||
{ | { | |||
template <> | template <> | |||
struct counter_type<mysql::connection> | struct counter_type<mysql::connection> | |||
{ | { | |||
typedef shared_base counter; | typedef shared_base counter; | |||
}; | }; | |||
} | } | |||
End of changes. 4 change blocks. | ||||
2 lines changed or deleted | 22 lines changed or added | |||
mysql-types.hxx | mysql-types.hxx | |||
---|---|---|---|---|
// file : odb/mysql/mysql-types.hxx | // file : odb/mysql/mysql-types.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_MYSQL_TYPES_HXX | #ifndef ODB_MYSQL_MYSQL_TYPES_HXX | |||
#define ODB_MYSQL_MYSQL_TYPES_HXX | #define ODB_MYSQL_MYSQL_TYPES_HXX | |||
#include <odb/mysql/details/config.hxx> | #include <odb/mysql/details/config.hxx> | |||
typedef char my_bool; | typedef char my_bool; | |||
typedef struct st_mysql_bind MYSQL_BIND; | typedef struct st_mysql_bind MYSQL_BIND; | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
mysql.hxx | mysql.hxx | |||
---|---|---|---|---|
// file : odb/mysql/mysql.hxx | // file : odb/mysql/mysql.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_MYSQL_HXX | #ifndef ODB_MYSQL_MYSQL_HXX | |||
#define ODB_MYSQL_MYSQL_HXX | #define ODB_MYSQL_MYSQL_HXX | |||
#include <odb/mysql/details/config.hxx> | #include <odb/mysql/details/config.hxx> | |||
#include <odb/mysql/mysql-types.hxx> | #include <odb/mysql/mysql-types.hxx> | |||
#ifdef _WIN32 | #ifdef _WIN32 | |||
# include <winsock2.h> | # ifndef NOMINMAX // No min and max macros. | |||
# define NOMINMAX | ||||
# include <winsock2.h> | ||||
# undef NOMINMAX | ||||
# else | ||||
# include <winsock2.h> | ||||
# endif | ||||
#endif | #endif | |||
#ifdef LIBODB_MYSQL_INCLUDE_SHORT | #ifdef LIBODB_MYSQL_INCLUDE_SHORT | |||
# include <mysql.h> | # include <mysql.h> | |||
# include <errmsg.h> | # include <errmsg.h> | |||
# include <mysqld_error.h> | # include <mysqld_error.h> | |||
#else | #else | |||
# include <mysql/mysql.h> | # include <mysql/mysql.h> | |||
# include <mysql/errmsg.h> | # include <mysql/errmsg.h> | |||
# include <mysql/mysqld_error.h> | # include <mysql/mysqld_error.h> | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 8 lines changed or added | |||
no-id-object-result.hxx | no-id-object-result.hxx | |||
---|---|---|---|---|
// file : odb/mysql/no-id-object-result.hxx | // file : odb/mysql/no-id-object-result.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_NO_ID_OBJECT_RESULT_HXX | #ifndef ODB_MYSQL_NO_ID_OBJECT_RESULT_HXX | |||
#define ODB_MYSQL_NO_ID_OBJECT_RESULT_HXX | #define ODB_MYSQL_NO_ID_OBJECT_RESULT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/no-id-object-result.hxx> | #include <odb/no-id-object-result.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> // query | #include <odb/mysql/forward.hxx> // query_base | |||
#include <odb/mysql/statement.hxx> | #include <odb/mysql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class no_id_object_result_impl: public odb::no_id_object_result_impl<T> | class no_id_object_result_impl: public odb::no_id_object_result_impl<T> | |||
{ | { | |||
public: | public: | |||
typedef odb::no_id_object_result_impl<T> base_type; | typedef odb::no_id_object_result_impl<T> base_type; | |||
typedef typename base_type::object_type object_type; | typedef typename base_type::object_type object_type; | |||
typedef typename base_type::object_traits object_traits; | ||||
typedef typename base_type::pointer_type pointer_type; | typedef typename base_type::pointer_type pointer_type; | |||
typedef object_traits_impl<object_type, id_mysql> object_traits; | ||||
typedef typename base_type::pointer_traits pointer_traits; | typedef typename base_type::pointer_traits pointer_traits; | |||
typedef typename object_traits::statements_type statements_type; | typedef typename object_traits::statements_type statements_type; | |||
virtual | virtual | |||
~no_id_object_result_impl (); | ~no_id_object_result_impl (); | |||
no_id_object_result_impl (const query&, | no_id_object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement>, | details::shared_ptr<select_statement>, | |||
statements_type&); | statements_type&); | |||
virtual void | virtual void | |||
load (object_type&); | load (object_type&); | |||
virtual void | virtual void | |||
next (); | next (); | |||
virtual void | virtual void | |||
cache (); | cache (); | |||
virtual std::size_t | virtual std::size_t | |||
size (); | size (); | |||
virtual void | ||||
invalidate (); | ||||
using base_type::current; | using base_type::current; | |||
private: | private: | |||
void | void | |||
fetch (); | fetch (); | |||
private: | private: | |||
details::shared_ptr<select_statement> statement_; | details::shared_ptr<select_statement> statement_; | |||
statements_type& statements_; | statements_type& statements_; | |||
std::size_t count_; | std::size_t count_; | |||
End of changes. 6 change blocks. | ||||
5 lines changed or deleted | 8 lines changed or added | |||
no-id-object-result.txx | no-id-object-result.txx | |||
---|---|---|---|---|
// file : odb/mysql/no-id-object-result.txx | // file : odb/mysql/no-id-object-result.txx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> // result_not_cached | #include <odb/exceptions.hxx> // result_not_cached | |||
#include <odb/mysql/no-id-object-statements.hxx> | #include <odb/mysql/no-id-object-statements.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
no_id_object_result_impl<T>:: | no_id_object_result_impl<T>:: | |||
~no_id_object_result_impl () | ~no_id_object_result_impl () | |||
{ | { | |||
if (!this->end_) | if (!this->end_) | |||
statement_->free_result (); | statement_->free_result (); | |||
} | } | |||
template <typename T> | template <typename T> | |||
void no_id_object_result_impl<T>:: | ||||
invalidate () | ||||
{ | ||||
if (!this->end_) | ||||
{ | ||||
statement_->free_result (); | ||||
this->end_ = true; | ||||
} | ||||
statement_.reset (); | ||||
} | ||||
template <typename T> | ||||
no_id_object_result_impl<T>:: | no_id_object_result_impl<T>:: | |||
no_id_object_result_impl (const query&, | no_id_object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement> stateme nt, | details::shared_ptr<select_statement> stateme nt, | |||
statements_type& statements) | statements_type& statements) | |||
: base_type (statements.connection ().database ()), | : base_type (statements.connection ()), | |||
statement_ (statement), | statement_ (statement), | |||
statements_ (statements), | statements_ (statements), | |||
count_ (0) | count_ (0) | |||
{ | { | |||
} | } | |||
template <typename T> | template <typename T> | |||
void no_id_object_result_impl<T>:: | void no_id_object_result_impl<T>:: | |||
load (object_type& obj) | load (object_type& obj) | |||
{ | { | |||
if (count_ > statement_->fetched ()) | if (count_ > statement_->fetched ()) | |||
fetch (); | fetch (); | |||
odb::database& db (this->database ()); | object_traits::callback (this->db_, obj, callback_event::pre_load); | |||
object_traits::init (obj, statements_.image (), &this->db_); | ||||
object_traits::callback (db, obj, callback_event::pre_load); | object_traits::callback (this->db_, obj, callback_event::post_load); | |||
object_traits::init (obj, statements_.image (), &db); | ||||
object_traits::callback (db, obj, callback_event::post_load); | ||||
} | } | |||
template <typename T> | template <typename T> | |||
void no_id_object_result_impl<T>:: | void no_id_object_result_impl<T>:: | |||
next () | next () | |||
{ | { | |||
this->current (pointer_type ()); | this->current (pointer_type ()); | |||
if (this->end_) | if (this->end_) | |||
return; | return; | |||
End of changes. 5 change blocks. | ||||
8 lines changed or deleted | 19 lines changed or added | |||
no-id-object-statements.hxx | no-id-object-statements.hxx | |||
---|---|---|---|---|
// file : odb/mysql/no-id-object-statements.hxx | // file : odb/mysql/no-id-object-statements.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_NO_ID_OBJECT_STATEMENTS_HXX | #ifndef ODB_MYSQL_NO_ID_OBJECT_STATEMENTS_HXX | |||
#define ODB_MYSQL_NO_ID_OBJECT_STATEMENTS_HXX | #define ODB_MYSQL_NO_ID_OBJECT_STATEMENTS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
skipping to change at line 37 | skipping to change at line 37 | |||
{ | { | |||
// | // | |||
// Implementation for objects without object id. | // Implementation for objects without object id. | |||
// | // | |||
template <typename T> | template <typename T> | |||
class no_id_object_statements: public statements_base | class no_id_object_statements: public statements_base | |||
{ | { | |||
public: | public: | |||
typedef T object_type; | typedef T object_type; | |||
typedef odb::object_traits<object_type> object_traits; | typedef object_traits_impl<object_type, id_mysql> object_traits; | |||
typedef typename object_traits::pointer_type pointer_type; | typedef typename object_traits::pointer_type pointer_type; | |||
typedef typename object_traits::image_type image_type; | typedef typename object_traits::image_type image_type; | |||
typedef mysql::insert_statement insert_statement_type; | typedef mysql::insert_statement insert_statement_type; | |||
public: | public: | |||
no_id_object_statements (connection_type&); | no_id_object_statements (connection_type&); | |||
virtual | virtual | |||
~no_id_object_statements (); | ~no_id_object_statements (); | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
no-id-object-statements.txx | no-id-object-statements.txx | |||
---|---|---|---|---|
// file : odb/mysql/no-id-object-statements.txx | // file : odb/mysql/no-id-object-statements.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cstring> // std::memset | #include <cstring> // std::memset | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
no_id_object_statements<T>:: | no_id_object_statements<T>:: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
polymorphic-object-result.hxx | polymorphic-object-result.hxx | |||
---|---|---|---|---|
// file : odb/mysql/polymorphic-object-result.hxx | // file : odb/mysql/polymorphic-object-result.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_POLYMORPHIC_OBJECT_RESULT_HXX | #ifndef ODB_MYSQL_POLYMORPHIC_OBJECT_RESULT_HXX | |||
#define ODB_MYSQL_POLYMORPHIC_OBJECT_RESULT_HXX | #define ODB_MYSQL_POLYMORPHIC_OBJECT_RESULT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/polymorphic-object-result.hxx> | #include <odb/polymorphic-object-result.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> // query | #include <odb/mysql/forward.hxx> // query_base | |||
#include <odb/mysql/statement.hxx> | #include <odb/mysql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class polymorphic_object_result_impl: | class polymorphic_object_result_impl: | |||
public odb::polymorphic_object_result_impl<T> | public odb::polymorphic_object_result_impl<T> | |||
{ | { | |||
public: | public: | |||
typedef odb::polymorphic_object_result_impl<T> base_type; | typedef odb::polymorphic_object_result_impl<T> base_type; | |||
typedef typename base_type::object_type object_type; | ||||
typedef typename base_type::object_traits object_traits; | ||||
typedef typename base_type::id_type id_type; | typedef typename base_type::id_type id_type; | |||
typedef typename base_type::object_type object_type; | ||||
typedef typename base_type::pointer_type pointer_type; | typedef typename base_type::pointer_type pointer_type; | |||
typedef object_traits_impl<object_type, id_mysql> object_traits; | ||||
typedef typename base_type::pointer_traits pointer_traits; | typedef typename base_type::pointer_traits pointer_traits; | |||
typedef typename base_type::root_type root_type; | typedef typename base_type::root_type root_type; | |||
typedef typename base_type::root_traits root_traits; | ||||
typedef typename base_type::discriminator_type discriminator_type; | typedef typename base_type::discriminator_type discriminator_type; | |||
typedef object_traits_impl<root_type, id_mysql> root_traits; | ||||
typedef typename object_traits::statements_type statements_type; | typedef typename object_traits::statements_type statements_type; | |||
virtual | virtual | |||
~polymorphic_object_result_impl (); | ~polymorphic_object_result_impl (); | |||
polymorphic_object_result_impl (const query&, | polymorphic_object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement> , | details::shared_ptr<select_statement> , | |||
statements_type&); | statements_type&); | |||
virtual void | virtual void | |||
load (object_type*, bool fetch); | load (object_type*, bool fetch); | |||
virtual id_type | virtual id_type | |||
load_id (); | load_id (); | |||
virtual discriminator_type | virtual discriminator_type | |||
skipping to change at line 69 | skipping to change at line 70 | |||
virtual void | virtual void | |||
next (); | next (); | |||
virtual void | virtual void | |||
cache (); | cache (); | |||
virtual std::size_t | virtual std::size_t | |||
size (); | size (); | |||
virtual void | ||||
invalidate (); | ||||
using base_type::current; | using base_type::current; | |||
private: | private: | |||
void | void | |||
fetch (bool next = true); | fetch (bool next = true); | |||
private: | private: | |||
details::shared_ptr<select_statement> statement_; | details::shared_ptr<select_statement> statement_; | |||
statements_type& statements_; | statements_type& statements_; | |||
std::size_t count_; | std::size_t count_; | |||
End of changes. 9 change blocks. | ||||
7 lines changed or deleted | 11 lines changed or added | |||
polymorphic-object-result.txx | polymorphic-object-result.txx | |||
---|---|---|---|---|
// file : odb/mysql/polymorphic-object-result.txx | // file : odb/mysql/polymorphic-object-result.txx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cassert> | #include <cassert> | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> // result_not_cached | #include <odb/exceptions.hxx> // result_not_cached | |||
#include <odb/mysql/polymorphic-object-statements.hxx> | #include <odb/mysql/polymorphic-object-statements.hxx> | |||
namespace odb | namespace odb | |||
skipping to change at line 25 | skipping to change at line 25 | |||
{ | { | |||
template <typename T> | template <typename T> | |||
polymorphic_object_result_impl<T>:: | polymorphic_object_result_impl<T>:: | |||
~polymorphic_object_result_impl () | ~polymorphic_object_result_impl () | |||
{ | { | |||
if (!this->end_) | if (!this->end_) | |||
statement_->free_result (); | statement_->free_result (); | |||
} | } | |||
template <typename T> | template <typename T> | |||
void polymorphic_object_result_impl<T>:: | ||||
invalidate () | ||||
{ | ||||
if (!this->end_) | ||||
{ | ||||
statement_->free_result (); | ||||
this->end_ = true; | ||||
} | ||||
statement_.reset (); | ||||
} | ||||
template <typename T> | ||||
polymorphic_object_result_impl<T>:: | polymorphic_object_result_impl<T>:: | |||
polymorphic_object_result_impl (const query&, | polymorphic_object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement> s t, | details::shared_ptr<select_statement> s t, | |||
statements_type& sts) | statements_type& sts) | |||
: base_type (sts.connection ().database ()), | : base_type (sts.connection ()), | |||
statement_ (st), | statement_ (st), | |||
statements_ (sts), | statements_ (sts), | |||
count_ (0) | count_ (0) | |||
{ | { | |||
} | } | |||
template <typename T> | template <typename T> | |||
void polymorphic_object_result_impl<T>:: | void polymorphic_object_result_impl<T>:: | |||
load (object_type* pobj, bool f) | load (object_type* pobj, bool f) | |||
{ | { | |||
skipping to change at line 58 | skipping to change at line 71 | |||
} | } | |||
typename statements_type::root_statements_type& rsts ( | typename statements_type::root_statements_type& rsts ( | |||
statements_.root_statements ()); | statements_.root_statements ()); | |||
// This is a top-level call so the statements cannot be locked. | // This is a top-level call so the statements cannot be locked. | |||
// | // | |||
assert (!rsts.locked ()); | assert (!rsts.locked ()); | |||
typename statements_type::auto_lock l (rsts); | typename statements_type::auto_lock l (rsts); | |||
odb::database& db (this->database ()); | ||||
typename object_traits::image_type& i (statements_.image ()); | typename object_traits::image_type& i (statements_.image ()); | |||
typename root_traits::image_type& ri (rsts.image ()); | typename root_traits::image_type& ri (rsts.image ()); | |||
id_type id (root_traits::id (ri)); | id_type id (root_traits::id (ri)); | |||
// Determine this object's dynamic type. | // Determine this object's dynamic type. | |||
// | // | |||
typedef typename root_traits::info_type info_type; | typedef typename root_traits::info_type info_type; | |||
discriminator_type d (root_traits::discriminator (ri)); | discriminator_type d (root_traits::discriminator (ri)); | |||
discriminator_type disc (d); | discriminator_type disc (d); | |||
skipping to change at line 95 | skipping to change at line 107 | |||
{ | { | |||
// Need to create a new instance of the dynamic type. | // Need to create a new instance of the dynamic type. | |||
// | // | |||
root_pointer_type rp (pi.create ()); | root_pointer_type rp (pi.create ()); | |||
pointer_type p ( | pointer_type p ( | |||
root_pointer_traits::template static_pointer_cast<object_type> (r p)); | root_pointer_traits::template static_pointer_cast<object_type> (r p)); | |||
// Insert it as a root pointer (for non-unique pointers, rp should | // Insert it as a root pointer (for non-unique pointers, rp should | |||
// still be valid and for unique pointers this is a no-op). | // still be valid and for unique pointers this is a no-op). | |||
// | // | |||
ig.reset (object_traits::pointer_cache_traits::insert (db, id, rp)) | ig.reset ( | |||
; | object_traits::pointer_cache_traits::insert (this->db_, id, rp)); | |||
pobj = &pointer_traits::get_ref (p); | pobj = &pointer_traits::get_ref (p); | |||
current (p); | current (p); | |||
} | } | |||
else | else | |||
{ | { | |||
// We are loading into an existing instance. If the static and | // We are loading into an existing instance. If the static and | |||
// dynamic types differ, then make sure the instance is at least | // dynamic types differ, then make sure the instance is at least | |||
// of the dynamic type. | // of the dynamic type. | |||
// | // | |||
if (&pi != &object_traits::info) | if (&pi != &object_traits::info) | |||
{ | { | |||
const info_type& dpi (root_traits::map->find (typeid (*pobj))); | const info_type& dpi (root_traits::map->find (typeid (*pobj))); | |||
if (&dpi != &pi && dpi.derived (pi)) | if (&dpi != &pi && dpi.derived (pi)) | |||
throw object_not_persistent (); // @@ type_mismatch ? | throw object_not_persistent (); // @@ type_mismatch ? | |||
} | } | |||
} | } | |||
callback_event ce (callback_event::pre_load); | callback_event ce (callback_event::pre_load); | |||
pi.dispatch (info_type::call_callback, db, pobj, &ce); | pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); | |||
object_traits::init (*pobj, i, &db); | object_traits::init (*pobj, i, &this->db_); | |||
// Initialize the id image and binding and load the rest of the objec t | // Initialize the id image and binding and load the rest of the objec t | |||
// (containers, dynamic part, etc). | // (containers, dynamic part, etc). | |||
// | // | |||
typename object_traits::id_image_type& idi (statements_.id_image ()); | typename object_traits::id_image_type& idi (statements_.id_image ()); | |||
root_traits::init (idi, id); | root_traits::init (idi, id); | |||
binding& idb (statements_.id_image_binding ()); | binding& idb (statements_.id_image_binding ()); | |||
if (idi.version != statements_.id_image_version () || idb.version == 0) | if (idi.version != statements_.id_image_version () || idb.version == 0) | |||
{ | { | |||
skipping to change at line 142 | skipping to change at line 155 | |||
} | } | |||
object_traits::load_ (statements_, *pobj); | object_traits::load_ (statements_, *pobj); | |||
// Load the dynamic part of the object unless static and dynamic | // Load the dynamic part of the object unless static and dynamic | |||
// types are the same. | // types are the same. | |||
// | // | |||
if (&pi != &object_traits::info) | if (&pi != &object_traits::info) | |||
{ | { | |||
std::size_t d (object_traits::depth); | std::size_t d (object_traits::depth); | |||
pi.dispatch (info_type::call_load, db, pobj, &d); | pi.dispatch (info_type::call_load, this->db_, pobj, &d); | |||
}; | }; | |||
rsts.load_delayed (); | rsts.load_delayed (); | |||
l.unlock (); | l.unlock (); | |||
ce = callback_event::post_load; | ce = callback_event::post_load; | |||
pi.dispatch (info_type::call_callback, db, pobj, &ce); | pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); | |||
object_traits::pointer_cache_traits::load (ig.position ()); | ||||
ig.release (); | ig.release (); | |||
} | } | |||
template <typename T> | template <typename T> | |||
typename polymorphic_object_result_impl<T>::id_type | typename polymorphic_object_result_impl<T>::id_type | |||
polymorphic_object_result_impl<T>:: | polymorphic_object_result_impl<T>:: | |||
load_id () | load_id () | |||
{ | { | |||
if (count_ > statement_->fetched ()) | if (count_ > statement_->fetched ()) | |||
fetch (); | fetch (); | |||
skipping to change at line 221 | skipping to change at line 235 | |||
if (this->end_) | if (this->end_) | |||
statement_->free_result (); | statement_->free_result (); | |||
} | } | |||
template <typename T, typename R> | template <typename T, typename R> | |||
struct polymorphic_image_rebind | struct polymorphic_image_rebind | |||
{ | { | |||
// Derived type version. | // Derived type version. | |||
// | // | |||
typedef object_traits<T> traits; | typedef object_traits_impl<T, id_mysql> traits; | |||
static bool | static bool | |||
rebind (typename traits::statements_type& sts) | rebind (typename traits::statements_type& sts) | |||
{ | { | |||
typename traits::image_type& im (sts.image ()); | typename traits::image_type& im (sts.image ()); | |||
if (traits::check_version (sts.select_image_versions (), im)) | if (traits::check_version (sts.select_image_versions (), im)) | |||
{ | { | |||
binding& b (sts.select_image_binding (traits::depth)); | binding& b (sts.select_image_binding (traits::depth)); | |||
traits::bind (b.bind, 0, 0, im, statement_select); | traits::bind (b.bind, 0, 0, im, statement_select); | |||
skipping to change at line 246 | skipping to change at line 260 | |||
return false; | return false; | |||
} | } | |||
}; | }; | |||
template <typename R> | template <typename R> | |||
struct polymorphic_image_rebind<R, R> | struct polymorphic_image_rebind<R, R> | |||
{ | { | |||
// Root type version. | // Root type version. | |||
// | // | |||
typedef object_traits<R> traits; | typedef object_traits_impl<R, id_mysql> traits; | |||
static bool | static bool | |||
rebind (typename traits::statements_type& sts) | rebind (typename traits::statements_type& sts) | |||
{ | { | |||
typename traits::image_type& im (sts.image ()); | typename traits::image_type& im (sts.image ()); | |||
if (im.version != sts.select_image_version ()) | if (im.version != sts.select_image_version ()) | |||
{ | { | |||
binding& b (sts.select_image_binding ()); | binding& b (sts.select_image_binding ()); | |||
traits::bind (b.bind, im, statement_select); | traits::bind (b.bind, im, statement_select); | |||
End of changes. 12 change blocks. | ||||
12 lines changed or deleted | 25 lines changed or added | |||
polymorphic-object-statements.hxx | polymorphic-object-statements.hxx | |||
---|---|---|---|---|
// file : odb/mysql/polymorphic-object-statements.hxx | // file : odb/mysql/polymorphic-object-statements.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | #ifndef ODB_MYSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | |||
#define ODB_MYSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | #define ODB_MYSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
skipping to change at line 156 | skipping to change at line 156 | |||
MYSQL_BIND discriminator_id_image_bind_[id_column_count]; | MYSQL_BIND discriminator_id_image_bind_[id_column_count]; | |||
details::shared_ptr<select_statement_type> find_discriminator_; | details::shared_ptr<select_statement_type> find_discriminator_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
class polymorphic_derived_object_statements: public statements_base | class polymorphic_derived_object_statements: public statements_base | |||
{ | { | |||
public: | public: | |||
typedef T object_type; | typedef T object_type; | |||
typedef odb::object_traits<object_type> object_traits; | typedef object_traits_impl<object_type, id_mysql> object_traits; | |||
typedef typename object_traits::id_type id_type; | typedef typename object_traits::id_type id_type; | |||
typedef typename object_traits::pointer_type pointer_type; | typedef typename object_traits::pointer_type pointer_type; | |||
typedef typename object_traits::id_image_type id_image_type; | typedef typename object_traits::id_image_type id_image_type; | |||
typedef typename object_traits::image_type image_type; | typedef typename object_traits::image_type image_type; | |||
typedef typename object_traits::root_type root_type; | typedef typename object_traits::root_type root_type; | |||
typedef | typedef | |||
polymorphic_root_object_statements<root_type> | polymorphic_root_object_statements<root_type> | |||
root_statements_type; | root_statements_type; | |||
skipping to change at line 351 | skipping to change at line 351 | |||
false)); | false)); | |||
return *erase_; | return *erase_; | |||
} | } | |||
// Container statement cache. | // Container statement cache. | |||
// | // | |||
container_statement_cache_type& | container_statement_cache_type& | |||
container_statment_cache () | container_statment_cache () | |||
{ | { | |||
return container_statement_cache_.get (conn_); | return container_statement_cache_.get (conn_, id_image_binding ()); | |||
} | } | |||
public: | public: | |||
// select = total - id + base::select | // select = total - id + base::select | |||
// insert = total - inverse | // insert = total - inverse | |||
// update = total - inverse - id - readonly | // update = total - inverse - id - readonly | |||
// | // | |||
static const std::size_t id_column_count = | static const std::size_t id_column_count = | |||
object_traits::id_column_count; | object_traits::id_column_count; | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added | |||
polymorphic-object-statements.txx | polymorphic-object-statements.txx | |||
---|---|---|---|---|
// file : odb/mysql/polymorphic-object-statements.txx | // file : odb/mysql/polymorphic-object-statements.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cstring> // std::memset | #include <cstring> // std::memset | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> | #include <odb/exceptions.hxx> | |||
#include <odb/mysql/connection.hxx> | #include <odb/mysql/connection.hxx> | |||
#include <odb/mysql/transaction.hxx> | #include <odb/mysql/transaction.hxx> | |||
#include <odb/mysql/statement-cache.hxx> | #include <odb/mysql/statement-cache.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
query.hxx | query.hxx | |||
---|---|---|---|---|
// file : odb/mysql/query.hxx | // file : odb/mysql/query.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_QUERY_HXX | #ifndef ODB_MYSQL_QUERY_HXX | |||
#define ODB_MYSQL_QUERY_HXX | #define ODB_MYSQL_QUERY_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <string> | #include <string> | |||
#include <vector> | #include <vector> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> // odb::query_column | ||||
#include <odb/query.hxx> | #include <odb/query.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | #include <odb/mysql/forward.hxx> | |||
#include <odb/mysql/traits.hxx> | #include <odb/mysql/traits.hxx> | |||
#include <odb/mysql/enum.hxx> | #include <odb/mysql/enum.hxx> | |||
#include <odb/mysql/binding.hxx> | #include <odb/mysql/binding.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/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
#include <odb/mysql/details/conversion.hxx> | #include <odb/mysql/details/conversion.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class val_bind | struct val_bind | |||
{ | { | |||
public: | typedef const T& type; | |||
explicit | ||||
val_bind (type v): val (v) {} | ||||
type val; | ||||
}; | ||||
template <typename T, std::size_t N> | ||||
struct val_bind<T[N]> | ||||
{ | ||||
typedef const T* type; | ||||
explicit | explicit | |||
val_bind (const T& v): val (v) {} | val_bind (type v): val (v) {} | |||
const T& val; | type val; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
class ref_bind | struct ref_bind | |||
{ | { | |||
public: | typedef const T& type; | |||
explicit | explicit | |||
ref_bind (const T& r): ref (r) {} | ref_bind (type r): ref (r) {} | |||
const T& ref; | const void* | |||
ptr () const {return &ref;} | ||||
type ref; | ||||
}; | ||||
template <typename T, std::size_t N> | ||||
struct ref_bind<T[N]> | ||||
{ | ||||
typedef const T* type; | ||||
explicit | ||||
ref_bind (type r): ref (r) {} | ||||
// Allow implicit conversion from decayed ref_bind's. | ||||
// | ||||
ref_bind (ref_bind<T*> r): ref (r.ref) {} | ||||
ref_bind (ref_bind<const T*> r): ref (r.ref) {} | ||||
const void* | ||||
ptr () const {return ref;} | ||||
type ref; | ||||
}; | ||||
template <typename T, database_type_id ID> | ||||
struct val_bind_typed: val_bind<T> | ||||
{ | ||||
explicit | ||||
val_bind_typed (typename val_bind<T>::type v): val_bind<T> (v) {} | ||||
}; | ||||
template <typename T, database_type_id ID> | ||||
struct ref_bind_typed: ref_bind<T> | ||||
{ | ||||
explicit | ||||
ref_bind_typed (typename ref_bind<T>::type r): ref_bind<T> (r) {} | ||||
}; | }; | |||
struct LIBODB_MYSQL_EXPORT query_param: details::shared_base | struct LIBODB_MYSQL_EXPORT query_param: details::shared_base | |||
{ | { | |||
virtual | virtual | |||
~query_param (); | ~query_param (); | |||
bool | bool | |||
reference () const | reference () const | |||
{ | { | |||
return value_ != 0; | return value_ != 0; | |||
} | } | |||
virtual bool | virtual bool | |||
init () = 0; | init () = 0; | |||
virtual void | virtual void | |||
bind (MYSQL_BIND*) = 0; | bind (MYSQL_BIND*) = 0; | |||
protected: | protected: | |||
query_param (const void* value) | query_param (const void* value) : value_ (value) {} | |||
: value_ (value) | ||||
{ | ||||
} | ||||
protected: | protected: | |||
const void* value_; | const void* value_; | |||
}; | }; | |||
// | // | |||
// | // | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
struct query_column; | struct query_column; | |||
class LIBODB_MYSQL_EXPORT query | class LIBODB_MYSQL_EXPORT query_base | |||
{ | { | |||
public: | public: | |||
struct clause_part | struct clause_part | |||
{ | { | |||
enum kind_type | enum kind_type | |||
{ | { | |||
column, | kind_column, | |||
param, | kind_param, | |||
native, | kind_native, | |||
boolean | kind_bool | |||
}; | }; | |||
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 (kind_bool), bool_part (p) {} | |||
kind_type kind; | kind_type kind; | |||
std::string part; // If kind is param, then part is conversion expr . | std::string part; // If kind is param, then part is conversion expr . | |||
bool bool_part; | bool bool_part; | |||
}; | }; | |||
query () | query_base () | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
} | } | |||
// True or false literal. | // True or false literal. | |||
// | // | |||
explicit | explicit | |||
query (bool v) | query_base (bool v) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
clause_.push_back (clause_part (v)); | append (v); | |||
} | } | |||
explicit | explicit | |||
query (const char* native) | query_base (const char* native) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
clause_.push_back (clause_part (clause_part::native, native)); | clause_.push_back (clause_part (clause_part::kind_native, native)); | |||
} | } | |||
explicit | explicit | |||
query (const std::string& native) | query_base (const std::string& native) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
clause_.push_back (clause_part (clause_part::native, native)); | clause_.push_back (clause_part (clause_part::kind_native, native)); | |||
} | } | |||
query (const char* table, const char* column) | query_base (const char* table, const char* column) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
append (table, column); | append (table, column); | |||
} | } | |||
template <typename T> | template <typename T> | |||
explicit | explicit | |||
query (val_bind<T> v) | query_base (val_bind<T> v) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
append<T, type_traits<T>::db_type_id> ( | *this += v; | |||
v, details::conversion<T>::to ()); | } | |||
template <typename T, database_type_id ID> | ||||
explicit | ||||
query_base (val_bind_typed<T, ID> v) | ||||
: binding_ (0, 0) | ||||
{ | ||||
*this += v; | ||||
} | } | |||
template <typename T> | template <typename T> | |||
explicit | explicit | |||
query (ref_bind<T> r) | query_base (ref_bind<T> r) | |||
: binding_ (0, 0) | : binding_ (0, 0) | |||
{ | { | |||
append<T, type_traits<T>::db_type_id> ( | *this += r; | |||
r, details::conversion<T>::to ()); | } | |||
template <typename T, database_type_id ID> | ||||
explicit | ||||
query_base (ref_bind_typed<T, ID> r) | ||||
: binding_ (0, 0) | ||||
{ | ||||
*this += r; | ||||
} | } | |||
template <database_type_id ID> | template <database_type_id ID> | |||
query (const query_column<bool, ID>&); | query_base (const query_column<bool, ID>&); | |||
// Translate common query representation to MySQL native. Defined | ||||
// in query-dynamic.cxx | ||||
// | ||||
query_base (const odb::query_base&); | ||||
query (const query&); | // Copy c-tor and assignment. | |||
// | ||||
query_base (const query_base&); | ||||
query& | query_base& | |||
operator= (const query&); | operator= (const query_base&); | |||
public: | public: | |||
std::string | std::string | |||
clause () const; | clause () const; | |||
const char* | const char* | |||
clause_prefix () const; | clause_prefix () const; | |||
// Initialize the by-reference parameters from bound variables. | ||||
// | ||||
void | ||||
init_parameters () const; | ||||
binding& | binding& | |||
parameters_binding () const; | parameters_binding () const; | |||
public: | public: | |||
bool | bool | |||
empty () const | empty () const | |||
{ | { | |||
return clause_.empty (); | return clause_.empty (); | |||
} | } | |||
static const query true_expr; | static const query_base true_expr; | |||
bool | bool | |||
const_true () const | const_true () const | |||
{ | { | |||
return clause_.size () == 1 && | return clause_.size () == 1 && | |||
clause_.front ().kind == clause_part::boolean && | clause_.front ().kind == clause_part::kind_bool && | |||
clause_.front ().bool_part; | clause_.front ().bool_part; | |||
} | } | |||
void | void | |||
optimize (); | optimize (); | |||
public: | 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 <database_type_id ID, typename T> | ||||
static val_bind_typed<T, ID> | ||||
_val (const T& x) | ||||
{ | ||||
return val_bind_typed<T, ID> (x); | ||||
} | ||||
template <typename T> | template <typename T> | |||
static ref_bind<T> | static ref_bind<T> | |||
_ref (const T& x) | _ref (const T& x) | |||
{ | { | |||
return ref_bind<T> (x); | return ref_bind<T> (x); | |||
} | } | |||
template <database_type_id ID, typename T> | ||||
static ref_bind_typed<T, ID> | ||||
_ref (const T& x) | ||||
{ | ||||
return ref_bind_typed<T, ID> (x); | ||||
} | ||||
// Some compilers (notably VC++), when deducing const T& from const | ||||
// array do not strip const from the array type. As a result, in the | ||||
// above signatures we get, for example, T = const char[4] instead | ||||
// of T = char[4], which is what we want. So to "fix" such compilers, | ||||
// we will have to provide the following specializations of the above | ||||
// functions. | ||||
// | ||||
template <typename T, std::size_t N> | ||||
static val_bind<T[N]> | ||||
_val (const T (&x) [N]) | ||||
{ | ||||
return val_bind<T[N]> (x); | ||||
} | ||||
template <database_type_id ID, typename T, std::size_t N> | ||||
static val_bind_typed<T[N], ID> | ||||
_val (const T (&x) [N]) | ||||
{ | ||||
return val_bind_typed<T[N], ID> (x); | ||||
} | ||||
template <typename T, std::size_t N> | ||||
static ref_bind<T[N]> | ||||
_ref (const T (&x) [N]) | ||||
{ | ||||
return ref_bind<T[N]> (x); | ||||
} | ||||
template <database_type_id ID, typename T, std::size_t N> | ||||
static ref_bind_typed<T[N], ID> | ||||
_ref (const T (&x) [N]) | ||||
{ | ||||
return ref_bind_typed<T[N], ID> (x); | ||||
} | ||||
public: | public: | |||
query& | query_base& | |||
operator+= (const query&); | operator+= (const query_base&); | |||
query& | query_base& | |||
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_base& | |||
operator+= (val_bind<T> v) | operator+= (val_bind<T> v) | |||
{ | { | |||
append<T, type_traits<T>::db_type_id> ( | append<T, type_traits<T>::db_type_id> ( | |||
v, details::conversion<T>::to ()); | v, details::conversion<T>::to ()); | |||
return *this; | return *this; | |||
} | } | |||
template <typename T, database_type_id ID> | ||||
query_base& | ||||
operator+= (val_bind_typed<T, ID> v) | ||||
{ | ||||
// We are not using default type_traits so no default conversion | ||||
// either. | ||||
// | ||||
append<T, ID> (v, 0); | ||||
return *this; | ||||
} | ||||
template <typename T> | template <typename T> | |||
query& | query_base& | |||
operator+= (ref_bind<T> r) | operator+= (ref_bind<T> r) | |||
{ | { | |||
append<T, type_traits<T>::db_type_id> ( | append<T, type_traits<T>::db_type_id> ( | |||
r, details::conversion<T>::to ()); | r, details::conversion<T>::to ()); | |||
return *this; | return *this; | |||
} | } | |||
template <typename T, database_type_id ID> | ||||
query_base& | ||||
operator+= (ref_bind_typed<T, ID> r) | ||||
{ | ||||
// We are not using default type_traits so no default conversion | ||||
// either. | ||||
// | ||||
append<T, ID> (r, 0); | ||||
return *this; | ||||
} | ||||
// Implementation details. | ||||
// | ||||
public: | public: | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
void | void | |||
append (val_bind<T>, const char* conv); | 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>, const char* conv); | append (ref_bind<T>, const char* conv); | |||
void | void | |||
append (details::shared_ptr<query_param>, const char* conv); | ||||
void | ||||
append (bool v) | ||||
{ | ||||
clause_.push_back (clause_part (v)); | ||||
} | ||||
void | ||||
append (const std::string& native); | append (const std::string& native); | |||
void | void | |||
append (const char* table, const char* column); | append (const char* native) // Clashes with append(bool). | |||
{ | ||||
append (std::string (native)); | ||||
} | ||||
private: | ||||
void | void | |||
add (details::shared_ptr<query_param>, const char* conv); | append (const char* table, const char* column); | |||
private: | private: | |||
typedef std::vector<clause_part> clause_type; | 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; | |||
clause_type clause_; | clause_type clause_; | |||
parameters_type parameters_; | parameters_type parameters_; | |||
mutable std::vector<MYSQL_BIND> bind_; | mutable std::vector<MYSQL_BIND> bind_; | |||
mutable binding binding_; | mutable binding binding_; | |||
}; | }; | |||
inline query | inline query_base | |||
operator+ (const query& x, const query& y) | operator+ (const query_base& x, const query_base& y) | |||
{ | { | |||
query r (x); | query_base r (x); | |||
r += y; | r += y; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (const query& q, val_bind<T> b) | operator+ (const query_base& q, val_bind<T> b) | |||
{ | { | |||
query r (q); | query_base r (q); | |||
r += b; | r += b; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (const query& q, ref_bind<T> b) | operator+ (val_bind<T> b, const query_base& q) | |||
{ | { | |||
query r (q); | query_base r; | |||
r += b; | r += b; | |||
r += q; | ||||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T, database_type_id ID> | |||
inline query | inline query_base | |||
operator+ (val_bind<T> b, const query& q) | operator+ (const query_base& q, val_bind_typed<T, ID> b) | |||
{ | ||||
query_base r (q); | ||||
r += b; | ||||
return r; | ||||
} | ||||
template <typename T, database_type_id ID> | ||||
inline query_base | ||||
operator+ (val_bind_typed<T, ID> b, const query_base& q) | ||||
{ | { | |||
query r; | query_base r; | |||
r += b; | r += b; | |||
r += q; | r += q; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (ref_bind<T> b, const query& q) | operator+ (const query_base& q, ref_bind<T> b) | |||
{ | ||||
query_base r (q); | ||||
r += b; | ||||
return r; | ||||
} | ||||
template <typename T> | ||||
inline query_base | ||||
operator+ (ref_bind<T> b, const query_base& q) | ||||
{ | ||||
query_base r; | ||||
r += b; | ||||
r += q; | ||||
return r; | ||||
} | ||||
template <typename T, database_type_id ID> | ||||
inline query_base | ||||
operator+ (const query_base& q, ref_bind_typed<T, ID> b) | ||||
{ | ||||
query_base r (q); | ||||
r += b; | ||||
return r; | ||||
} | ||||
template <typename T, database_type_id ID> | ||||
inline query_base | ||||
operator+ (ref_bind_typed<T, ID> b, const query_base& q) | ||||
{ | { | |||
query r; | query_base r; | |||
r += b; | r += b; | |||
r += q; | r += q; | |||
return r; | return r; | |||
} | } | |||
inline query | inline query_base | |||
operator+ (const query& q, const std::string& s) | operator+ (const query_base& q, const std::string& s) | |||
{ | { | |||
query r (q); | query_base r (q); | |||
r += s; | r += s; | |||
return r; | return r; | |||
} | } | |||
inline query | inline query_base | |||
operator+ (const std::string& s, const query& q) | operator+ (const std::string& s, const query_base& q) | |||
{ | { | |||
query r (s); | query_base r (s); | |||
r += q; | r += q; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (const std::string& s, val_bind<T> b) | operator+ (const std::string& s, val_bind<T> b) | |||
{ | { | |||
query r (s); | query_base r (s); | |||
r += b; | r += b; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (const std::string& s, ref_bind<T> b) | operator+ (val_bind<T> b, const std::string& s) | |||
{ | { | |||
query r (s); | query_base r; | |||
r += b; | r += b; | |||
r += s; | ||||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T, database_type_id ID> | |||
inline query | inline query_base | |||
operator+ (val_bind<T> b, const std::string& s) | operator+ (const std::string& s, val_bind_typed<T, ID> b) | |||
{ | { | |||
query r; | query_base r (s); | |||
r += b; | ||||
return r; | ||||
} | ||||
template <typename T, database_type_id ID> | ||||
inline query_base | ||||
operator+ (val_bind_typed<T, ID> b, const std::string& s) | ||||
{ | ||||
query_base r; | ||||
r += b; | r += b; | |||
r += s; | r += s; | |||
return r; | return r; | |||
} | } | |||
template <typename T> | template <typename T> | |||
inline query | inline query_base | |||
operator+ (const std::string& s, ref_bind<T> b) | ||||
{ | ||||
query_base r (s); | ||||
r += b; | ||||
return r; | ||||
} | ||||
template <typename T> | ||||
inline query_base | ||||
operator+ (ref_bind<T> b, const std::string& s) | operator+ (ref_bind<T> b, const std::string& s) | |||
{ | { | |||
query r; | query_base r; | |||
r += b; | r += b; | |||
r += s; | r += s; | |||
return r; | return r; | |||
} | } | |||
LIBODB_MYSQL_EXPORT query | template <typename T, database_type_id ID> | |||
operator&& (const query& x, const query& y); | inline query_base | |||
operator+ (const std::string& s, ref_bind_typed<T, ID> b) | ||||
LIBODB_MYSQL_EXPORT query | { | |||
operator|| (const query& x, const query& y); | query_base r (s); | |||
r += b; | ||||
LIBODB_MYSQL_EXPORT query | return r; | |||
operator! (const query& x); | } | |||
// query_column | ||||
// | ||||
template <typename T, typename T2> | template <typename T, database_type_id ID> | |||
class copy_bind: public val_bind<T> | inline query_base | |||
operator+ (ref_bind_typed<T, ID> b, const std::string& s) | ||||
{ | { | |||
public: | query_base r; | |||
explicit | r += b; | |||
copy_bind (const T2& v): val_bind<T> (val), val (v) {} | r += s; | |||
return r; | ||||
} | ||||
const T val; | LIBODB_MYSQL_EXPORT query_base | |||
}; | operator&& (const query_base& x, const query_base& y); | |||
template <typename T> | LIBODB_MYSQL_EXPORT query_base | |||
const T& | operator|| (const query_base& x, const query_base& y); | |||
type_instance (); | ||||
template <typename T, database_type_id ID> | LIBODB_MYSQL_EXPORT query_base | |||
struct query_column | operator! (const query_base& x); | |||
// query_column | ||||
// | ||||
struct LIBODB_MYSQL_EXPORT query_column_base | ||||
{ | { | |||
// Note that we keep shallow copies of the table, column, and convers ion | // Note that we keep shallow copies of the table, column, and convers ion | |||
// expression. The latter can be NULL. | // expression. The latter can be NULL. | |||
// | // | |||
query_column (const char* table, const char* column, const char* conv | query_column_base (const char* table, | |||
) | const char* column, | |||
const char* conv) | ||||
: table_ (table), column_ (column), conversion_ (conv) | : table_ (table), column_ (column), conversion_ (conv) | |||
{ | { | |||
} | } | |||
const char* | const char* | |||
table () const | table () const | |||
{ | { | |||
return table_; | return table_; | |||
} | } | |||
skipping to change at line 427 | skipping to change at line 646 | |||
} | } | |||
// Can be NULL. | // Can be NULL. | |||
// | // | |||
const char* | const char* | |||
conversion () const | conversion () const | |||
{ | { | |||
return conversion_; | return conversion_; | |||
} | } | |||
protected: | ||||
const char* table_; | ||||
const char* column_; | ||||
const char* conversion_; | ||||
}; | ||||
template <typename T, database_type_id ID> | ||||
struct query_column: query_column_base | ||||
{ | ||||
typedef typename decay_traits<T>::type decayed_type; | ||||
// 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, const char* conv | ||||
) | ||||
: query_column_base (table, column, conv) {} | ||||
// Implementation is in query-dynamic.ixx. | ||||
// | ||||
query_column (odb::query_column<T>&, | ||||
const char* table, const char* column, const char* conv | ||||
); | ||||
// is_null, is_not_null | // is_null, is_not_null | |||
// | // | |||
public: | public: | |||
query | query_base | |||
is_null () const | is_null () const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IS NULL"; | q += "IS NULL"; | |||
return q; | return q; | |||
} | } | |||
query | query_base | |||
is_not_null () const | is_not_null () const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IS NOT NULL"; | q += "IS NOT NULL"; | |||
return q; | return q; | |||
} | } | |||
// in | // in | |||
// | // | |||
public: | public: | |||
query | query_base | |||
in (const T&, const T&) const; | in (decayed_type, decayed_type) const; | |||
query | query_base | |||
in (const T&, const T&, const T&) const; | in (decayed_type, decayed_type, decayed_type) const; | |||
query | query_base | |||
in (const T&, const T&, const T&, const T&) const; | in (decayed_type, decayed_type, decayed_type, decayed_type) const; | |||
query | query_base | |||
in (const T&, const T&, const T&, const T&, const T&) const; | in (decayed_type, decayed_type, decayed_type, decayed_type, | |||
decayed_type) const; | ||||
template <typename I> | template <typename I> | |||
query | query_base | |||
in_range (I begin, I end) const; | in_range (I begin, I end) const; | |||
// = | // = | |||
// | // | |||
public: | public: | |||
query | query_base | |||
equal (const T& v) const | equal (decayed_type v) const | |||
{ | { | |||
return equal (val_bind<T> (v)); | return equal (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
equal (val_bind<T> v) const | equal (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "="; | q += "="; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
equal (val_bind<T2> v) const | equal (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return equal (val_bind<T> (decayed_type (v.val))); | |||
return equal (c); | ||||
} | } | |||
query | query_base | |||
equal (ref_bind<T> r) const | equal (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "="; | q += "="; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator== (const query_column& c, const T& v) | operator== (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator== (const T& v, const query_column& c) | operator== (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator== (const query_column& c, val_bind<T> v) | operator== (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator== (val_bind<T> v, const query_column& c) | operator== (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator== (const query_column& c, val_bind<T2> v) | operator== (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator== (val_bind<T2> v, const query_column& c) | operator== (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.equal (v); | return c.equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator== (const query_column& c, ref_bind<T> r) | operator== (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.equal (r); | return c.equal (r); | |||
} | } | |||
friend query | friend query_base | |||
operator== (ref_bind<T> r, const query_column& c) | operator== (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.equal (r); | return c.equal (r); | |||
} | } | |||
// != | // != | |||
// | // | |||
public: | public: | |||
query | query_base | |||
unequal (const T& v) const | unequal (decayed_type v) const | |||
{ | { | |||
return unequal (val_bind<T> (v)); | return unequal (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
unequal (val_bind<T> v) const | unequal (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "!="; | q += "!="; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
unequal (val_bind<T2> v) const | unequal (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return unequal (val_bind<T> (decayed_type (v.val))); | |||
return unequal (c); | ||||
} | } | |||
query | query_base | |||
unequal (ref_bind<T> r) const | unequal (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "!="; | q += "!="; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator!= (const query_column& c, const T& v) | operator!= (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator!= (const T& v, const query_column& c) | operator!= (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator!= (const query_column& c, val_bind<T> v) | operator!= (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator!= (val_bind<T> v, const query_column& c) | operator!= (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator!= (const query_column& c, val_bind<T2> v) | operator!= (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator!= (val_bind<T2> v, const query_column& c) | operator!= (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.unequal (v); | return c.unequal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator!= (const query_column& c, ref_bind<T> r) | operator!= (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.unequal (r); | return c.unequal (r); | |||
} | } | |||
friend query | friend query_base | |||
operator!= (ref_bind<T> r, const query_column& c) | operator!= (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.unequal (r); | return c.unequal (r); | |||
} | } | |||
// < | // < | |||
// | // | |||
public: | public: | |||
query | query_base | |||
less (const T& v) const | less (decayed_type v) const | |||
{ | { | |||
return less (val_bind<T> (v)); | return less (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
less (val_bind<T> v) const | less (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<"; | q += "<"; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
less (val_bind<T2> v) const | less (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return less (val_bind<T> (decayed_type (v.val))); | |||
return less (c); | ||||
} | } | |||
query | query_base | |||
less (ref_bind<T> r) const | less (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<"; | q += "<"; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator< (const query_column& c, const T& v) | operator< (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
friend query | friend query_base | |||
operator< (const T& v, const query_column& c) | operator< (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
friend query | friend query_base | |||
operator< (const query_column& c, val_bind<T> v) | operator< (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
friend query | friend query_base | |||
operator< (val_bind<T> v, const query_column& c) | operator< (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator< (const query_column& c, val_bind<T2> v) | operator< (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator< (val_bind<T2> v, const query_column& c) | operator< (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
friend query | friend query_base | |||
operator< (const query_column& c, ref_bind<T> r) | operator< (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.less (r); | return c.less (r); | |||
} | } | |||
friend query | friend query_base | |||
operator< (ref_bind<T> r, const query_column& c) | operator< (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.greater (r); | return c.greater (r); | |||
} | } | |||
// > | // > | |||
// | // | |||
public: | public: | |||
query | query_base | |||
greater (const T& v) const | greater (decayed_type v) const | |||
{ | { | |||
return greater (val_bind<T> (v)); | return greater (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
greater (val_bind<T> v) const | greater (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">"; | q += ">"; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
greater (val_bind<T2> v) const | greater (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return greater (val_bind<T> (decayed_type (v.val))); | |||
return greater (c); | ||||
} | } | |||
query | query_base | |||
greater (ref_bind<T> r) const | greater (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">"; | q += ">"; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator> (const query_column& c, const T& v) | operator> (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
friend query | friend query_base | |||
operator> (const T& v, const query_column& c) | operator> (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
friend query | friend query_base | |||
operator> (const query_column& c, val_bind<T> v) | operator> (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
friend query | friend query_base | |||
operator> (val_bind<T> v, const query_column& c) | operator> (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator> (const query_column& c, val_bind<T2> v) | operator> (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.greater (v); | return c.greater (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator> (val_bind<T2> v, const query_column& c) | operator> (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.less (v); | return c.less (v); | |||
} | } | |||
friend query | friend query_base | |||
operator> (const query_column& c, ref_bind<T> r) | operator> (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.greater (r); | return c.greater (r); | |||
} | } | |||
friend query | friend query_base | |||
operator> (ref_bind<T> r, const query_column& c) | operator> (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.less (r); | return c.less (r); | |||
} | } | |||
// <= | // <= | |||
// | // | |||
public: | public: | |||
query | query_base | |||
less_equal (const T& v) const | less_equal (decayed_type v) const | |||
{ | { | |||
return less_equal (val_bind<T> (v)); | return less_equal (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
less_equal (val_bind<T> v) const | less_equal (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<="; | q += "<="; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
less_equal (val_bind<T2> v) const | less_equal (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return less_equal (val_bind<T> (decayed_type (v.val))); | |||
return less_equal (c); | ||||
} | } | |||
query | query_base | |||
less_equal (ref_bind<T> r) const | less_equal (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<="; | q += "<="; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator<= (const query_column& c, const T& v) | operator<= (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator<= (const T& v, const query_column& c) | operator<= (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator<= (const query_column& c, val_bind<T> v) | operator<= (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator<= (val_bind<T> v, const query_column& c) | operator<= (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator<= (const query_column& c, val_bind<T2> v) | operator<= (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator<= (val_bind<T2> v, const query_column& c) | operator<= (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator<= (const query_column& c, ref_bind<T> r) | operator<= (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.less_equal (r); | return c.less_equal (r); | |||
} | } | |||
friend query | friend query_base | |||
operator<= (ref_bind<T> r, const query_column& c) | operator<= (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.greater_equal (r); | return c.greater_equal (r); | |||
} | } | |||
// >= | // >= | |||
// | // | |||
public: | public: | |||
query | query_base | |||
greater_equal (const T& v) const | greater_equal (decayed_type v) const | |||
{ | { | |||
return greater_equal (val_bind<T> (v)); | return greater_equal (val_bind<T> (v)); | |||
} | } | |||
query | query_base | |||
greater_equal (val_bind<T> v) const | greater_equal (val_bind<T> v) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">="; | q += ">="; | |||
q.append<T, ID> (v, conversion_); | q.append<T, ID> (v, conversion_); | |||
return q; | return q; | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
query | query_base | |||
greater_equal (val_bind<T2> v) const | greater_equal (val_bind<T2> v) const | |||
{ | { | |||
copy_bind<T, T2> c (v.val); | return greater_equal (val_bind<T> (decayed_type (v.val))); | |||
return greater_equal (c); | ||||
} | } | |||
query | query_base | |||
greater_equal (ref_bind<T> r) const | greater_equal (ref_bind<T> r) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">="; | q += ">="; | |||
q.append<T, ID> (r, conversion_); | q.append<T, ID> (r, conversion_); | |||
return q; | return q; | |||
} | } | |||
friend query | friend query_base | |||
operator>= (const query_column& c, const T& v) | operator>= (const query_column& c, decayed_type v) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator>= (const T& v, const query_column& c) | operator>= (decayed_type v, const query_column& c) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator>= (const query_column& c, val_bind<T> v) | operator>= (const query_column& c, val_bind<T> v) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator>= (val_bind<T> v, const query_column& c) | operator>= (val_bind<T> v, const query_column& c) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator>= (const query_column& c, val_bind<T2> v) | operator>= (const query_column& c, val_bind<T2> v) | |||
{ | { | |||
return c.greater_equal (v); | return c.greater_equal (v); | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
friend query | friend query_base | |||
operator>= (val_bind<T2> v, const query_column& c) | operator>= (val_bind<T2> v, const query_column& c) | |||
{ | { | |||
return c.less_equal (v); | return c.less_equal (v); | |||
} | } | |||
friend query | friend query_base | |||
operator>= (const query_column& c, ref_bind<T> r) | operator>= (const query_column& c, ref_bind<T> r) | |||
{ | { | |||
return c.greater_equal (r); | return c.greater_equal (r); | |||
} | } | |||
friend query | friend query_base | |||
operator>= (ref_bind<T> r, const query_column& c) | operator>= (ref_bind<T> r, const query_column& c) | |||
{ | { | |||
return c.less_equal (r); | return c.less_equal (r); | |||
} | } | |||
// Column comparison. | // Column comparison. | |||
// | // | |||
public: | public: | |||
template <typename T2, database_type_id ID2> | template <typename T2, database_type_id ID2> | |||
query | query_base | |||
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 (decay_traits<T>::instance () == | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "="; | q += "="; | |||
q.append (c.table (), c.column ()); | 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_base | |||
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 (decay_traits<T>::instance () != | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "!="; | q += "!="; | |||
q.append (c.table (), c.column ()); | 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_base | |||
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 (decay_traits<T>::instance () < | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<"; | q += "<"; | |||
q.append (c.table (), c.column ()); | 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_base | |||
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 (decay_traits<T>::instance () > | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">"; | q += ">"; | |||
q.append (c.table (), c.column ()); | 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_base | |||
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 (decay_traits<T>::instance () <= | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "<="; | q += "<="; | |||
q.append (c.table (), c.column ()); | 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_base | |||
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 (decay_traits<T>::instance () >= | |||
decay_traits<T2>::instance ())); | ||||
query q (table_, column_); | query_base q (table_, column_); | |||
q += ">="; | q += ">="; | |||
q.append (c.table (), c.column ()); | q.append (c.table (), c.column ()); | |||
return q; | return q; | |||
} | } | |||
private: | ||||
const char* table_; | ||||
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_base | |||
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_base q (c.table (), c.column ()); | |||
q += s; | q += s; | |||
return q; | return q; | |||
} | } | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
inline query | inline query_base | |||
operator+ (const std::string& s, const query_column<T, ID>& c) | operator+ (const std::string& s, const query_column<T, ID>& c) | |||
{ | { | |||
query q (s); | query_base q (s); | |||
q.append (c.table (), c.column ()); | q.append (c.table (), c.column ()); | |||
return q; | return q; | |||
} | } | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
inline query | inline query_base | |||
operator+ (const query_column<T, ID>& c, const query& q) | operator+ (const query_column<T, ID>& c, const query_base& q) | |||
{ | { | |||
query r (c.table (), c.column ()); | query_base r (c.table (), c.column ()); | |||
r += q; | r += q; | |||
return r; | return r; | |||
} | } | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
inline query | inline query_base | |||
operator+ (const query& q, const query_column<T, ID>& c) | operator+ (const query_base& q, const query_column<T, ID>& c) | |||
{ | { | |||
query r (q); | query_base r (q); | |||
r.append (c.table (), c.column ()); | r.append (c.table (), c.column ()); | |||
return r; | return r; | |||
} | } | |||
// | // | |||
// | // | |||
template <typename T, database_type_id> | template <typename T, database_type_id> | |||
struct query_param_impl; | struct query_param_impl; | |||
// TINY | // TINY | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_tiny>: query_param | struct query_param_impl<T, id_tiny>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_TINY; | b->buffer_type = MYSQL_TYPE_TINY; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_tiny>::set_image (image_, is_null, v); | value_traits<T, id_tiny>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
signed char image_; | signed char image_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_utiny>: query_param | struct query_param_impl<T, id_utiny>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_TINY; | b->buffer_type = MYSQL_TYPE_TINY; | |||
b->is_unsigned = true; | b->is_unsigned = true; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_utiny>::set_image (image_, is_null, v); | value_traits<T, id_utiny>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
unsigned char image_; | unsigned char image_; | |||
}; | }; | |||
// SHORT | // SHORT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_short>: query_param | struct query_param_impl<T, id_short>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_SHORT; | b->buffer_type = MYSQL_TYPE_SHORT; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_short>::set_image (image_, is_null, v); | value_traits<T, id_short>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
short image_; | short image_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_ushort>: query_param | struct query_param_impl<T, id_ushort>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_SHORT; | b->buffer_type = MYSQL_TYPE_SHORT; | |||
b->is_unsigned = true; | b->is_unsigned = true; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_ushort>::set_image (image_, is_null, v); | value_traits<T, id_ushort>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
unsigned short image_; | unsigned short image_; | |||
}; | }; | |||
// LONG | // LONG | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_long>: query_param | struct query_param_impl<T, id_long>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_LONG; | b->buffer_type = MYSQL_TYPE_LONG; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_long>::set_image (image_, is_null, v); | value_traits<T, id_long>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
int image_; | int image_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_ulong>: query_param | struct query_param_impl<T, id_ulong>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_LONG; | b->buffer_type = MYSQL_TYPE_LONG; | |||
b->is_unsigned = true; | b->is_unsigned = true; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_ulong>::set_image (image_, is_null, v); | value_traits<T, id_ulong>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
unsigned int image_; | unsigned int image_; | |||
}; | }; | |||
// LONGLONG | // LONGLONG | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_longlong>: query_param | struct query_param_impl<T, id_longlong>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_LONGLONG; | b->buffer_type = MYSQL_TYPE_LONGLONG; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_longlong>::set_image (image_, is_null, v); | value_traits<T, id_longlong>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
long long image_; | long long image_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_ulonglong>: query_param | struct query_param_impl<T, id_ulonglong>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_LONGLONG; | b->buffer_type = MYSQL_TYPE_LONGLONG; | |||
b->is_unsigned = true; | b->is_unsigned = true; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_ulonglong>::set_image (image_, is_null, v); | value_traits<T, id_ulonglong>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
unsigned long long image_; | unsigned long long image_; | |||
}; | }; | |||
// FLOAT | // FLOAT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_float>: query_param | struct query_param_impl<T, id_float>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_FLOAT; | b->buffer_type = MYSQL_TYPE_FLOAT; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_float>::set_image (image_, is_null, v); | value_traits<T, id_float>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
float image_; | float image_; | |||
}; | }; | |||
// DOUBLE | // DOUBLE | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_double>: query_param | struct query_param_impl<T, id_double>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_DOUBLE; | b->buffer_type = MYSQL_TYPE_DOUBLE; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_double>::set_image (image_, is_null, v); | value_traits<T, id_double>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
double image_; | double image_; | |||
}; | }; | |||
// DECIMAL | // DECIMAL | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_decimal>: query_param | struct query_param_impl<T, id_decimal>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
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 (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_NEWDECIMAL; | b->buffer_type = MYSQL_TYPE_NEWDECIMAL; | |||
b->buffer = buffer_.data (); | b->buffer = buffer_.data (); | |||
b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | |||
b->length = &size_; | b->length = &size_; | |||
} | } | |||
private: | private: | |||
bool | bool | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
std::size_t size (0), cap (buffer_.capacity ()); | std::size_t size (0), cap (buffer_.capacity ()); | |||
value_traits<T, id_decimal>::set_image (buffer_, size, is_null, v); | value_traits<T, id_decimal>::set_image (buffer_, size, is_null, v); | |||
size_ = static_cast<unsigned long> (size); | size_ = static_cast<unsigned long> (size); | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
unsigned long size_; | unsigned long size_; | |||
}; | }; | |||
// DATE | // DATE | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_date>: query_param | struct query_param_impl<T, id_date>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_DATE; | b->buffer_type = MYSQL_TYPE_DATE; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_date>::set_image (image_, is_null, v); | value_traits<T, id_date>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
MYSQL_TIME image_; | MYSQL_TIME image_; | |||
}; | }; | |||
// TIME | // TIME | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_time>: query_param | struct query_param_impl<T, id_time>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_TIME; | b->buffer_type = MYSQL_TYPE_TIME; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_time>::set_image (image_, is_null, v); | value_traits<T, id_time>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
MYSQL_TIME image_; | MYSQL_TIME image_; | |||
}; | }; | |||
// DATETIME | // DATETIME | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_datetime>: query_param | struct query_param_impl<T, id_datetime>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_DATETIME; | b->buffer_type = MYSQL_TYPE_DATETIME; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_datetime>::set_image (image_, is_null, v); | value_traits<T, id_datetime>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
MYSQL_TIME image_; | MYSQL_TIME image_; | |||
}; | }; | |||
// TIMESTAMP | // TIMESTAMP | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_timestamp>: query_param | struct query_param_impl<T, id_timestamp>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_TIMESTAMP; | b->buffer_type = MYSQL_TYPE_TIMESTAMP; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_timestamp>::set_image (image_, is_null, v); | value_traits<T, id_timestamp>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
MYSQL_TIME image_; | MYSQL_TIME image_; | |||
}; | }; | |||
// YEAR | // YEAR | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_year>: query_param | struct query_param_impl<T, id_year>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_SHORT; | b->buffer_type = MYSQL_TYPE_SHORT; | |||
b->is_unsigned = false; | b->is_unsigned = false; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
value_traits<T, id_year>::set_image (image_, is_null, v); | value_traits<T, id_year>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
short image_; | short image_; | |||
}; | }; | |||
// STRING | // STRING | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_string>: query_param | struct query_param_impl<T, id_string>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
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 (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_STRING; | b->buffer_type = MYSQL_TYPE_STRING; | |||
b->buffer = buffer_.data (); | b->buffer = buffer_.data (); | |||
b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | |||
b->length = &size_; | b->length = &size_; | |||
} | } | |||
private: | private: | |||
bool | bool | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
std::size_t size (0), cap (buffer_.capacity ()); | std::size_t size (0), cap (buffer_.capacity ()); | |||
value_traits<T, id_string>::set_image (buffer_, size, is_null, v); | value_traits<T, id_string>::set_image (buffer_, size, is_null, v); | |||
size_ = static_cast<unsigned long> (size); | size_ = static_cast<unsigned long> (size); | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
unsigned long size_; | unsigned long size_; | |||
}; | }; | |||
// BLOB | // BLOB | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_blob>: query_param | struct query_param_impl<T, id_blob>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
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 (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_BLOB; | b->buffer_type = MYSQL_TYPE_BLOB; | |||
b->buffer = buffer_.data (); | b->buffer = buffer_.data (); | |||
b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | |||
b->length = &size_; | b->length = &size_; | |||
} | } | |||
private: | private: | |||
bool | bool | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
std::size_t size (0), cap (buffer_.capacity ()); | std::size_t size (0), cap (buffer_.capacity ()); | |||
value_traits<T, id_blob>::set_image (buffer_, size, is_null, v); | value_traits<T, id_blob>::set_image (buffer_, size, is_null, v); | |||
size_ = static_cast<unsigned long> (size); | size_ = static_cast<unsigned long> (size); | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
unsigned long size_; | unsigned long size_; | |||
}; | }; | |||
// BIT | // BIT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_bit>: query_param | struct query_param_impl<T, id_bit>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
virtual bool | virtual bool | |||
init () | init () | |||
{ | { | |||
init (*static_cast<const T*> (value_)); | init (*static_cast<const T*> (value_)); | |||
return false; | return false; | |||
} | } | |||
virtual void | virtual void | |||
bind (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_BLOB; | b->buffer_type = MYSQL_TYPE_BLOB; | |||
b->buffer = buffer_; | b->buffer = buffer_; | |||
b->buffer_length = static_cast<unsigned long> (sizeof (buffer_)); | b->buffer_length = static_cast<unsigned long> (sizeof (buffer_)); | |||
b->length = &size_; | b->length = &size_; | |||
} | } | |||
private: | private: | |||
void | void | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
std::size_t size (0); | std::size_t size (0); | |||
value_traits<T, id_bit>::set_image ( | value_traits<T, id_bit>::set_image ( | |||
buffer_, sizeof (buffer_), size, is_null, v); | buffer_, sizeof (buffer_), size, is_null, v); | |||
size_ = static_cast<unsigned long> (size); | size_ = static_cast<unsigned long> (size); | |||
} | } | |||
private: | private: | |||
// Max 64 bit. | // Max 64 bit. | |||
skipping to change at line 1791 | skipping to change at line 2028 | |||
unsigned long size_; | unsigned long size_; | |||
}; | }; | |||
// ENUM | // ENUM | |||
// | // | |||
// The image type can be either integer or string. | // The image type can be either integer or string. | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_enum>: query_param | struct query_param_impl<T, id_enum>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
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 (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
enum_traits::bind (*b, image_, size_, 0); | enum_traits::bind (*b, image_, size_, 0); | |||
} | } | |||
private: | private: | |||
bool | bool | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
return enum_traits::set_image (image_, size_, is_null, v); | return enum_traits::set_image (image_, size_, is_null, v); | |||
} | } | |||
private: | private: | |||
typename value_traits<T, id_enum>::image_type image_; | typename value_traits<T, id_enum>::image_type image_; | |||
unsigned long size_; // Keep size in case it is a string. | unsigned long size_; // Keep size in case it is a string. | |||
}; | }; | |||
// SET | // SET | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_set>: query_param | struct query_param_impl<T, id_set>: query_param | |||
{ | { | |||
query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} | query_param_impl (ref_bind<T> r) : query_param (r.ptr ()) {} | |||
query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} | |||
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 (MYSQL_BIND* b) | bind (MYSQL_BIND* b) | |||
{ | { | |||
b->buffer_type = MYSQL_TYPE_STRING; | b->buffer_type = MYSQL_TYPE_STRING; | |||
b->buffer = buffer_.data (); | b->buffer = buffer_.data (); | |||
b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | b->buffer_length = static_cast<unsigned long> (buffer_.capacity ()) ; | |||
b->length = &size_; | b->length = &size_; | |||
} | } | |||
private: | private: | |||
bool | bool | |||
init (const T& v) | init (typename decay_traits<T>::type v) | |||
{ | { | |||
bool is_null (false); // Can't be NULL. | bool is_null (false); // Can't be NULL. | |||
std::size_t size (0), cap (buffer_.capacity ()); | std::size_t size (0), cap (buffer_.capacity ()); | |||
value_traits<T, id_set>::set_image (buffer_, size, is_null, v); | value_traits<T, id_set>::set_image (buffer_, size, is_null, v); | |||
size_ = static_cast<unsigned long> (size); | size_ = static_cast<unsigned long> (size); | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
unsigned long size_; | unsigned long size_; | |||
}; | }; | |||
} | } | |||
} | } | |||
// odb::query specialization for MySQL. | // odb::mysql::query and odb::query specialization for MySQL. | |||
// | // | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | ||||
{ | ||||
template <typename T> | ||||
class query: public query_base, | ||||
public query_selector<T, id_mysql>::columns_type | ||||
{ | ||||
public: | ||||
// We don't define any typedefs here since they may clash with | ||||
// column names defined by our base type. | ||||
// | ||||
query () | ||||
{ | ||||
} | ||||
explicit | ||||
query (bool v) | ||||
: query_base (v) | ||||
{ | ||||
} | ||||
explicit | ||||
query (const char* q) | ||||
: query_base (q) | ||||
{ | ||||
} | ||||
explicit | ||||
query (const std::string& q) | ||||
: query_base (q) | ||||
{ | ||||
} | ||||
template <typename T2> | ||||
explicit | ||||
query (val_bind<T2> v) | ||||
: query_base (v) | ||||
{ | ||||
} | ||||
template <typename T2> | ||||
explicit | ||||
query (ref_bind<T2> r) | ||||
: query_base (r) | ||||
{ | ||||
} | ||||
query (const query_base& q) | ||||
: query_base (q) | ||||
{ | ||||
} | ||||
template <database_type_id ID> | ||||
query (const query_column<bool, ID>& qc) | ||||
: query_base (qc) | ||||
{ | ||||
} | ||||
query (const odb::query_base& q) | ||||
: query_base (q) | ||||
{ | ||||
} | ||||
}; | ||||
namespace core | ||||
{ | ||||
using mysql::query; | ||||
} | ||||
} | ||||
// Derive odb::query from odb::mysql::query so that it can be | ||||
// implicitly converted in mysql::database::query() calls. | ||||
// | ||||
template <typename T> | template <typename T> | |||
class query<T, mysql::query>: public mysql::query, | class query<T, mysql::query_base>: public mysql::query<T> | |||
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) | |||
: mysql::query (v) | : mysql::query<T> (v) | |||
{ | { | |||
} | } | |||
explicit | explicit | |||
query (const char* q) | query (const char* q) | |||
: mysql::query (q) | : mysql::query<T> (q) | |||
{ | { | |||
} | } | |||
explicit | explicit | |||
query (const std::string& q) | query (const std::string& q) | |||
: mysql::query (q) | : mysql::query<T> (q) | |||
{ | { | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
explicit | explicit | |||
query (mysql::val_bind<T2> v) | query (mysql::val_bind<T2> v) | |||
: mysql::query (mysql::query (v)) | : mysql::query<T> (v) | |||
{ | { | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
explicit | explicit | |||
query (mysql::ref_bind<T2> r) | query (mysql::ref_bind<T2> r) | |||
: mysql::query (mysql::query (r)) | : mysql::query<T> (r) | |||
{ | { | |||
} | } | |||
query (const mysql::query& q) | query (const mysql::query_base& q) | |||
: mysql::query (q) | : mysql::query<T> (q) | |||
{ | { | |||
} | } | |||
template <mysql::database_type_id ID> | template <mysql::database_type_id ID> | |||
query (const mysql::query_column<bool, ID>& qc) | query (const mysql::query_column<bool, ID>& qc) | |||
: mysql::query (qc) | : mysql::query<T> (qc) | |||
{ | { | |||
} | } | |||
}; | }; | |||
} | } | |||
#include <odb/mysql/query.ixx> | #include <odb/mysql/query.ixx> | |||
#include <odb/mysql/query.txx> | #include <odb/mysql/query.txx> | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
End of changes. 254 change blocks. | ||||
318 lines changed or deleted | 629 lines changed or added | |||
query.ixx | query.ixx | |||
---|---|---|---|---|
// file : odb/mysql/query.ixx | // file : odb/mysql/query.ixx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
inline binding& query_base:: | ||||
parameters_binding () const | ||||
{ | ||||
return binding_; | ||||
} | ||||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
inline void query:: | inline void query_base:: | |||
append (val_bind<T> v, const char* conv) | append (val_bind<T> v, const char* conv) | |||
{ | { | |||
add ( | append ( | |||
details::shared_ptr<query_param> ( | details::shared_ptr<query_param> ( | |||
new (details::shared) query_param_impl<T, ID> (v)), | new (details::shared) query_param_impl<T, ID> (v)), | |||
conv); | conv); | |||
} | } | |||
template <typename T, database_type_id ID> | template <typename T, database_type_id ID> | |||
inline void query:: | inline void query_base:: | |||
append (ref_bind<T> r, const char* conv) | append (ref_bind<T> r, const char* conv) | |||
{ | { | |||
add ( | append ( | |||
details::shared_ptr<query_param> ( | details::shared_ptr<query_param> ( | |||
new (details::shared) query_param_impl<T, ID> (r)), | new (details::shared) query_param_impl<T, ID> (r)), | |||
conv); | conv); | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 6 change blocks. | ||||
5 lines changed or deleted | 11 lines changed or added | |||
query.txx | query.txx | |||
---|---|---|---|---|
// file : odb/mysql/query.txx | // file : odb/mysql/query.txx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
// query | // query_base | |||
// | // | |||
template <database_type_id ID> | template <database_type_id ID> | |||
query:: | query_base:: | |||
query (const query_column<bool, ID>& c) | query_base (const query_column<bool, ID>& c) | |||
: binding_ (0, 0) | : binding_ (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. | |||
// | // | |||
append (c.table (), c.column ()); | append (c.table (), c.column ()); | |||
append ("="); | append ("="); | |||
append<bool, ID> (val_bind<bool> (true), c.conversion ()); | 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_base query_column<T, ID>:: | |||
in (const T& v1, const T& v2) const | in (decayed_type v1, decayed_type v2) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IN ("; | q += "IN ("; | |||
q.append<T, ID> (val_bind<T> (v1), conversion_); | q.append<T, ID> (val_bind<T> (v1), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v2), conversion_); | 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_base query_column<T, ID>:: | |||
in (const T& v1, const T& v2, const T& v3) const | in (decayed_type v1, decayed_type v2, decayed_type v3) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IN ("; | q += "IN ("; | |||
q.append<T, ID> (val_bind<T> (v1), conversion_); | q.append<T, ID> (val_bind<T> (v1), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v2), conversion_); | q.append<T, ID> (val_bind<T> (v2), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v3), conversion_); | 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_base query_column<T, ID>:: | |||
in (const T& v1, const T& v2, const T& v3, const T& v4) const | in (decayed_type v1, decayed_type v2, decayed_type v3, | |||
decayed_type v4) const | ||||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IN ("; | q += "IN ("; | |||
q.append<T, ID> (val_bind<T> (v1), conversion_); | q.append<T, ID> (val_bind<T> (v1), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v2), conversion_); | q.append<T, ID> (val_bind<T> (v2), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v3), conversion_); | q.append<T, ID> (val_bind<T> (v3), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v4), conversion_); | 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_base query_column<T, ID>:: | |||
in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) co | in (decayed_type v1, decayed_type v2, decayed_type v3, decayed_type v4, | |||
nst | decayed_type v5) const | |||
{ | { | |||
query q (table_, column_); | query_base q (table_, column_); | |||
q += "IN ("; | q += "IN ("; | |||
q.append<T, ID> (val_bind<T> (v1), conversion_); | q.append<T, ID> (val_bind<T> (v1), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v2), conversion_); | q.append<T, ID> (val_bind<T> (v2), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v3), conversion_); | q.append<T, ID> (val_bind<T> (v3), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v4), conversion_); | q.append<T, ID> (val_bind<T> (v4), conversion_); | |||
q += ","; | q += ","; | |||
q.append<T, ID> (val_bind<T> (v5), conversion_); | 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_base query_column<T, ID>:: | |||
in_range (I begin, I end) const | in_range (I begin, I end) const | |||
{ | { | |||
query q (table_, column_); | query_base 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), conversion_); | q.append<T, ID> (val_bind<T> (*i), conversion_); | |||
} | } | |||
q += ")"; | q += ")"; | |||
return q; | return q; | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 14 change blocks. | ||||
19 lines changed or deleted | 21 lines changed or added | |||
simple-object-result.hxx | simple-object-result.hxx | |||
---|---|---|---|---|
// file : odb/mysql/simple-object-result.hxx | // file : odb/mysql/simple-object-result.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_SIMPLE_OBJECT_RESULT_HXX | #ifndef ODB_MYSQL_SIMPLE_OBJECT_RESULT_HXX | |||
#define ODB_MYSQL_SIMPLE_OBJECT_RESULT_HXX | #define ODB_MYSQL_SIMPLE_OBJECT_RESULT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/simple-object-result.hxx> | #include <odb/simple-object-result.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> // query | #include <odb/mysql/forward.hxx> // query_base | |||
#include <odb/mysql/statement.hxx> | #include <odb/mysql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class object_result_impl: public odb::object_result_impl<T> | class object_result_impl: public odb::object_result_impl<T> | |||
{ | { | |||
public: | public: | |||
typedef odb::object_result_impl<T> base_type; | typedef odb::object_result_impl<T> base_type; | |||
typedef typename base_type::object_type object_type; | ||||
typedef typename base_type::object_traits object_traits; | ||||
typedef typename base_type::id_type id_type; | typedef typename base_type::id_type id_type; | |||
typedef typename base_type::object_type object_type; | ||||
typedef typename base_type::pointer_type pointer_type; | typedef typename base_type::pointer_type pointer_type; | |||
typedef object_traits_impl<object_type, id_mysql> object_traits; | ||||
typedef typename base_type::pointer_traits pointer_traits; | typedef typename base_type::pointer_traits pointer_traits; | |||
typedef typename object_traits::statements_type statements_type; | typedef typename object_traits::statements_type statements_type; | |||
virtual | virtual | |||
~object_result_impl (); | ~object_result_impl (); | |||
object_result_impl (const query&, | object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement>, | details::shared_ptr<select_statement>, | |||
statements_type&); | statements_type&); | |||
virtual void | virtual void | |||
load (object_type&, bool fetch); | load (object_type&, bool fetch); | |||
virtual id_type | virtual id_type | |||
load_id (); | load_id (); | |||
virtual void | virtual void | |||
next (); | next (); | |||
virtual void | virtual void | |||
cache (); | cache (); | |||
virtual std::size_t | virtual std::size_t | |||
size (); | size (); | |||
virtual void | ||||
invalidate (); | ||||
using base_type::current; | using base_type::current; | |||
private: | private: | |||
void | void | |||
fetch (bool next = true); | fetch (bool next = true); | |||
private: | private: | |||
details::shared_ptr<select_statement> statement_; | details::shared_ptr<select_statement> statement_; | |||
statements_type& statements_; | statements_type& statements_; | |||
std::size_t count_; | std::size_t count_; | |||
End of changes. 7 change blocks. | ||||
6 lines changed or deleted | 9 lines changed or added | |||
simple-object-result.txx | simple-object-result.txx | |||
---|---|---|---|---|
// file : odb/mysql/simple-object-result.txx | // file : odb/mysql/simple-object-result.txx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cassert> | #include <cassert> | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> // result_not_cached | #include <odb/exceptions.hxx> // result_not_cached | |||
#include <odb/mysql/simple-object-statements.hxx> | #include <odb/mysql/simple-object-statements.hxx> | |||
namespace odb | namespace odb | |||
skipping to change at line 25 | skipping to change at line 25 | |||
{ | { | |||
template <typename T> | template <typename T> | |||
object_result_impl<T>:: | object_result_impl<T>:: | |||
~object_result_impl () | ~object_result_impl () | |||
{ | { | |||
if (!this->end_) | if (!this->end_) | |||
statement_->free_result (); | statement_->free_result (); | |||
} | } | |||
template <typename T> | template <typename T> | |||
void object_result_impl<T>:: | ||||
invalidate () | ||||
{ | ||||
if (!this->end_) | ||||
{ | ||||
statement_->free_result (); | ||||
this->end_ = true; | ||||
} | ||||
statement_.reset (); | ||||
} | ||||
template <typename T> | ||||
object_result_impl<T>:: | object_result_impl<T>:: | |||
object_result_impl (const query&, | object_result_impl (const query_base&, | |||
details::shared_ptr<select_statement> statement, | details::shared_ptr<select_statement> statement, | |||
statements_type& statements) | statements_type& statements) | |||
: base_type (statements.connection ().database ()), | : base_type (statements.connection ()), | |||
statement_ (statement), | statement_ (statement), | |||
statements_ (statements), | statements_ (statements), | |||
count_ (0) | count_ (0) | |||
{ | { | |||
} | } | |||
template <typename T> | template <typename T> | |||
void object_result_impl<T>:: | void object_result_impl<T>:: | |||
load (object_type& obj, bool f) | load (object_type& obj, bool f) | |||
{ | { | |||
skipping to change at line 55 | skipping to change at line 68 | |||
// between the last time we fetched and this call to load(). | // between the last time we fetched and this call to load(). | |||
// | // | |||
fetch (false); | fetch (false); | |||
} | } | |||
// This is a top-level call so the statements cannot be locked. | // This is a top-level call so the statements cannot be locked. | |||
// | // | |||
assert (!statements_.locked ()); | assert (!statements_.locked ()); | |||
typename statements_type::auto_lock l (statements_); | typename statements_type::auto_lock l (statements_); | |||
odb::database& db (this->database ()); | object_traits::callback (this->db_, obj, callback_event::pre_load); | |||
object_traits::callback (db, obj, callback_event::pre_load); | ||||
typename object_traits::image_type& i (statements_.image ()); | typename object_traits::image_type& i (statements_.image ()); | |||
object_traits::init (obj, i, &db); | object_traits::init (obj, i, &this->db_); | |||
// Initialize the id image and binding and load the rest of the objec t | // Initialize the id image and binding and load the rest of the objec t | |||
// (containers, etc). | // (containers, etc). | |||
// | // | |||
typename object_traits::id_image_type& idi (statements_.id_image ()); | typename object_traits::id_image_type& idi (statements_.id_image ()); | |||
object_traits::init (idi, object_traits::id (i)); | object_traits::init (idi, object_traits::id (i)); | |||
binding& idb (statements_.id_image_binding ()); | binding& idb (statements_.id_image_binding ()); | |||
if (idi.version != statements_.id_image_version () || idb.version == 0) | if (idi.version != statements_.id_image_version () || idb.version == 0) | |||
{ | { | |||
object_traits::bind (idb.bind, idi); | object_traits::bind (idb.bind, idi); | |||
statements_.id_image_version (idi.version); | statements_.id_image_version (idi.version); | |||
idb.version++; | idb.version++; | |||
} | } | |||
object_traits::load_ (statements_, obj); | object_traits::load_ (statements_, obj); | |||
statements_.load_delayed (); | statements_.load_delayed (); | |||
l.unlock (); | l.unlock (); | |||
object_traits::callback (db, obj, callback_event::post_load); | object_traits::callback (this->db_, obj, callback_event::post_load); | |||
} | } | |||
template <typename T> | template <typename T> | |||
typename object_result_impl<T>::id_type | typename object_result_impl<T>::id_type | |||
object_result_impl<T>:: | object_result_impl<T>:: | |||
load_id () | load_id () | |||
{ | { | |||
if (count_ > statement_->fetched ()) | if (count_ > statement_->fetched ()) | |||
fetch (); | fetch (); | |||
else if (statement_->cached ()) | else if (statement_->cached ()) | |||
End of changes. 7 change blocks. | ||||
7 lines changed or deleted | 19 lines changed or added | |||
simple-object-statements.hxx | simple-object-statements.hxx | |||
---|---|---|---|---|
// file : odb/mysql/simple-object-statements.hxx | // file : odb/mysql/simple-object-statements.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_SIMPLE_OBJECT_STATEMENTS_HXX | #ifndef ODB_MYSQL_SIMPLE_OBJECT_STATEMENTS_HXX | |||
#define ODB_MYSQL_SIMPLE_OBJECT_STATEMENTS_HXX | #define ODB_MYSQL_SIMPLE_OBJECT_STATEMENTS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <vector> | #include <vector> | |||
#include <cassert> | #include <cassert> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
skipping to change at line 48 | skipping to change at line 48 | |||
// and when needed. We will also need to store a pointer to the | // and when needed. We will also need to store a pointer to the | |||
// deleter function which will be initialized during allocation | // deleter function which will be initialized during allocation | |||
// (at that point we know that the cache class is defined). | // (at that point we know that the cache class is defined). | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct container_statement_cache_ptr | struct container_statement_cache_ptr | |||
{ | { | |||
typedef mysql::connection connection_type; | typedef mysql::connection connection_type; | |||
container_statement_cache_ptr (): p_ (0) {} | container_statement_cache_ptr (): p_ (0) {} | |||
~container_statement_cache_ptr () {if (p_ != 0) (this->*deleter_) (0) | ~container_statement_cache_ptr () | |||
;} | { | |||
if (p_ != 0) | ||||
(this->*deleter_) (0, 0); | ||||
} | ||||
T& | T& | |||
get (connection_type& c) | get (connection_type& c, binding& id) | |||
{ | { | |||
if (p_ == 0) | if (p_ == 0) | |||
allocate (&c); | allocate (&c, &id); | |||
return *p_; | return *p_; | |||
} | } | |||
private: | private: | |||
void | void | |||
allocate (connection_type*); | allocate (connection_type*, binding*); | |||
private: | private: | |||
T* p_; | T* p_; | |||
void (container_statement_cache_ptr::*deleter_) (connection_type*); | void (container_statement_cache_ptr::*deleter_) ( | |||
connection_type*, binding*); | ||||
}; | }; | |||
template <typename T> | template <typename T> | |||
void container_statement_cache_ptr<T>:: | void container_statement_cache_ptr<T>:: | |||
allocate (connection_type* c) | allocate (connection_type* c, binding* id) | |||
{ | { | |||
// To reduce object code size, this function acts as both allocator | // To reduce object code size, this function acts as both allocator | |||
// and deleter. | // and deleter. | |||
// | // | |||
if (p_ == 0) | if (p_ == 0) | |||
{ | { | |||
p_ = new T (*c); | p_ = new T (*c, *id); | |||
deleter_ = &container_statement_cache_ptr<T>::allocate; | deleter_ = &container_statement_cache_ptr<T>::allocate; | |||
} | } | |||
else | else | |||
delete p_; | delete p_; | |||
} | } | |||
// | // | |||
// Implementation for objects with object id. | // Implementation for objects with object id. | |||
// | // | |||
skipping to change at line 150 | skipping to change at line 155 | |||
bool locked_; | bool locked_; | |||
}; | }; | |||
template <typename T, bool optimistic> | template <typename T, bool optimistic> | |||
struct optimistic_data; | struct optimistic_data; | |||
template <typename T> | template <typename T> | |||
struct optimistic_data<T, true> | struct optimistic_data<T, true> | |||
{ | { | |||
typedef T object_type; | typedef T object_type; | |||
typedef odb::object_traits<object_type> object_traits; | typedef object_traits_impl<object_type, id_mysql> object_traits; | |||
optimistic_data (MYSQL_BIND*); | optimistic_data (MYSQL_BIND*); | |||
// The id + optimistic column binding. | // The id + optimistic column binding. | |||
// | // | |||
std::size_t id_image_version_; | std::size_t id_image_version_; | |||
binding id_image_binding_; | binding id_image_binding_; | |||
details::shared_ptr<delete_statement> erase_; | details::shared_ptr<delete_statement> erase_; | |||
}; | }; | |||
skipping to change at line 173 | skipping to change at line 178 | |||
struct optimistic_data<T, false> | struct optimistic_data<T, false> | |||
{ | { | |||
optimistic_data (MYSQL_BIND*) {} | optimistic_data (MYSQL_BIND*) {} | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
class object_statements: public object_statements_base | class object_statements: public object_statements_base | |||
{ | { | |||
public: | public: | |||
typedef T object_type; | typedef T object_type; | |||
typedef odb::object_traits<object_type> object_traits; | typedef object_traits_impl<object_type, id_mysql> object_traits; | |||
typedef typename object_traits::id_type id_type; | typedef typename object_traits::id_type id_type; | |||
typedef typename object_traits::pointer_type pointer_type; | typedef typename object_traits::pointer_type pointer_type; | |||
typedef typename object_traits::image_type image_type; | typedef typename object_traits::image_type image_type; | |||
typedef typename object_traits::id_image_type id_image_type; | typedef typename object_traits::id_image_type id_image_type; | |||
typedef | typedef | |||
typename object_traits::pointer_cache_traits | typename object_traits::pointer_cache_traits | |||
pointer_cache_traits; | pointer_cache_traits; | |||
typedef | typedef | |||
skipping to change at line 415 | skipping to change at line 420 | |||
} | } | |||
return *od_.erase_; | return *od_.erase_; | |||
} | } | |||
// Container statement cache. | // Container statement cache. | |||
// | // | |||
container_statement_cache_type& | container_statement_cache_type& | |||
container_statment_cache () | container_statment_cache () | |||
{ | { | |||
return container_statement_cache_.get (conn_); | return container_statement_cache_.get (conn_, id_image_binding_); | |||
} | } | |||
public: | public: | |||
// select = total | // select = total | |||
// insert = total - inverse - managed_optimistic | // insert = total - inverse - managed_optimistic | |||
// update = total - inverse - managed_optimistic - id - readonly | // update = total - inverse - managed_optimistic - id - readonly | |||
// | // | |||
static const std::size_t select_column_count = | static const std::size_t select_column_count = | |||
object_traits::column_count; | object_traits::column_count; | |||
End of changes. 11 change blocks. | ||||
12 lines changed or deleted | 16 lines changed or added | |||
simple-object-statements.ixx | simple-object-statements.ixx | |||
---|---|---|---|---|
// file : odb/mysql/simple-object-statements.ixx | // file : odb/mysql/simple-object-statements.ixx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
// | // | |||
// auto_unlock | // auto_unlock | |||
// | // | |||
inline object_statements_base::auto_unlock:: | inline object_statements_base::auto_unlock:: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
simple-object-statements.txx | simple-object-statements.txx | |||
---|---|---|---|---|
// file : odb/mysql/simple-object-statements.txx | // file : odb/mysql/simple-object-statements.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cstring> // std::memset | #include <cstring> // std::memset | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> | #include <odb/exceptions.hxx> | |||
#include <odb/mysql/connection.hxx> | #include <odb/mysql/connection.hxx> | |||
namespace odb | namespace odb | |||
skipping to change at line 85 | skipping to change at line 85 | |||
load_delayed_ () | load_delayed_ () | |||
{ | { | |||
database& db (connection ().database ()); | database& db (connection ().database ()); | |||
delayed_loads dls; | delayed_loads dls; | |||
swap_guard sg (*this, dls); | swap_guard sg (*this, dls); | |||
while (!dls.empty ()) | while (!dls.empty ()) | |||
{ | { | |||
delayed_load l (dls.back ()); | delayed_load l (dls.back ()); | |||
typename pointer_cache_traits::insert_guard g (l.pos); | typename pointer_cache_traits::insert_guard ig (l.pos); | |||
dls.pop_back (); | dls.pop_back (); | |||
if (l.loader == 0) | if (l.loader == 0) | |||
{ | { | |||
if (!object_traits::find_ (*this, &l.id)) | if (!object_traits::find_ (*this, &l.id)) | |||
throw object_not_persistent (); | throw object_not_persistent (); | |||
object_traits::callback (db, *l.obj, callback_event::pre_load); | object_traits::callback (db, *l.obj, callback_event::pre_load); | |||
// Our calls to init/load below can result in additional delayed | // Our calls to init/load below can result in additional delayed | |||
skipping to change at line 121 | skipping to change at line 121 | |||
// returning). | // returning). | |||
// | // | |||
{ | { | |||
auto_unlock u (*this); | auto_unlock u (*this); | |||
object_traits::callback (db, *l.obj, callback_event::post_load) ; | object_traits::callback (db, *l.obj, callback_event::post_load) ; | |||
} | } | |||
} | } | |||
else | else | |||
l.loader (db, l.id, *l.obj); | l.loader (db, l.id, *l.obj); | |||
g.release (); | pointer_cache_traits::load (ig.position ()); | |||
ig.release (); | ||||
} | } | |||
} | } | |||
template <typename T> | template <typename T> | |||
void object_statements<T>:: | void object_statements<T>:: | |||
clear_delayed_ () | clear_delayed_ () | |||
{ | { | |||
// Remove the objects from the session cache. This is not the most | // Remove the objects from the session cache. | |||
// efficient way to do this (cache_traits::erase() will check for | ||||
// a session on every iteration), but the delay vector won't be | ||||
// empty only if something goes wrong (i.e., we are throwing an | ||||
// exception). | ||||
// | // | |||
for (typename delayed_loads::iterator i (delayed_.begin ()), | for (typename delayed_loads::iterator i (delayed_.begin ()), | |||
e (delayed_.end ()); i != e; ++i) | e (delayed_.end ()); i != e; ++i) | |||
{ | { | |||
pointer_cache_traits::erase (i->pos); | pointer_cache_traits::erase (i->pos); | |||
} | } | |||
delayed_.clear (); | delayed_.clear (); | |||
} | } | |||
} | } | |||
End of changes. 4 change blocks. | ||||
8 lines changed or deleted | 5 lines changed or added | |||
statement-cache.hxx | statement-cache.hxx | |||
---|---|---|---|---|
// file : odb/mysql/statement-cache.hxx | // file : odb/mysql/statement-cache.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_STATEMENT_CACHE_HXX | #ifndef ODB_MYSQL_STATEMENT_CACHE_HXX | |||
#define ODB_MYSQL_STATEMENT_CACHE_HXX | #define ODB_MYSQL_STATEMENT_CACHE_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <map> | #include <map> | |||
#include <typeinfo> | #include <typeinfo> | |||
skipping to change at line 35 | skipping to change at line 35 | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
class LIBODB_MYSQL_EXPORT statement_cache | class LIBODB_MYSQL_EXPORT statement_cache | |||
{ | { | |||
public: | public: | |||
statement_cache (connection& conn): conn_ (conn) {} | statement_cache (connection& conn): conn_ (conn) {} | |||
template <typename T> | template <typename T> | |||
typename object_traits<T>::statements_type& | typename object_traits_impl<T, id_mysql>::statements_type& | |||
find_object (); | find_object (); | |||
template <typename T> | template <typename T> | |||
view_statements<T>& | view_statements<T>& | |||
find_view (); | find_view (); | |||
private: | private: | |||
typedef std::map<const std::type_info*, | typedef std::map<const std::type_info*, | |||
details::shared_ptr<statements_base>, | details::shared_ptr<statements_base>, | |||
details::type_info_comparator> map; | details::type_info_comparator> map; | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
statement-cache.txx | statement-cache.txx | |||
---|---|---|---|---|
// file : odb/mysql/statement-cache.txx | // file : odb/mysql/statement-cache.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
typename object_traits<T>::statements_type& statement_cache:: | typename object_traits_impl<T, id_mysql>::statements_type& | |||
statement_cache:: | ||||
find_object () | find_object () | |||
{ | { | |||
typedef typename object_traits<T>::statements_type statements_type; | typedef | |||
typename object_traits_impl<T, id_mysql>::statements_type | ||||
statements_type; | ||||
map::iterator i (map_.find (&typeid (T))); | map::iterator i (map_.find (&typeid (T))); | |||
if (i != map_.end ()) | if (i != map_.end ()) | |||
return static_cast<statements_type&> (*i->second); | return static_cast<statements_type&> (*i->second); | |||
details::shared_ptr<statements_type> p ( | details::shared_ptr<statements_type> p ( | |||
new (details::shared) statements_type (conn_)); | new (details::shared) statements_type (conn_)); | |||
map_.insert (map::value_type (&typeid (T), p)); | map_.insert (map::value_type (&typeid (T), p)); | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 6 lines changed or added | |||
statement.hxx | statement.hxx | |||
---|---|---|---|---|
// file : odb/mysql/statement.hxx | // file : odb/mysql/statement.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_STATEMENT_HXX | #ifndef ODB_MYSQL_STATEMENT_HXX | |||
#define ODB_MYSQL_STATEMENT_HXX | #define ODB_MYSQL_STATEMENT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <string> | #include <string> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | ||||
#include <odb/statement.hxx> | #include <odb/statement.hxx> | |||
#include <odb/mysql/mysql.hxx> | #include <odb/mysql/mysql.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> | ||||
#include <odb/mysql/binding.hxx> | #include <odb/mysql/binding.hxx> | |||
#include <odb/mysql/connection.hxx> | ||||
#include <odb/mysql/auto-handle.hxx> | #include <odb/mysql/auto-handle.hxx> | |||
#include <odb/mysql/details/export.hxx> | #include <odb/mysql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
class connection; | class connection; | |||
class LIBODB_MYSQL_EXPORT statement: public odb::statement | class LIBODB_MYSQL_EXPORT statement: public odb::statement | |||
{ | { | |||
public: | public: | |||
typedef mysql::connection connection_type; | ||||
virtual | virtual | |||
~statement () = 0; | ~statement () = 0; | |||
MYSQL_STMT* | MYSQL_STMT* | |||
handle () const | handle () const | |||
{ | { | |||
return stmt_; | return stmt_; | |||
} | } | |||
virtual const char* | virtual const char* | |||
text () const; | text () const; | |||
virtual connection_type& | ||||
connection () | ||||
{ | ||||
return conn_; | ||||
} | ||||
// Cancel the statement execution (e.g., result fetching) so | // Cancel the statement execution (e.g., result fetching) so | |||
// that another statement can be executed on the connection. | // that another statement can be executed on the connection. | |||
// | // | |||
virtual void | virtual void | |||
cancel (); | cancel (); | |||
protected: | protected: | |||
statement (connection&, const std::string& text); | statement (connection_type&, const std::string& text); | |||
statement (connection&, const char* text, bool copy_text); | statement (connection_type&, const char* text, bool copy_text); | |||
private: | private: | |||
void | void | |||
init (std::size_t text_size); | init (std::size_t text_size); | |||
protected: | protected: | |||
connection& conn_; | connection_type& conn_; | |||
std::string text_copy_; | std::string text_copy_; | |||
const char* text_; | const char* text_; | |||
auto_handle<MYSQL_STMT> stmt_; | auto_handle<MYSQL_STMT> stmt_; | |||
}; | }; | |||
class LIBODB_MYSQL_EXPORT select_statement: public statement | class LIBODB_MYSQL_EXPORT select_statement: public statement | |||
{ | { | |||
public: | public: | |||
virtual | virtual | |||
~select_statement (); | ~select_statement (); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const std::string& text, | const std::string& text, | |||
binding& param, | binding& param, | |||
binding& result); | binding& result); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const char* text, | const char* text, | |||
binding& param, | binding& param, | |||
binding& result, | binding& result, | |||
bool copy_text = true); | bool copy_text = true); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const std::string& text, | const std::string& text, | |||
binding& result); | binding& result); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const char* text, | const char* text, | |||
binding& result, | binding& result, | |||
bool copy_text = true); | bool copy_text = true); | |||
enum result | enum result | |||
{ | { | |||
success, | success, | |||
no_data, | no_data, | |||
truncated | truncated | |||
}; | }; | |||
skipping to change at line 179 | skipping to change at line 188 | |||
private: | private: | |||
select_statement& s_; | select_statement& s_; | |||
}; | }; | |||
class LIBODB_MYSQL_EXPORT insert_statement: public statement | class LIBODB_MYSQL_EXPORT insert_statement: public statement | |||
{ | { | |||
public: | public: | |||
virtual | virtual | |||
~insert_statement (); | ~insert_statement (); | |||
insert_statement (connection& conn, | insert_statement (connection_type& conn, | |||
const std::string& text, | const std::string& text, | |||
binding& param); | binding& param); | |||
insert_statement (connection& conn, | insert_statement (connection_type& conn, | |||
const char* text, | const char* text, | |||
binding& param, | binding& param, | |||
bool copy_text = true); | bool copy_text = true); | |||
// Return true if successful and false if the row is a duplicate. | // Return true if successful and false if the row is a duplicate. | |||
// All other errors are reported by throwing exceptions. | // All other errors are reported by throwing exceptions. | |||
// | // | |||
bool | bool | |||
execute (); | execute (); | |||
skipping to change at line 212 | skipping to change at line 221 | |||
binding& param_; | binding& param_; | |||
std::size_t param_version_; | std::size_t param_version_; | |||
}; | }; | |||
class LIBODB_MYSQL_EXPORT update_statement: public statement | class LIBODB_MYSQL_EXPORT update_statement: public statement | |||
{ | { | |||
public: | public: | |||
virtual | virtual | |||
~update_statement (); | ~update_statement (); | |||
update_statement (connection& conn, | update_statement (connection_type& conn, | |||
const std::string& text, | const std::string& text, | |||
binding& param); | binding& param); | |||
update_statement (connection& conn, | update_statement (connection_type& conn, | |||
const char* text, | const char* text, | |||
binding& param, | binding& param, | |||
bool copy_text = true); | bool copy_text = true); | |||
unsigned long long | unsigned long long | |||
execute (); | execute (); | |||
private: | private: | |||
update_statement (const update_statement&); | update_statement (const update_statement&); | |||
update_statement& operator= (const update_statement&); | update_statement& operator= (const update_statement&); | |||
skipping to change at line 239 | skipping to change at line 248 | |||
binding& param_; | binding& param_; | |||
std::size_t param_version_; | std::size_t param_version_; | |||
}; | }; | |||
class LIBODB_MYSQL_EXPORT delete_statement: public statement | class LIBODB_MYSQL_EXPORT delete_statement: public statement | |||
{ | { | |||
public: | public: | |||
virtual | virtual | |||
~delete_statement (); | ~delete_statement (); | |||
delete_statement (connection& conn, | delete_statement (connection_type& conn, | |||
const std::string& text, | const std::string& text, | |||
binding& param); | binding& param); | |||
delete_statement (connection& conn, | delete_statement (connection_type& conn, | |||
const char* text, | const char* text, | |||
binding& param, | binding& param, | |||
bool copy_text = true); | bool copy_text = true); | |||
unsigned long long | unsigned long long | |||
execute (); | execute (); | |||
private: | private: | |||
delete_statement (const delete_statement&); | delete_statement (const delete_statement&); | |||
delete_statement& operator= (const delete_statement&); | delete_statement& operator= (const delete_statement&); | |||
End of changes. 18 change blocks. | ||||
15 lines changed or deleted | 24 lines changed or added | |||
statements-base.hxx | statements-base.hxx | |||
---|---|---|---|---|
// file : odb/mysql/statements-base.hxx | // file : odb/mysql/statements-base.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_STATEMENTS_BASE_HXX | #ifndef ODB_MYSQL_STATEMENTS_BASE_HXX | |||
#define ODB_MYSQL_STATEMENTS_BASE_HXX | #define ODB_MYSQL_STATEMENTS_BASE_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
tracer.hxx | tracer.hxx | |||
---|---|---|---|---|
// file : odb/mysql/tracer.hxx | // file : odb/mysql/tracer.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_TRACER_HXX | #ifndef ODB_MYSQL_TRACER_HXX | |||
#define ODB_MYSQL_TRACER_HXX | #define ODB_MYSQL_TRACER_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/tracer.hxx> | #include <odb/tracer.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
traits.hxx | traits.hxx | |||
---|---|---|---|---|
// file : odb/mysql/traits.hxx | // file : odb/mysql/traits.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_TRAITS_HXX | #ifndef ODB_MYSQL_TRAITS_HXX | |||
#define ODB_MYSQL_TRAITS_HXX | #define ODB_MYSQL_TRAITS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/details/config.hxx> // ODB_CXX11 | #include <odb/details/config.hxx> // ODB_CXX11 | |||
#include <string> | #include <string> | |||
skipping to change at line 413 | skipping to change at line 413 | |||
string_value_traits | string_value_traits | |||
{ | { | |||
}; | }; | |||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_set>: | struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_set>: | |||
string_value_traits | string_value_traits | |||
{ | { | |||
}; | }; | |||
// const char* specialization | // char*/const char* specialization | |||
// | // | |||
// Specialization for const char* which only supports initialization | // Specialization for const char* which only supports initialization | |||
// of an image from the value but not the other way around. This way | // of an image from the value but not the other way around. This way | |||
// we can pass such values to the queries. | // we can pass such values to the queries. | |||
// | // | |||
class LIBODB_MYSQL_EXPORT c_string_value_traits | class LIBODB_MYSQL_EXPORT c_string_value_traits | |||
{ | { | |||
public: | public: | |||
typedef const char* value_type; | typedef const char* value_type; | |||
typedef const char* query_type; | ||||
typedef details::buffer image_type; | typedef details::buffer image_type; | |||
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 char*); | const char*); | |||
}; | }; | |||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<char*, id_string>: | ||||
c_string_value_traits {}; | ||||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<char*, id_decimal>: | ||||
c_string_value_traits {}; | ||||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<char*, id_enum>: | ||||
c_string_value_traits {}; | ||||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<char*, id_set>: | ||||
c_string_value_traits {}; | ||||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_string> : | struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_string> : | |||
c_string_value_traits | c_string_value_traits {}; | |||
{ | ||||
}; | ||||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_decimal >: | struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_decimal >: | |||
c_string_value_traits | c_string_value_traits {}; | |||
{ | ||||
}; | ||||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_enum>: | struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_enum>: | |||
c_string_value_traits | c_string_value_traits {}; | |||
{ | ||||
}; | ||||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_set>: | struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_set>: | |||
c_string_value_traits | c_string_value_traits {}; | |||
// char[N] specializations. | ||||
// | ||||
struct LIBODB_MYSQL_EXPORT c_array_value_traits_base | ||||
{ | { | |||
static void | ||||
set_value (char* const& v, | ||||
const details::buffer& b, | ||||
std::size_t n, | ||||
bool is_null, | ||||
std::size_t N); | ||||
static void | ||||
set_image (details::buffer& b, | ||||
std::size_t& n, | ||||
bool& is_null, | ||||
const char* v, | ||||
std::size_t N); | ||||
}; | }; | |||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<char[N], id_string>: c_string_value_traits | struct c_array_value_traits | |||
{ | { | |||
typedef char* value_type; | ||||
typedef char query_type[N]; | ||||
typedef details::buffer image_type; | ||||
static void | ||||
set_value (char* const& v, | ||||
const details::buffer& b, | ||||
std::size_t n, | ||||
bool is_null) | ||||
{ | ||||
c_array_value_traits_base::set_value (v, b, n, is_null, N); | ||||
} | ||||
static void | ||||
set_image (details::buffer& b, | ||||
std::size_t& n, | ||||
bool& is_null, | ||||
const char* v) | ||||
{ | ||||
c_array_value_traits_base::set_image (b, n, is_null, v, N); | ||||
} | ||||
}; | }; | |||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<const char[N], id_string>: | struct default_value_traits<char[N], id_string>: c_array_value_traits<N | |||
c_string_value_traits | > | |||
{ | {}; | |||
}; | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<char[N], id_decimal>: c_string_value_traits | struct default_value_traits<char[N], id_decimal>: c_array_value_traits< | |||
{ | N> | |||
}; | {}; | |||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<const char[N], id_decimal>: | struct default_value_traits<char[N], id_enum>: c_array_value_traits<N> | |||
c_string_value_traits | {}; | |||
{ | ||||
}; | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<char[N], id_enum>: c_string_value_traits | struct default_value_traits<char[N], id_set>: c_array_value_traits<N> | |||
{ | {}; | |||
}; | ||||
// std::array<char, N> (string) specialization. | ||||
// | ||||
#ifdef ODB_CXX11 | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<const char[N], id_enum>: c_string_value_tra its | struct std_array_value_traits | |||
{ | { | |||
typedef std::array<char, N> value_type; | ||||
typedef std::array<char, N> 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) | ||||
{ | ||||
c_array_value_traits_base::set_value (v.data (), b, n, is_null, N); | ||||
} | ||||
static void | ||||
set_image (details::buffer& b, | ||||
std::size_t& n, | ||||
bool& is_null, | ||||
const value_type& v) | ||||
{ | ||||
c_array_value_traits_base::set_image (b, n, is_null, v.data (), N); | ||||
} | ||||
}; | }; | |||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<char[N], id_set>: c_string_value_traits | struct default_value_traits<std::array<char, N>, id_string>: | |||
{ | std_array_value_traits<N> {}; | |||
}; | ||||
template <std::size_t N> | ||||
struct default_value_traits<std::array<char, N>, id_decimal>: | ||||
std_array_value_traits<N> {}; | ||||
template <std::size_t N> | ||||
struct default_value_traits<std::array<char, N>, id_enum>: | ||||
std_array_value_traits<N> {}; | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<const char[N], id_set>: c_string_value_trai | struct default_value_traits<std::array<char, N>, id_set>: | |||
ts | std_array_value_traits<N> {}; | |||
#endif | ||||
// char specialization. | ||||
// | ||||
struct LIBODB_MYSQL_EXPORT char_value_traits | ||||
{ | { | |||
typedef char value_type; | ||||
typedef char query_type; | ||||
typedef details::buffer image_type; | ||||
static void | ||||
set_value (char& v, | ||||
const details::buffer& b, | ||||
std::size_t n, | ||||
bool is_null) | ||||
{ | ||||
c_array_value_traits_base::set_value (&v, b, n, is_null, 1); | ||||
} | ||||
static void | ||||
set_image (details::buffer& b, | ||||
std::size_t& n, | ||||
bool& is_null, | ||||
char v) | ||||
{ | ||||
c_array_value_traits_base::set_image (b, n, is_null, &v, 1); | ||||
} | ||||
}; | }; | |||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<char, id_string>: | ||||
char_value_traits {}; | ||||
template <> | ||||
struct LIBODB_MYSQL_EXPORT default_value_traits<char, id_enum>: | ||||
char_value_traits {}; | ||||
// std::vector<char> (buffer) specialization. | // std::vector<char> (buffer) specialization. | |||
// | // | |||
template <> | template <> | |||
struct LIBODB_MYSQL_EXPORT default_value_traits<std::vector<char>, id_b lob> | struct LIBODB_MYSQL_EXPORT default_value_traits<std::vector<char>, id_b lob> | |||
{ | { | |||
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 569 | skipping to change at line 676 | |||
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 char query_type[N]; | |||
typedef details::buffer image_type; | typedef details::buffer image_type; | |||
static void | static void | |||
set_value (char* const& v, | set_value (char* const& v, | |||
const details::buffer& b, | const details::buffer& b, | |||
std::size_t n, | std::size_t n, | |||
bool is_null) | bool is_null) | |||
{ | { | |||
if (!is_null) | if (!is_null) | |||
std::memcpy (v, b.data (), (n < N ? n : N)); | std::memcpy (v, b.data (), (n < N ? n : N)); | |||
skipping to change at line 607 | skipping to change at line 714 | |||
} | } | |||
}; | }; | |||
// 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 unsigned char query_type[N]; | |||
typedef details::buffer image_type; | typedef details::buffer image_type; | |||
static void | static void | |||
set_value (unsigned char* const& v, | set_value (unsigned char* const& v, | |||
const details::buffer& b, | const details::buffer& b, | |||
std::size_t n, | std::size_t n, | |||
bool is_null) | bool is_null) | |||
{ | { | |||
if (!is_null) | if (!is_null) | |||
std::memcpy (v, b.data (), (n < N ? n : N)); | std::memcpy (v, b.data (), (n < N ? n : N)); | |||
skipping to change at line 819 | skipping to change at line 926 | |||
// String types. | // 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_string; | static const database_type_id db_type_id = id_string; | |||
}; | }; | |||
template <> | template <> | |||
struct default_type_traits<char*> | ||||
{ | ||||
static const database_type_id db_type_id = id_string; | ||||
}; | ||||
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> | 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_string; | static const database_type_id db_type_id = id_string; | |||
}; | }; | |||
#ifdef ODB_CXX11 | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_type_traits<const char[N]> | struct default_type_traits<std::array<char, N> > | |||
{ | ||||
static const database_type_id db_type_id = id_string; | ||||
}; | ||||
#endif | ||||
template <> | ||||
struct default_type_traits<char> | ||||
{ | { | |||
static const database_type_id db_type_id = id_string; | static const database_type_id db_type_id = id_string; | |||
}; | }; | |||
// Binary types. | // Binary types. | |||
// | // | |||
template <> | template <std::size_t N> | |||
struct default_type_traits<std::vector<char> > | struct default_type_traits<unsigned char[N]> | |||
{ | { | |||
static const database_type_id db_type_id = id_blob; | static const database_type_id db_type_id = id_blob; | |||
}; | }; | |||
template <> | template <> | |||
struct default_type_traits<std::vector<unsigned char> > | struct default_type_traits<std::vector<char> > | |||
{ | { | |||
static const database_type_id db_type_id = id_blob; | static const database_type_id db_type_id = id_blob; | |||
}; | }; | |||
#ifdef ODB_CXX11 | template <> | |||
template <std::size_t N> | struct default_type_traits<std::vector<unsigned char> > | |||
struct default_type_traits<std::array<char, N> > | ||||
{ | { | |||
static const database_type_id db_type_id = id_blob; | static const database_type_id db_type_id = id_blob; | |||
}; | }; | |||
#ifdef ODB_CXX11 | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_type_traits<std::array<unsigned char, N> > | struct default_type_traits<std::array<unsigned char, N> > | |||
{ | { | |||
static const database_type_id db_type_id = id_blob; | static const database_type_id db_type_id = id_blob; | |||
}; | }; | |||
#endif | #endif | |||
} | } | |||
} | } | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
End of changes. 31 change blocks. | ||||
43 lines changed or deleted | 165 lines changed or added | |||
transaction-impl.hxx | transaction-impl.hxx | |||
---|---|---|---|---|
// file : odb/mysql/transaction-impl.hxx | // file : odb/mysql/transaction-impl.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_TRANSACTION_IMPL_HXX | #ifndef ODB_MYSQL_TRANSACTION_IMPL_HXX | |||
#define ODB_MYSQL_TRANSACTION_IMPL_HXX | #define ODB_MYSQL_TRANSACTION_IMPL_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/transaction.hxx> | #include <odb/transaction.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
transaction-impl.ixx | transaction-impl.ixx | |||
---|---|---|---|---|
// file : odb/mysql/transaction-impl.ixx | // file : odb/mysql/transaction-impl.ixx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
inline transaction_impl::connection_type& transaction_impl:: | inline transaction_impl::connection_type& transaction_impl:: | |||
connection () | connection () | |||
{ | { | |||
return *connection_; | return *connection_; | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
transaction.hxx | transaction.hxx | |||
---|---|---|---|---|
// file : odb/mysql/transaction.hxx | // file : odb/mysql/transaction.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_TRANSACTION_HXX | #ifndef ODB_MYSQL_TRANSACTION_HXX | |||
#define ODB_MYSQL_TRANSACTION_HXX | #define ODB_MYSQL_TRANSACTION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/transaction.hxx> | #include <odb/transaction.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
transaction.ixx | transaction.ixx | |||
---|---|---|---|---|
// file : odb/mysql/transaction.ixx | // file : odb/mysql/transaction.ixx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <odb/mysql/database.hxx> | #include <odb/mysql/database.hxx> | |||
#include <odb/mysql/transaction-impl.hxx> | #include <odb/mysql/transaction-impl.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
inline transaction:: | inline transaction:: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
version.hxx | version.hxx | |||
---|---|---|---|---|
// file : odb/mysql/version.hxx | // file : odb/mysql/version.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_VERSION_HXX | #ifndef ODB_MYSQL_VERSION_HXX | |||
#define ODB_MYSQL_VERSION_HXX | #define ODB_MYSQL_VERSION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/mysql/details/config.hxx> | #include <odb/mysql/details/config.hxx> | |||
#ifdef LIBODB_MYSQL_INCLUDE_SHORT | #ifdef LIBODB_MYSQL_INCLUDE_SHORT | |||
skipping to change at line 39 | skipping to change at line 39 | |||
// Version AABBCCDD | // Version AABBCCDD | |||
// 2.0.0 02000000 | // 2.0.0 02000000 | |||
// 2.1.0 02010000 | // 2.1.0 02010000 | |||
// 2.1.1 02010100 | // 2.1.1 02010100 | |||
// 2.2.0.a1 02019901 | // 2.2.0.a1 02019901 | |||
// 3.0.0.b2 02999952 | // 3.0.0.b2 02999952 | |||
// | // | |||
// Check that we have compatible ODB version. | // Check that we have compatible ODB version. | |||
// | // | |||
#if ODB_VERSION != 20100 | #if ODB_VERSION != 20200 | |||
# error incompatible odb interface version detected | # error incompatible odb interface version detected | |||
#endif | #endif | |||
// Check that we have a compatible MySQL version (5.0.3 or later). | // Check that we have a compatible MySQL version (5.0.3 or later). | |||
// | // | |||
#if !defined(MYSQL_VERSION_ID) || MYSQL_VERSION_ID < 50003 | #if !defined(MYSQL_VERSION_ID) || MYSQL_VERSION_ID < 50003 | |||
# error incompatible MySQL version detected | # error incompatible MySQL version detected | |||
#endif | #endif | |||
// libodb-mysql version: odb interface version plus the bugfix | // libodb-mysql version: odb interface version plus the bugfix | |||
// version. | // version. | |||
// | // | |||
#define LIBODB_MYSQL_VERSION 2010100 | #define LIBODB_MYSQL_VERSION 2020000 | |||
#define LIBODB_MYSQL_VERSION_STR "2.1.1" | #define LIBODB_MYSQL_VERSION_STR "2.2.0" | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_MYSQL_VERSION_HXX | #endif // ODB_MYSQL_VERSION_HXX | |||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added | |||
view-result.hxx | view-result.hxx | |||
---|---|---|---|---|
// file : odb/mysql/view-result.hxx | // file : odb/mysql/view-result.hxx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_VIEW_RESULT_HXX | #ifndef ODB_MYSQL_VIEW_RESULT_HXX | |||
#define ODB_MYSQL_VIEW_RESULT_HXX | #define ODB_MYSQL_VIEW_RESULT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/view-result.hxx> | #include <odb/view-result.hxx> | |||
#include <odb/details/shared-ptr.hxx> | #include <odb/details/shared-ptr.hxx> | |||
#include <odb/mysql/version.hxx> | #include <odb/mysql/version.hxx> | |||
#include <odb/mysql/forward.hxx> // query, view_statements | #include <odb/mysql/forward.hxx> // query_base, view_statements | |||
#include <odb/mysql/statement.hxx> | #include <odb/mysql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class view_result_impl: public odb::view_result_impl<T> | class view_result_impl: public odb::view_result_impl<T> | |||
{ | { | |||
public: | public: | |||
typedef odb::view_result_impl<T> base_type; | typedef odb::view_result_impl<T> base_type; | |||
typedef typename base_type::view_type view_type; | typedef typename base_type::view_type view_type; | |||
typedef typename base_type::view_traits view_traits; | ||||
typedef typename base_type::pointer_type pointer_type; | typedef typename base_type::pointer_type pointer_type; | |||
typedef view_traits_impl<view_type, id_mysql> view_traits; | ||||
typedef typename base_type::pointer_traits pointer_traits; | typedef typename base_type::pointer_traits pointer_traits; | |||
typedef view_statements<view_type> statements_type; | typedef view_statements<view_type> statements_type; | |||
virtual | virtual | |||
~view_result_impl (); | ~view_result_impl (); | |||
view_result_impl (const query&, | view_result_impl (const query_base&, | |||
details::shared_ptr<select_statement>, | details::shared_ptr<select_statement>, | |||
statements_type&); | statements_type&); | |||
virtual void | virtual void | |||
load (view_type&); | load (view_type&); | |||
virtual void | virtual void | |||
next (); | next (); | |||
virtual void | virtual void | |||
cache (); | cache (); | |||
virtual std::size_t | virtual std::size_t | |||
size (); | size (); | |||
virtual void | ||||
invalidate (); | ||||
using base_type::current; | using base_type::current; | |||
private: | private: | |||
void | void | |||
fetch (); | fetch (); | |||
private: | private: | |||
details::shared_ptr<select_statement> statement_; | details::shared_ptr<select_statement> statement_; | |||
statements_type& statements_; | statements_type& statements_; | |||
std::size_t count_; | std::size_t count_; | |||
End of changes. 6 change blocks. | ||||
5 lines changed or deleted | 8 lines changed or added | |||
view-result.txx | view-result.txx | |||
---|---|---|---|---|
// file : odb/mysql/view-result.txx | // file : odb/mysql/view-result.txx | |||
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <odb/callback.hxx> | #include <odb/callback.hxx> | |||
#include <odb/exceptions.hxx> | #include <odb/exceptions.hxx> | |||
#include <odb/mysql/view-statements.hxx> | #include <odb/mysql/view-statements.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
view_result_impl<T>:: | view_result_impl<T>:: | |||
~view_result_impl () | ~view_result_impl () | |||
{ | { | |||
if (!this->end_) | if (!this->end_) | |||
statement_->free_result (); | statement_->free_result (); | |||
} | } | |||
template <typename T> | template <typename T> | |||
void view_result_impl<T>:: | ||||
invalidate () | ||||
{ | ||||
if (!this->end_) | ||||
{ | ||||
statement_->free_result (); | ||||
this->end_ = true; | ||||
} | ||||
statement_.reset (); | ||||
} | ||||
template <typename T> | ||||
view_result_impl<T>:: | view_result_impl<T>:: | |||
view_result_impl (const query&, | view_result_impl (const query_base&, | |||
details::shared_ptr<select_statement> statement, | details::shared_ptr<select_statement> statement, | |||
statements_type& statements) | statements_type& statements) | |||
: base_type (statements.connection ().database ()), | : base_type (statements.connection ()), | |||
statement_ (statement), | statement_ (statement), | |||
statements_ (statements), | statements_ (statements), | |||
count_ (0) | count_ (0) | |||
{ | { | |||
} | } | |||
template <typename T> | template <typename T> | |||
void view_result_impl<T>:: | void view_result_impl<T>:: | |||
load (view_type& view) | load (view_type& view) | |||
{ | { | |||
if (count_ > statement_->fetched ()) | if (count_ > statement_->fetched ()) | |||
fetch (); | fetch (); | |||
odb::database& db (this->database ()); | view_traits::callback (this->db_, view, callback_event::pre_load); | |||
view_traits::init (view, statements_.image (), &this->db_); | ||||
view_traits::callback (db, view, callback_event::pre_load); | view_traits::callback (this->db_, view, callback_event::post_load); | |||
view_traits::init (view, statements_.image (), &db); | ||||
view_traits::callback (db, view, callback_event::post_load); | ||||
} | } | |||
template <typename T> | template <typename T> | |||
void view_result_impl<T>:: | void view_result_impl<T>:: | |||
next () | next () | |||
{ | { | |||
this->current (pointer_type ()); | this->current (pointer_type ()); | |||
if (this->end_) | if (this->end_) | |||
return; | return; | |||
End of changes. 5 change blocks. | ||||
8 lines changed or deleted | 19 lines changed or added | |||
view-statements.hxx | view-statements.hxx | |||
---|---|---|---|---|
// file : odb/mysql/view-statements.hxx | // file : odb/mysql/view-statements.hxx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#ifndef ODB_MYSQL_VIEW_STATEMENTS_HXX | #ifndef ODB_MYSQL_VIEW_STATEMENTS_HXX | |||
#define ODB_MYSQL_VIEW_STATEMENTS_HXX | #define ODB_MYSQL_VIEW_STATEMENTS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
skipping to change at line 29 | skipping to change at line 29 | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
class view_statements: public statements_base | class view_statements: public statements_base | |||
{ | { | |||
public: | public: | |||
typedef T view_type; | typedef T view_type; | |||
typedef odb::view_traits<view_type> view_traits; | typedef view_traits_impl<view_type, id_mysql> view_traits; | |||
typedef typename view_traits::pointer_type pointer_type; | typedef typename view_traits::pointer_type pointer_type; | |||
typedef typename view_traits::image_type image_type; | typedef typename view_traits::image_type image_type; | |||
public: | public: | |||
view_statements (connection_type&); | view_statements (connection_type&); | |||
virtual | virtual | |||
~view_statements (); | ~view_statements (); | |||
// View image. | // View image. | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
view-statements.txx | view-statements.txx | |||
---|---|---|---|---|
// file : odb/mysql/view-statements.txx | // file : odb/mysql/view-statements.txx | |||
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC | // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC | |||
// license : GNU GPL v2; see accompanying LICENSE file | // license : GNU GPL v2; see accompanying LICENSE file | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <cstring> // std::memset | #include <cstring> // std::memset | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace mysql | namespace mysql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||