auto-handle.hxx | auto-handle.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/auto-handle.hxx | // file : odb/pgsql/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_PGSQL_AUTO_HANDLE_HXX | #ifndef ODB_PGSQL_AUTO_HANDLE_HXX | |||
#define ODB_PGSQL_AUTO_HANDLE_HXX | #define ODB_PGSQL_AUTO_HANDLE_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/pgsql-fwd.hxx> // PGconn, PGresult | #include <odb/pgsql/pgsql-fwd.hxx> // PGconn, PGresult | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
binding.hxx | binding.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/binding.hxx | // file : odb/pgsql/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_PGSQL_BINDING_HXX | #ifndef ODB_PGSQL_BINDING_HXX | |||
#define ODB_PGSQL_BINDING_HXX | #define ODB_PGSQL_BINDING_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
config.h | config.h | |||
---|---|---|---|---|
/* odb/pgsql/details/config.h. Generated from config.h.in by configure. * / | /* odb/pgsql/details/config.h. Generated from config.h.in by configure. * / | |||
/* file : odb/pgsql/details/config.h.in | /* file : odb/pgsql/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_PGSQL_DETAILS_CONFIG_H | #ifndef ODB_PGSQL_DETAILS_CONFIG_H | |||
#define ODB_PGSQL_DETAILS_CONFIG_H | #define ODB_PGSQL_DETAILS_CONFIG_H | |||
/* #undef LIBODB_PGSQL_STATIC_LIB */ | /* #undef LIBODB_PGSQL_STATIC_LIB */ | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
config.hxx | config.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/details/config.hxx | // file : odb/pgsql/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_PGSQL_DETAILS_CONFIG_HXX | #ifndef ODB_PGSQL_DETAILS_CONFIG_HXX | |||
#define ODB_PGSQL_DETAILS_CONFIG_HXX | #define ODB_PGSQL_DETAILS_CONFIG_HXX | |||
// no pre | // no pre | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
#elif defined(ODB_COMPILER) | #elif defined(ODB_COMPILER) | |||
# error libodb-pgsql header included in odb-compiled header | # error libodb-pgsql header included in odb-compiled header | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
connection-factory.hxx | connection-factory.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/connection-factory.hxx | // file : odb/pgsql/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_PGSQL_CONNECTION_FACTORY_HXX | #ifndef ODB_PGSQL_CONNECTION_FACTORY_HXX | |||
#define ODB_PGSQL_CONNECTION_FACTORY_HXX | #define ODB_PGSQL_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/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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | #include <odb/pgsql/forward.hxx> | |||
#include <odb/pgsql/connection.hxx> | #include <odb/pgsql/connection.hxx> | |||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
skipping to change at line 91 | skipping to change at line 92 | |||
// | // | |||
connection_pool_factory (std::size_t max_connections = 0, | connection_pool_factory (std::size_t max_connections = 0, | |||
std::size_t min_connections = 0) | std::size_t min_connections = 0) | |||
: max_ (max_connections), | : max_ (max_connections), | |||
min_ (min_connections), | min_ (min_connections), | |||
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/pgsql/connection.hxx | // file : odb/pgsql/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_PGSQL_CONNECTION_HXX | #ifndef ODB_PGSQL_CONNECTION_HXX | |||
#define ODB_PGSQL_CONNECTION_HXX | #define ODB_PGSQL_CONNECTION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/forward.hxx> | ||||
#include <odb/connection.hxx> | #include <odb/connection.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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | #include <odb/pgsql/forward.hxx> | |||
#include <odb/pgsql/query.hxx> | ||||
#include <odb/pgsql/tracer.hxx> | #include <odb/pgsql/tracer.hxx> | |||
#include <odb/pgsql/transaction-impl.hxx> | #include <odb/pgsql/transaction-impl.hxx> | |||
#include <odb/pgsql/auto-handle.hxx> | #include <odb/pgsql/auto-handle.hxx> | |||
#include <odb/pgsql/pgsql-fwd.hxx> // PGconn | #include <odb/pgsql/pgsql-fwd.hxx> // PGconn | |||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
skipping to change at line 62 | skipping to change at line 62 | |||
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 pgsql::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 pgsql::tracer tracer_type; | typedef pgsql::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 116 | skipping to change at line 135 | |||
private: | private: | |||
connection (const connection&); | connection (const connection&); | |||
connection& operator= (const connection&); | connection& operator= (const connection&); | |||
private: | private: | |||
void | void | |||
init (); | init (); | |||
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_; | |||
auto_handle<PGconn> handle_; | auto_handle<PGconn> handle_; | |||
bool failed_; | bool failed_; | |||
// Keep statement_cache_ after handle_ so that it is destroyed before | // Keep statement_cache_ after handle_ so that it is destroyed before | |||
// the connection is closed. | // the connection is closed. | |||
// | // | |||
details::unique_ptr<statement_cache_type> statement_cache_; | details::unique_ptr<statement_cache_type> statement_cache_; | |||
}; | }; | |||
} | } | |||
} | } | |||
#include <odb/pgsql/connection.ixx> | ||||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_PGSQL_CONNECTION_HXX | #endif // ODB_PGSQL_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/pgsql/container-statements.hxx | // file : odb/pgsql/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_PGSQL_CONTAINER_STATEMENTS_HXX | #ifndef ODB_PGSQL_CONTAINER_STATEMENTS_HXX | |||
#define ODB_PGSQL_CONTAINER_STATEMENTS_HXX | #define ODB_PGSQL_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> | |||
#include <odb/traits.hxx> | #include <odb/traits.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/binding.hxx> | #include <odb/pgsql/binding.hxx> | |||
#include <odb/pgsql/statement.hxx> | #include <odb/pgsql/statement.hxx> | |||
#include <odb/pgsql/pgsql-fwd.hxx> // Oid | #include <odb/pgsql/pgsql-fwd.hxx> // Oid | |||
#include <odb/pgsql/pgsql-oid.hxx> | ||||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
class connection; | class connection; | |||
// 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 pgsql::insert_statement insert_statement_type; | typedef pgsql::insert_statement insert_statement_type; | |||
typedef pgsql::select_statement select_statement_type; | typedef pgsql::select_statement select_statement_type; | |||
typedef pgsql::delete_statement delete_statement_type; | typedef pgsql::delete_statement delete_statement_type; | |||
typedef pgsql::connection connection_type; | typedef pgsql::connection connection_type; | |||
container_statements (connection_type&); | container_statements (connection_type&, | |||
binding& id, | ||||
native_binding& idn, | ||||
const Oid* idt); | ||||
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. | 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 | 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. | |||
{ | // | |||
cond_id_binding_version_ = v; | ||||
} | ||||
binding& | insert_statement_type& | |||
cond_image_binding () | insert_statement () | |||
{ | { | |||
return cond_image_binding_; | if (insert_ == 0) | |||
} | insert_.reset ( | |||
new (details::shared) insert_statement_type ( | ||||
conn_, | ||||
insert_name_, | ||||
insert_text_, | ||||
insert_types_, | ||||
insert_count_, | ||||
insert_image_binding_, | ||||
insert_image_native_binding_, | ||||
false, | ||||
false)); | ||||
native_binding& | return *insert_; | |||
cond_image_native_binding () | ||||
{ | ||||
return cond_image_native_binding_; | ||||
} | } | |||
// Data image. | select_statement_type& | |||
// | select_statement () | |||
data_image_type& | ||||
data_image () | ||||
{ | { | |||
return data_image_; | if (select_ == 0) | |||
select_.reset ( | ||||
new (details::shared) select_statement_type ( | ||||
conn_, | ||||
select_name_, | ||||
select_text_, | ||||
id_types_, | ||||
id_binding_.count, | ||||
id_binding_, | ||||
id_native_binding_, | ||||
select_image_binding_, | ||||
false)); | ||||
return *select_; | ||||
} | } | |||
std::size_t | delete_statement_type& | |||
data_image_version () const | delete_statement () | |||
{ | { | |||
return data_image_version_; | if (delete_ == 0) | |||
delete_.reset ( | ||||
new (details::shared) delete_statement_type ( | ||||
conn_, | ||||
delete_name_, | ||||
delete_text_, | ||||
id_types_, | ||||
id_binding_.count, | ||||
id_binding_, | ||||
id_native_binding_, | ||||
false)); | ||||
return *delete_; | ||||
} | } | |||
void | private: | |||
data_image_version (std::size_t v) | container_statements (const container_statements&); | |||
container_statements& operator= (const container_statements&); | ||||
protected: | ||||
connection_type& conn_; | ||||
binding& id_binding_; | ||||
native_binding& id_native_binding_; | ||||
const Oid* id_types_; | ||||
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_; | ||||
native_binding insert_image_native_binding_; | ||||
binding select_image_binding_; | ||||
bool* select_image_truncated_; | ||||
const char* insert_name_; | ||||
const char* insert_text_; | ||||
const Oid* insert_types_; | ||||
std::size_t insert_count_; | ||||
const char* select_name_; | ||||
const char* select_text_; | ||||
const char* delete_name_; | ||||
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 pgsql::update_statement update_statement_type; | ||||
typedef pgsql::delete_statement delete_statement_type; | ||||
typedef pgsql::connection connection_type; | ||||
smart_container_statements (connection_type&, | ||||
binding& id, | ||||
native_binding& idn, | ||||
const Oid* idt); | ||||
// 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 () | ||||
{ | { | |||
data_image_version_ = v; | return cond_image_; | |||
} | } | |||
std::size_t | bind* | |||
data_id_binding_version () const | cond_bind () | |||
{ | { | |||
return data_id_binding_version_; | return cond_image_binding_.bind; | |||
} | } | |||
void | bool | |||
data_id_binding_version (std::size_t v) | cond_binding_test_version () const | |||
{ | { | |||
data_id_binding_version_ = v; | return cond_id_binding_version_ != this->id_binding_.version || | |||
cond_image_version_ != cond_image_.version || | ||||
cond_image_binding_.version == 0; | ||||
} | } | |||
binding& | void | |||
data_image_binding () | cond_binding_update_version () | |||
{ | { | |||
return data_image_binding_; | cond_id_binding_version_ = this->id_binding_.version; | |||
cond_image_version_ = cond_image_.version; | ||||
cond_image_binding_.version++; | ||||
} | } | |||
native_binding& | // Update image. The image is split as follows: value comes | |||
data_image_native_binding () | // from the data image, id comes as binding, and index/key | |||
// comes from the condition image. | ||||
// | ||||
bind* | ||||
update_bind () | ||||
{ | { | |||
return data_image_native_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; | ||||
} | } | |||
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_name_, | ||||
insert_one_text_, | ||||
insert_one_types_, | ||||
insert_one_count_, | ||||
data_image_binding_, | ||||
data_image_native_binding_, | ||||
false, | ||||
false)); | ||||
} | ||||
return *insert_one_; | ||||
} | ||||
select_statement_type& | ||||
select_all_statement () | ||||
{ | { | |||
if (select_all_ == 0) | if (this->delete_ == 0) | |||
{ | this->delete_.reset ( | |||
select_all_.reset ( | new (details::shared) delete_statement_type ( | |||
new (details::shared) select_statement_type ( | this->conn_, | |||
conn_, | this->delete_name_, | |||
select_all_name_, | this->delete_text_, | |||
select_all_text_, | delete_types_, | |||
select_all_types_, | delete_count_, | |||
select_all_count_, | ||||
cond_image_binding_, | cond_image_binding_, | |||
cond_image_native_binding_, | cond_image_native_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) | |||
{ | update_.reset ( | |||
delete_all_.reset ( | new (details::shared) update_statement_type ( | |||
new (details::shared) delete_statement_type ( | this->conn_, | |||
conn_, | update_name_, | |||
delete_all_name_, | update_text_, | |||
delete_all_text_, | update_types_, | |||
delete_all_types_, | update_count_, | |||
delete_all_count_, | update_image_binding_, | |||
cond_image_binding_, | update_image_native_binding_, | |||
cond_image_native_binding_, | ||||
false)); | 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_; | |||
native_binding cond_image_native_binding_; | native_binding cond_image_native_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_; | native_binding update_image_native_binding_; | |||
native_binding data_image_native_binding_; | ||||
const char* update_name_; | ||||
const char* update_text_; | ||||
const Oid* update_types_; | ||||
std::size_t update_count_; | ||||
// Skips the id from data_image_binding. | const Oid* delete_types_; | |||
// | std::size_t delete_count_; | |||
binding select_image_binding_; | ||||
bool* select_image_truncated_; | ||||
const char* insert_one_name_; | details::shared_ptr<update_statement_type> update_; | |||
const char* insert_one_text_; | ||||
const Oid* insert_one_types_; | ||||
std::size_t insert_one_count_; | ||||
const char* select_all_name_; | ||||
const char* select_all_text_; | ||||
const Oid* select_all_types_; | ||||
std::size_t select_all_count_; | ||||
const char* delete_all_name_; | ||||
const char* delete_all_text_; | ||||
const Oid* delete_all_types_; | ||||
std::size_t delete_all_count_; | ||||
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 pgsql::connection connection_type; | typedef pgsql::connection connection_type; | |||
container_statements_impl (connection_type&); | container_statements_impl (connection_type&, | |||
binding&, | ||||
native_binding&, | ||||
const Oid*); | ||||
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: | |||
bind cond_image_bind_[traits::cond_column_count]; | ||||
char* cond_image_values_[traits::cond_column_count]; | ||||
int cond_image_lengths_[traits::cond_column_count]; | ||||
int cond_image_formats_[traits::cond_column_count]; | ||||
bind data_image_bind_[traits::data_column_count]; | bind data_image_bind_[traits::data_column_count]; | |||
char* data_image_values_[traits::data_column_count]; | char* data_image_values_[traits::data_column_count]; | |||
int data_image_lengths_[traits::data_column_count]; | int data_image_lengths_[traits::data_column_count]; | |||
int data_image_formats_[traits::data_column_count]; | int data_image_formats_[traits::data_column_count]; | |||
bool select_image_truncated_array_[traits::data_column_count - | 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 pgsql::connection connection_type; | ||||
smart_container_statements_impl (connection_type&, | ||||
binding&, | ||||
native_binding&, | ||||
const Oid*); | ||||
private: | ||||
bind cond_image_bind_[traits::cond_column_count]; | ||||
char* cond_image_values_[traits::cond_column_count]; | ||||
int cond_image_lengths_[traits::cond_column_count]; | ||||
int cond_image_formats_[traits::cond_column_count]; | ||||
bind update_image_bind_[traits::value_column_count + | ||||
traits::cond_column_count]; | ||||
char* update_image_values_[traits::value_column_count + | ||||
traits::cond_column_count]; | ||||
int update_image_lengths_[traits::value_column_count + | ||||
traits::cond_column_count]; | ||||
int update_image_formats_[traits::value_column_count + | ||||
traits::cond_column_count]; | ||||
}; | ||||
} | } | |||
} | } | |||
#include <odb/pgsql/container-statements.txx> | #include <odb/pgsql/container-statements.txx> | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_PGSQL_CONTAINER_STATEMENTS_HXX | #endif // ODB_PGSQL_CONTAINER_STATEMENTS_HXX | |||
End of changes. 54 change blocks. | ||||
158 lines changed or deleted | 240 lines changed or added | |||
container-statements.txx | container-statements.txx | |||
---|---|---|---|---|
// file : odb/pgsql/container-statements.txx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
// 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, | ||||
native_binding& idn, | ||||
const Oid* idt) | ||||
: conn_ (conn), | : conn_ (conn), | |||
functions_ (this, | id_binding_ (id), | |||
&traits::insert_one, | id_native_binding_ (idn), | |||
&traits::load_all, | id_types_ (idt), | |||
&traits::delete_all), | functions_ (this), | |||
id_binding_ (0), | insert_image_binding_ (0, 0), // Initialized by impl | |||
cond_image_binding_ (0, 0), // Initialized by impl. | . | |||
cond_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. | insert_image_native_binding_ (0, 0, 0, 0), // Initialized by impl | |||
data_image_binding_ (0, 0), // Initialized by impl. | . | |||
data_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. | select_image_binding_ (0, 0) // Initialized by impl | |||
select_image_binding_ (0, 0) // Initialized by impl. | . | |||
{ | { | |||
cond_image_.version = 0; | functions_.insert_ = &traits::insert; | |||
cond_image_version_ = 0; | functions_.select_ = &traits::select; | |||
cond_id_binding_version_ = 0; | functions_.delete__ = &traits::delete_; | |||
data_image_.version = 0; | data_image_.version = 0; | |||
data_image_version_ = 0; | data_image_version_ = 0; | |||
data_id_binding_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, | ||||
native_binding& idn, | ||||
const Oid* idt) | ||||
: container_statements<T> (conn, id, idn, idt), | ||||
cond_image_binding_ (0, 0), // Initialized by imp | ||||
l. | ||||
cond_image_native_binding_ (0, 0, 0, 0), // Initialized by imp | ||||
l. | ||||
update_image_binding_ (0, 0), // Initialized by imp | ||||
l. | ||||
update_image_native_binding_ (0, 0, 0, 0) // Initialized by imp | ||||
l. | ||||
{ | ||||
this->functions_.update_ = &traits::update; | ||||
cond_image_.version = 0; | ||||
cond_image_version_ = 0; | ||||
cond_id_binding_version_ = 0; | ||||
update_id_binding_version_ = 0; | ||||
update_cond_image_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, | |||
: base (conn) | binding& id, | |||
native_binding& idn, | ||||
const Oid* idt) | ||||
: base (conn, id, idn, idt) | ||||
{ | { | |||
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; | |||
this->cond_image_native_binding_.values = cond_image_values_; | this->insert_image_native_binding_.values = data_image_values_; | |||
this->cond_image_native_binding_.lengths = cond_image_lengths_; | this->insert_image_native_binding_.lengths = data_image_lengths_; | |||
this->cond_image_native_binding_.formats = cond_image_formats_; | this->insert_image_native_binding_.formats = data_image_formats_; | |||
this->cond_image_native_binding_.count = traits::cond_column_count; | this->insert_image_native_binding_.count = traits::data_column_count; | |||
this->data_image_native_binding_.values = data_image_values_; | ||||
this->data_image_native_binding_.lengths = data_image_lengths_; | ||||
this->data_image_native_binding_.formats = data_image_formats_; | ||||
this->data_image_native_binding_.count = traits::data_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].truncated = | data_image_bind_[i + traits::id_column_count].truncated = | |||
select_image_truncated_array_ + i; | select_image_truncated_array_ + i; | |||
this->insert_one_name_ = traits::insert_one_name; | this->insert_name_ = traits::insert_name; | |||
this->insert_one_text_ = traits::insert_one_statement; | this->insert_text_ = traits::insert_statement; | |||
this->insert_one_types_ = traits::insert_one_types; | this->insert_types_ = traits::insert_types; | |||
this->insert_one_count_ = traits::data_column_count; | this->insert_count_ = traits::data_column_count; | |||
this->select_all_name_ = traits::select_all_name; | this->select_name_ = traits::select_name; | |||
this->select_all_text_ = traits::select_all_statement; | this->select_text_ = traits::select_statement; | |||
this->select_all_types_ = traits::select_all_types; | ||||
this->select_all_count_ = traits::cond_column_count; | this->delete_name_ = traits::delete_name; | |||
this->delete_text_ = traits::delete_statement; | ||||
this->delete_all_name_ = traits::delete_all_name; | } | |||
this->delete_all_text_ = traits::delete_all_statement; | ||||
this->delete_all_types_ = traits::delete_all_types; | // smart_container_statements_impl | |||
this->delete_all_count_ = traits::cond_column_count; | // | |||
template <typename T> | ||||
smart_container_statements_impl<T>:: | ||||
smart_container_statements_impl (connection_type& conn, | ||||
binding& id, | ||||
native_binding& idn, | ||||
const Oid* idt) | ||||
: container_statements_impl<T> (conn, id, idn, idt) | ||||
{ | ||||
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; | ||||
this->cond_image_native_binding_.values = cond_image_values_; | ||||
this->cond_image_native_binding_.lengths = cond_image_lengths_; | ||||
this->cond_image_native_binding_.formats = cond_image_formats_; | ||||
this->cond_image_native_binding_.count = traits::cond_column_count; | ||||
this->update_image_native_binding_.values = update_image_values_; | ||||
this->update_image_native_binding_.lengths = update_image_lengths_; | ||||
this->update_image_native_binding_.formats = update_image_formats_; | ||||
this->update_image_native_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_name_ = traits::update_name; | ||||
this->update_text_ = traits::update_statement; | ||||
this->update_types_ = traits::update_types; | ||||
this->update_count_ = traits::value_column_count + | ||||
traits::cond_column_count; | ||||
this->delete_types_ = traits::delete_types; | ||||
this->delete_count_ = traits::cond_column_count; | ||||
} | } | |||
} | } | |||
} | } | |||
End of changes. 11 change blocks. | ||||
47 lines changed or deleted | 112 lines changed or added | |||
conversion.hxx | conversion.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/details/conversion.hxx | // file : odb/pgsql/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_PGSQL_DETAILS_CONVERSION_HXX | #ifndef ODB_PGSQL_DETAILS_CONVERSION_HXX | |||
#define ODB_PGSQL_DETAILS_CONVERSION_HXX | #define ODB_PGSQL_DETAILS_CONVERSION_HXX | |||
#include <odb/pgsql/traits.hxx> | #include <odb/pgsql/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/pgsql/database.hxx | // file : odb/pgsql/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_PGSQL_DATABASE_HXX | #ifndef ODB_PGSQL_DATABASE_HXX | |||
#define ODB_PGSQL_DATABASE_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | #include <odb/pgsql/forward.hxx> | |||
#include <odb/pgsql/query.hxx> | ||||
#include <odb/pgsql/tracer.hxx> | #include <odb/pgsql/tracer.hxx> | |||
#include <odb/pgsql/connection.hxx> | #include <odb/pgsql/connection.hxx> | |||
#include <odb/pgsql/connection-factory.hxx> | #include <odb/pgsql/connection-factory.hxx> | |||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
skipping to change at line 83 | skipping to change at line 84 | |||
database (int& argc, | database (int& argc, | |||
char* argv[], | char* argv[], | |||
bool erase = false, | bool erase = false, | |||
const std::string& extra_conninfo = "", | const std::string& extra_conninfo = "", | |||
details::transfer_ptr<connection_factory> = | details::transfer_ptr<connection_factory> = | |||
details::transfer_ptr<connection_factory> ()); | details::transfer_ptr<connection_factory> ()); | |||
static void | static void | |||
print_usage (std::ostream&); | print_usage (std::ostream&); | |||
// 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 pgsql::query_base&); | ||||
template <typename T> | ||||
unsigned long long | ||||
erase_query (const odb::query_base&); | ||||
// Query API. | ||||
// | ||||
template <typename T> | ||||
result<T> | ||||
query (); | ||||
template <typename T> | ||||
result<T> | ||||
query (const char*); | ||||
template <typename T> | ||||
result<T> | ||||
query (const std::string&); | ||||
template <typename T> | ||||
result<T> | ||||
query (const pgsql::query_base&); | ||||
template <typename T> | ||||
result<T> | ||||
query (const odb::query_base&); | ||||
// 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 pgsql::query_base&); | ||||
template <typename T> | ||||
prepared_query<T> | ||||
prepare_query (const char* name, const odb::query_base&); | ||||
// Transactions. | // Transactions. | |||
// | // | |||
public: | public: | |||
virtual transaction_impl* | virtual transaction_impl* | |||
begin (); | begin (); | |||
public: | public: | |||
connection_ptr | connection_ptr | |||
connection (); | connection (); | |||
public: | public: | |||
// Database id constant (useful for meta-programming). | ||||
// | ||||
static const odb::database_id database_id = id_pgsql; | ||||
public: | ||||
virtual | virtual | |||
~database (); | ~database (); | |||
protected: | protected: | |||
virtual odb::connection* | virtual odb::connection* | |||
connection_ (); | connection_ (); | |||
// SQL statement tracing. | // SQL statement tracing. | |||
// | // | |||
public: | public: | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 226 lines changed or added | |||
database.ixx | database.ixx | |||
---|---|---|---|---|
// file : odb/pgsql/database.ixx | // file : odb/pgsql/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/pgsql/transaction.hxx> | ||||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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<pgsql::connection*> (connection_ ())); | static_cast<pgsql::connection*> (connection_ ())); | |||
} | } | |||
template <typename T> | ||||
inline typename object_traits<T>::id_type database:: | ||||
persist (T& obj) | ||||
{ | ||||
return persist_<T, id_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (id); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
load (const typename object_traits<T>::id_type& id, T& obj) | ||||
{ | ||||
return load_<T, id_pgsql> (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_pgsql> (id); | ||||
} | ||||
template <typename T> | ||||
inline bool database:: | ||||
find (const typename object_traits<T>::id_type& id, T& obj) | ||||
{ | ||||
return find_<T, id_pgsql> (id, obj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
reload (T& obj) | ||||
{ | ||||
reload_<T, id_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (pobj); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (const typename object_traits<T>::id_type& id) | ||||
{ | ||||
return erase_<T, id_pgsql> (id); | ||||
} | ||||
template <typename T> | ||||
inline void database:: | ||||
erase (T& obj) | ||||
{ | ||||
return erase_<T, id_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (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_pgsql> (pobj); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query () | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return erase_query<T> (pgsql::query_base ()); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const char* q) | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return erase_query<T> (pgsql::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> (pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline unsigned long long database:: | ||||
erase_query (const pgsql::query_base& q) | ||||
{ | ||||
// T is always object_type. | ||||
// | ||||
return object_traits_impl<T, id_pgsql>::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> (pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query () | ||||
{ | ||||
return query<T> (pgsql::query_base ()); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const char* q) | ||||
{ | ||||
return query<T> (pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const std::string& q) | ||||
{ | ||||
return query<T> (pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const pgsql::query_base& q) | ||||
{ | ||||
// T is always object_type. We also don't need to check for transacti | ||||
on | ||||
// here; object_traits::query () does this. | ||||
// | ||||
return query_<T, id_pgsql>::call (*this, q); | ||||
} | ||||
template <typename T> | ||||
inline result<T> database:: | ||||
query (const odb::query_base& q) | ||||
{ | ||||
// Translate to native query. | ||||
// | ||||
return query<T> (pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const char* q) | ||||
{ | ||||
return prepare_query<T> (n, pgsql::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, pgsql::query_base (q)); | ||||
} | ||||
template <typename T> | ||||
inline prepared_query<T> database:: | ||||
prepare_query (const char* n, const pgsql::query_base& q) | ||||
{ | ||||
// Throws if not in transaction. | ||||
// | ||||
pgsql::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, pgsql::query_base (q)); | ||||
} | ||||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 441 lines changed or added | |||
endian-traits.hxx | endian-traits.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/details/endian-traits.hxx | // file : odb/pgsql/details/endian-traits.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_PGSQL_DETAILS_ENDIAN_TRAITS_HXX | #ifndef ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX | |||
#define ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX | #define ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <algorithm> // std::reverse | #include <algorithm> // std::reverse | |||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
error.hxx | error.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/error.hxx | // file : odb/pgsql/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_PGSQL_ERROR_HXX | #ifndef ODB_PGSQL_ERROR_HXX | |||
#define ODB_PGSQL_ERROR_HXX | #define ODB_PGSQL_ERROR_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <libpq-fe.h> | #include <libpq-fe.h> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
error.ixx | error.ixx | |||
---|---|---|---|---|
// file : odb/pgsql/error.ixx | // file : odb/pgsql/error.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 pgsql | namespace pgsql | |||
{ | { | |||
bool | bool | |||
inline is_good_result (PGresult* r, ExecStatusType* s) | inline is_good_result (PGresult* r, ExecStatusType* s) | |||
{ | { | |||
if (r != 0) | if (r != 0) | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
exceptions.hxx | exceptions.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/exceptions.hxx | // file : odb/pgsql/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_PGSQL_EXCEPTIONS_HXX | #ifndef ODB_PGSQL_EXCEPTIONS_HXX | |||
#define ODB_PGSQL_EXCEPTIONS_HXX | #define ODB_PGSQL_EXCEPTIONS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <string> | #include <string> | |||
#include <odb/exceptions.hxx> | #include <odb/exceptions.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | ||||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
struct LIBODB_PGSQL_EXPORT database_exception: odb::database_exception | struct LIBODB_PGSQL_EXPORT database_exception: odb::database_exception | |||
{ | { | |||
database_exception (const std::string& message); | database_exception (const std::string& message); | |||
skipping to change at line 63 | skipping to change at line 63 | |||
{ | { | |||
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 pgsql::database_exception; | ||||
using pgsql::cli_exception; | ||||
} | ||||
} | } | |||
} | } | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_PGSQL_EXCEPTIONS_HXX | #endif // ODB_PGSQL_EXCEPTIONS_HXX | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 8 lines changed or added | |||
export.hxx | export.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/details/export.hxx | // file : odb/pgsql/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_PGSQL_DETAILS_EXPORT_HXX | #ifndef ODB_PGSQL_DETAILS_EXPORT_HXX | |||
#define ODB_PGSQL_DETAILS_EXPORT_HXX | #define ODB_PGSQL_DETAILS_EXPORT_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/pgsql/details/config.hxx> | #include <odb/pgsql/details/config.hxx> | |||
#ifdef LIBODB_PGSQL_STATIC_LIB | #ifdef LIBODB_PGSQL_STATIC_LIB | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
forward.hxx | forward.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/forward.hxx | // file : odb/pgsql/forward.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_PGSQL_FORWARD_HXX | #ifndef ODB_PGSQL_FORWARD_HXX | |||
#define ODB_PGSQL_FORWARD_HXX | #define ODB_PGSQL_FORWARD_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/forward.hxx> | #include <odb/forward.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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 pgsql::database; | ||||
using pgsql::connection; | ||||
using pgsql::connection_ptr; | ||||
using pgsql::transaction; | ||||
using pgsql::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<pgsql::connection> | struct counter_type<pgsql::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 | |||
no-id-object-result.hxx | no-id-object-result.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/no-id-object-result.hxx | // file : odb/pgsql/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_PGSQL_NO_ID_OBJECT_RESULT_HXX | #ifndef ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX | |||
#define ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> // query | #include <odb/pgsql/forward.hxx> // query_base | |||
#include <odb/pgsql/statement.hxx> | #include <odb/pgsql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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_pgsql> 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: | |||
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/pgsql/no-id-object-result.txx | // file : odb/pgsql/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/pgsql/no-id-object-statements.hxx> | #include <odb/pgsql/no-id-object-statements.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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) | |||
{ | { | |||
skipping to change at line 67 | skipping to change at line 80 | |||
if (im.version != statements_.select_image_version ()) | if (im.version != statements_.select_image_version ()) | |||
{ | { | |||
binding& b (statements_.select_image_binding ()); | binding& b (statements_.select_image_binding ()); | |||
object_traits::bind (b.bind, im, statement_select); | object_traits::bind (b.bind, im, statement_select); | |||
statements_.select_image_version (im.version); | statements_.select_image_version (im.version); | |||
b.version++; | b.version++; | |||
statement_->reload (); | statement_->reload (); | |||
} | } | |||
} | } | |||
odb::database& db (this->database ()); | object_traits::callback (this->db_, obj, callback_event::pre_load); | |||
object_traits::init (obj, im, &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, im, &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 (statement_->next ()) | if (statement_->next ()) | |||
count_++; | count_++; | |||
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/pgsql/no-id-object-statements.hxx | // file : odb/pgsql/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_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX | #ifndef ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX | |||
#define ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX | #define ODB_PGSQL_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_pgsql> 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 pgsql::insert_statement insert_statement_type; | typedef pgsql::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/pgsql/no-id-object-statements.txx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
// | // | |||
// no_id_object_statements | // no_id_object_statements | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
pgsql-fwd.hxx | pgsql-fwd.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/pgsql-fwd.hxx | // file : odb/pgsql/pgsql-fwd.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_PGSQL_PGSQL_FWD_HXX | #ifndef ODB_PGSQL_PGSQL_FWD_HXX | |||
#define ODB_PGSQL_PGSQL_FWD_HXX | #define ODB_PGSQL_PGSQL_FWD_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
// Forward declaration for some of the types defined in libpq-fe.h. This | // Forward declaration for some of the types defined in libpq-fe.h. This | |||
// allows us to avoid having to include libpq-fe.h in public headers. | // allows us to avoid having to include libpq-fe.h in public headers. | |||
// | // | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
pgsql-oid.hxx | pgsql-oid.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/pgsql-oid.hxx | // file : odb/pgsql/pgsql-oid.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 | |||
// Generated file of OIDs extracted from the PostgreSQL 8.4.8 source file | // Generated file of OIDs extracted from the PostgreSQL 8.4.8 source file | |||
// src/include/catalog/pg_type.h | // src/include/catalog/pg_type.h | |||
// | // | |||
#ifndef ODB_PGSQL_PGSQL_OID_HXX | #ifndef ODB_PGSQL_PGSQL_OID_HXX | |||
#define ODB_PGSQL_PGSQL_OID_HXX | #define ODB_PGSQL_PGSQL_OID_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
pgsql-types.hxx | pgsql-types.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/pgsql-types.hxx | // file : odb/pgsql/pgsql-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_PGSQL_PGSQL_TYPES_HXX | #ifndef ODB_PGSQL_PGSQL_TYPES_HXX | |||
#define ODB_PGSQL_PGSQL_TYPES_HXX | #define ODB_PGSQL_PGSQL_TYPES_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <cstddef> // std::size_t | #include <cstddef> // std::size_t | |||
#include <odb/pgsql/pgsql-fwd.hxx> // Oid | #include <odb/pgsql/pgsql-fwd.hxx> // Oid | |||
skipping to change at line 25 | skipping to change at line 25 | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
// The libpq result binding. This data structures is | // The libpq result binding. This data structures is | |||
// modelled after MYSQL_BIND from MySQL. | // modelled after MYSQL_BIND from MySQL. | |||
// | // | |||
struct bind | struct bind | |||
{ | { | |||
enum buffer_type | enum buffer_type | |||
{ | { | |||
boolean, // Buffer is a bool; size, capacity, truncated are unused . | boolean_, // Buffer is a bool; size, capacity, truncated are unused . | |||
smallint, // Buffer is short; size, capacity, truncated are unused. | smallint, // Buffer is short; size, capacity, truncated are unused. | |||
integer, // Buffer is int; size, capacity, truncated are unused. | integer, // Buffer is int; size, capacity, truncated are unused. | |||
bigint, // Buffer is long long; size, capacity, truncated are unu sed. | bigint, // Buffer is long long; size, capacity, truncated are unu sed. | |||
real, // Buffer is float; size, capacity, truncated are unused. | real, // Buffer is float; size, capacity, truncated are unused. | |||
double_, // Buffer is double; size, capacity, truncated are unused . | double_, // Buffer is double; size, capacity, truncated are unused . | |||
numeric, // Buffer is a char array. | numeric, // Buffer is a char array. | |||
date, // Buffer is int; size, capacity, truncated are unused. | date, // Buffer is int; size, capacity, truncated are unused. | |||
time, // Buffer is long long; size, capacity, truncated are unu sed. | time, // Buffer is long long; size, capacity, truncated are unu sed. | |||
timestamp,// Buffer is long long; size, capacity, truncated are unu sed. | timestamp,// Buffer is long long; size, capacity, truncated are unu sed. | |||
text, // Buffer is a char array. | text, // Buffer is a char array. | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
polymorphic-object-result.hxx | polymorphic-object-result.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/polymorphic-object-result.hxx | // file : odb/pgsql/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_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX | #ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX | |||
#define ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> // query | #include <odb/pgsql/forward.hxx> // query_base | |||
#include <odb/pgsql/statement.hxx> | #include <odb/pgsql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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_pgsql> 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_pgsql> 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 | |||
load_image (); | load_image (); | |||
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/pgsql/polymorphic-object-result.txx | // file : odb/pgsql/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> // object_not_persistent | #include <odb/exceptions.hxx> // object_not_persistent | |||
#include <odb/pgsql/polymorphic-object-statements.hxx> | #include <odb/pgsql/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 fetch) | load (object_type* pobj, bool fetch) | |||
{ | { | |||
skipping to change at line 51 | skipping to change at line 64 | |||
load_image (); | load_image (); | |||
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 88 | skipping to change at line 100 | |||
{ | { | |||
// 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 135 | skipping to change at line 148 | |||
} | } | |||
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 () | |||
{ | { | |||
load_image (); | load_image (); | |||
return root_traits::id (statements_.root_statements ().image ()); | return root_traits::id (statements_.root_statements ().image ()); | |||
skipping to change at line 185 | skipping to change at line 199 | |||
statement_->free_result (); | statement_->free_result (); | |||
this->end_ = true; | this->end_ = true; | |||
} | } | |||
} | } | |||
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_pgsql> 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 210 | skipping to change at line 224 | |||
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_pgsql> 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/pgsql/polymorphic-object-statements.hxx | // file : odb/pgsql/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_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | #ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | |||
#define ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX | #define ODB_PGSQL_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 169 | skipping to change at line 169 | |||
int discriminator_id_image_formats_[id_column_count]; | int discriminator_id_image_formats_[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_pgsql> 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 381 | skipping to change at line 381 | |||
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_, | ||||
root_statements_.id_image_binding (), | ||||
root_statements_.id_image_native_binding (), | ||||
object_traits::find_statement_types); | ||||
} | } | |||
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 | 7 lines changed or added | |||
polymorphic-object-statements.txx | polymorphic-object-statements.txx | |||
---|---|---|---|---|
// file : odb/pgsql/polymorphic-object-statements.txx | // file : odb/pgsql/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/pgsql/connection.hxx> | #include <odb/pgsql/connection.hxx> | |||
#include <odb/pgsql/transaction.hxx> | #include <odb/pgsql/transaction.hxx> | |||
#include <odb/pgsql/statement-cache.hxx> | #include <odb/pgsql/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/pgsql/query.hxx | // file : odb/pgsql/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_PGSQL_QUERY_HXX | #ifndef ODB_PGSQL_QUERY_HXX | |||
#define ODB_PGSQL_QUERY_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | #include <odb/pgsql/forward.hxx> | |||
#include <odb/pgsql/traits.hxx> | #include <odb/pgsql/traits.hxx> | |||
#include <odb/pgsql/binding.hxx> | #include <odb/pgsql/binding.hxx> | |||
#include <odb/pgsql/pgsql-oid.hxx> | #include <odb/pgsql/pgsql-oid.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/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
#include <odb/pgsql/details/conversion.hxx> | #include <odb/pgsql/details/conversion.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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_PGSQL_EXPORT query_param: details::shared_base | struct LIBODB_PGSQL_EXPORT query_param: details::shared_base | |||
{ | { | |||
typedef pgsql::bind bind_type; | typedef pgsql::bind bind_type; | |||
virtual | virtual | |||
~query_param (); | ~query_param (); | |||
bool | bool | |||
skipping to change at line 89 | skipping to change at line 139 | |||
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_PGSQL_EXPORT query | class LIBODB_PGSQL_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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |||
{ | { | |||
} | } | |||
// True or false literal. | // True or false literal. | |||
// | // | |||
explicit | explicit | |||
query (bool v) | query_base (bool v) | |||
: binding_ (0, 0), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |||
{ | { | |||
clause_.push_back (clause_part (v)); | append (v); | |||
} | } | |||
explicit | explicit | |||
query (const char* native) | query_base (const char* native) | |||
: binding_ (0, 0), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |||
{ | { | |||
clause_.push_back (clause_part (clause_part::native, native)); | 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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 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), native_binding_ (0, 0, 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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 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), native_binding_ (0, 0, 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 PostgreSQL native. Define | ||||
d | ||||
// 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; | ||||
native_binding& | native_binding& | |||
parameters_binding () const; | parameters_binding () const; | |||
const unsigned int* | const unsigned int* | |||
parameter_types () const | parameter_types () const | |||
{ | { | |||
return types_.empty () ? 0 : &types_[0]; | return types_.empty () ? 0 : &types_[0]; | |||
} | } | |||
std::size_t | std::size_t | |||
skipping to change at line 200 | skipping to change at line 276 | |||
return parameters_.size (); | return parameters_.size (); | |||
} | } | |||
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<bind> bind_; | mutable std::vector<bind> bind_; | |||
mutable binding binding_; | mutable binding binding_; | |||
std::vector<char*> values_; | std::vector<char*> values_; | |||
std::vector<int> lengths_; | std::vector<int> lengths_; | |||
std::vector<int> formats_; | std::vector<int> formats_; | |||
std::vector<unsigned int> types_; | std::vector<unsigned int> types_; | |||
mutable native_binding native_binding_; | mutable native_binding native_binding_; | |||
}; | }; | |||
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_PGSQL_EXPORT query | template <typename T, database_type_id ID> | |||
operator&& (const query&, const query&); | inline query_base | |||
operator+ (const std::string& s, ref_bind_typed<T, ID> b) | ||||
LIBODB_PGSQL_EXPORT query | { | |||
operator|| (const query&, const query&); | query_base r (s); | |||
r += b; | ||||
LIBODB_PGSQL_EXPORT query | return r; | |||
operator! (const query&); | } | |||
// 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_PGSQL_EXPORT query_base | |||
}; | operator&& (const query_base&, const query_base&); | |||
template <typename T> | LIBODB_PGSQL_EXPORT query_base | |||
const T& | operator|| (const query_base&, const query_base&); | |||
type_instance (); | ||||
template <typename T, database_type_id ID> | LIBODB_PGSQL_EXPORT query_base | |||
struct query_column | operator! (const query_base&); | |||
// query_column | ||||
// | ||||
struct LIBODB_PGSQL_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 450 | skipping to change at line 672 | |||
} | } | |||
// 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; | |||
// BOOLEAN | // BOOLEAN | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_boolean>: query_param | struct query_param_impl<T, id_boolean>: query_param | |||
{ | { | |||
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 (bind_type* b) | bind (bind_type* b) | |||
{ | { | |||
b->type = bind::boolean; | b->type = bind::boolean_; | |||
b->buffer = &image_; | b->buffer = &image_; | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return bool_oid; | return bool_oid; | |||
} | } | |||
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_boolean>::set_image (image_, is_null, v); | value_traits<T, id_boolean>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
bool image_; | bool image_; | |||
}; | }; | |||
// SMALLINT | // SMALLINT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_smallint>: query_param | struct query_param_impl<T, id_smallint>: 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 | |||
skipping to change at line 1205 | skipping to change at line 1445 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return int2_oid; | return int2_oid; | |||
} | } | |||
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_smallint>::set_image (image_, is_null, v); | value_traits<T, id_smallint>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
short image_; | short image_; | |||
}; | }; | |||
// INTEGER | // INTEGER | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_integer>: query_param | struct query_param_impl<T, id_integer>: 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 | |||
skipping to change at line 1245 | skipping to change at line 1485 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return int4_oid; | return int4_oid; | |||
} | } | |||
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_integer>::set_image (image_, is_null, v); | value_traits<T, id_integer>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
int image_; | int image_; | |||
}; | }; | |||
// BIGINT | // BIGINT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_bigint>: query_param | struct query_param_impl<T, id_bigint>: 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 | |||
skipping to change at line 1285 | skipping to change at line 1525 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return int8_oid; | return int8_oid; | |||
} | } | |||
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_bigint>::set_image (image_, is_null, v); | value_traits<T, id_bigint>::set_image (image_, is_null, v); | |||
} | } | |||
private: | private: | |||
long long image_; | long long image_; | |||
}; | }; | |||
// REAL | // REAL | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_real>: query_param | struct query_param_impl<T, id_real>: query_param | |||
{ | { | |||
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 | |||
skipping to change at line 1325 | skipping to change at line 1565 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return float4_oid; | return float4_oid; | |||
} | } | |||
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_real>::set_image (image_, is_null, v); | value_traits<T, id_real>::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 | |||
skipping to change at line 1365 | skipping to change at line 1605 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return float8_oid; | return float8_oid; | |||
} | } | |||
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_; | |||
}; | }; | |||
// NUMERIC | // NUMERIC | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_numeric>: query_param | struct query_param_impl<T, id_numeric>: 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 (bind_type* b) | bind (bind_type* b) | |||
skipping to change at line 1406 | skipping to change at line 1646 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return numeric_oid; | return numeric_oid; | |||
} | } | |||
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_numeric>::set_image (buffer_, size, is_null, v); | value_traits<T, id_numeric>::set_image (buffer_, size, is_null, v); | |||
size_ = size; | size_ = size; | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
std::size_t size_; | std::size_t 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 | |||
skipping to change at line 1450 | skipping to change at line 1690 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return date_oid; | return date_oid; | |||
} | } | |||
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: | |||
int image_; | int 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 | |||
skipping to change at line 1490 | skipping to change at line 1730 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return time_oid; | return time_oid; | |||
} | } | |||
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: | |||
long long image_; | long long 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 | |||
skipping to change at line 1530 | skipping to change at line 1770 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return timestamp_oid; | return timestamp_oid; | |||
} | } | |||
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: | |||
long long image_; | long long 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 (bind_type* b) | bind (bind_type* b) | |||
skipping to change at line 1571 | skipping to change at line 1811 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return text_oid; | return text_oid; | |||
} | } | |||
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_ = size; | size_ = size; | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
std::size_t size_; | std::size_t size_; | |||
}; | }; | |||
// BYTEA | // BYTEA | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_bytea>: query_param | struct query_param_impl<T, id_bytea>: 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 (bind_type* b) | bind (bind_type* b) | |||
skipping to change at line 1616 | skipping to change at line 1856 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return bytea_oid; | return bytea_oid; | |||
} | } | |||
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_bytea>::set_image (buffer_, size, is_null, v); | value_traits<T, id_bytea>::set_image (buffer_, size, is_null, v); | |||
size_ = size; | size_ = size; | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::buffer buffer_; | details::buffer buffer_; | |||
std::size_t size_; | std::size_t 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 () | |||
{ | { | |||
return init (*static_cast<const T*> (value_)); | return init (*static_cast<const T*> (value_)); | |||
} | } | |||
virtual void | virtual void | |||
bind (bind_type* b) | bind (bind_type* b) | |||
{ | { | |||
b->type = bind::bit; | b->type = bind::bit; | |||
b->buffer = buffer_.data (); | b->buffer = buffer_.data (); | |||
b->capacity = buffer_.capacity (); | b->capacity = buffer_.capacity (); | |||
b->size = &size_; | b->size = &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 ()); | |||
// NOTE: Using a fixed size bit type in queries requires | // NOTE: Using a fixed size bit type in queries requires | |||
// alternative image buffer type support. | // alternative image buffer type support. | |||
// | // | |||
value_traits<T, id_bit>::set_image (buffer_, size, is_null, v); | value_traits<T, id_bit>::set_image (buffer_, size, is_null, v); | |||
size_ = size; | size_ = size; | |||
skipping to change at line 1679 | skipping to change at line 1919 | |||
private: | private: | |||
details::ubuffer buffer_; | details::ubuffer buffer_; | |||
std::size_t size_; | std::size_t size_; | |||
}; | }; | |||
// VARBIT | // VARBIT | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_varbit>: query_param | struct query_param_impl<T, id_varbit>: 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 (bind_type* b) | bind (bind_type* b) | |||
skipping to change at line 1705 | skipping to change at line 1945 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return varbit_oid; | return varbit_oid; | |||
} | } | |||
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_varbit>::set_image (buffer_, size, is_null, v); | value_traits<T, id_varbit>::set_image (buffer_, size, is_null, v); | |||
size_ = size; | size_ = size; | |||
return cap != buffer_.capacity (); | return cap != buffer_.capacity (); | |||
} | } | |||
private: | private: | |||
details::ubuffer buffer_; | details::ubuffer buffer_; | |||
std::size_t size_; | std::size_t size_; | |||
}; | }; | |||
// UUID | // UUID | |||
// | // | |||
template <typename T> | template <typename T> | |||
struct query_param_impl<T, id_uuid>: query_param | struct query_param_impl<T, id_uuid>: 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 | |||
skipping to change at line 1749 | skipping to change at line 1989 | |||
} | } | |||
virtual unsigned int | virtual unsigned int | |||
oid () const | oid () const | |||
{ | { | |||
return uuid_oid; | return uuid_oid; | |||
} | } | |||
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_uuid>::set_image (buffer_, is_null, v); | value_traits<T, id_uuid>::set_image (buffer_, is_null, v); | |||
} | } | |||
private: | private: | |||
unsigned char buffer_[16]; | unsigned char buffer_[16]; | |||
}; | }; | |||
} | } | |||
} | } | |||
// odb::query specialization for PostgreSQL. | // odb::pgsql::query and odb::query specialization for PostgreSQL. | |||
// | // | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | ||||
{ | ||||
template <typename T> | ||||
class query: public query_base, | ||||
public query_selector<T, id_pgsql>::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 pgsql::query; | ||||
} | ||||
} | ||||
// Derive odb::query from odb::pgsql::query so that it can be | ||||
// implicitly converted in pgsql::database::query() calls. | ||||
// | ||||
template <typename T> | template <typename T> | |||
class query<T, pgsql::query>: public pgsql::query, | class query<T, pgsql::query_base>: public pgsql::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) | |||
: pgsql::query (v) | : pgsql::query<T> (v) | |||
{ | { | |||
} | } | |||
explicit | explicit | |||
query (const char* q) | query (const char* q) | |||
: pgsql::query (q) | : pgsql::query<T> (q) | |||
{ | { | |||
} | } | |||
explicit | explicit | |||
query (const std::string& q) | query (const std::string& q) | |||
: pgsql::query (q) | : pgsql::query<T> (q) | |||
{ | { | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
explicit | explicit | |||
query (pgsql::val_bind<T2> v) | query (pgsql::val_bind<T2> v) | |||
: pgsql::query (pgsql::query (v)) | : pgsql::query<T> (v) | |||
{ | { | |||
} | } | |||
template <typename T2> | template <typename T2> | |||
explicit | explicit | |||
query (pgsql::ref_bind<T2> r) | query (pgsql::ref_bind<T2> r) | |||
: pgsql::query (pgsql::query (r)) | : pgsql::query<T> (r) | |||
{ | { | |||
} | } | |||
query (const pgsql::query& q) | query (const pgsql::query_base& q) | |||
: pgsql::query (q) | : pgsql::query<T> (q) | |||
{ | { | |||
} | } | |||
template <pgsql::database_type_id ID> | template <pgsql::database_type_id ID> | |||
query (const pgsql::query_column<bool, ID>& qc) | query (const pgsql::query_column<bool, ID>& qc) | |||
: pgsql::query (qc) | : pgsql::query<T> (qc) | |||
{ | { | |||
} | } | |||
}; | }; | |||
} | } | |||
#include <odb/pgsql/query.ixx> | #include <odb/pgsql/query.ixx> | |||
#include <odb/pgsql/query.txx> | #include <odb/pgsql/query.txx> | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
End of changes. 242 change blocks. | ||||
303 lines changed or deleted | 618 lines changed or added | |||
query.ixx | query.ixx | |||
---|---|---|---|---|
// file : odb/pgsql/query.ixx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
inline native_binding& query_base:: | ||||
parameters_binding () const | ||||
{ | ||||
return native_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/pgsql/query.txx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
// 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), native_binding_ (0, 0, 0, 0) | : binding_ (0, 0), native_binding_ (0, 0, 0, 0) | |||
{ | { | |||
// Cannot use IS TRUE here since database type can be a non- | // Cannot use IS TRUE here since database type can be a non- | |||
// integral type. | // integral type. | |||
// | // | |||
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/pgsql/simple-object-result.hxx | // file : odb/pgsql/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_PGSQL_SIMPLE_OBJECT_RESULT_HXX | #ifndef ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX | |||
#define ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> // query | #include <odb/pgsql/forward.hxx> // query_base | |||
#include <odb/pgsql/statement.hxx> | #include <odb/pgsql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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_pgsql> 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 | |||
load_image (); | load_image (); | |||
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/pgsql/simple-object-result.txx | // file : odb/pgsql/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/pgsql/simple-object-statements.hxx> | #include <odb/pgsql/simple-object-statements.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
skipping to change at line 24 | skipping to change at line 24 | |||
{ | { | |||
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 fetch) | load (object_type& obj, bool fetch) | |||
{ | { | |||
if (fetch) | if (fetch) | |||
load_image (); | load_image (); | |||
// 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 () | |||
{ | { | |||
load_image (); | load_image (); | |||
return object_traits::id (statements_.image ()); | return object_traits::id (statements_.image ()); | |||
} | } | |||
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/pgsql/simple-object-statements.hxx | // file : odb/pgsql/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_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX | #ifndef ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX | |||
#define ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX | #define ODB_PGSQL_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 pgsql::connection connection_type; | typedef pgsql::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, 0, 0); | ||||
} | ||||
T& | T& | |||
get (connection_type& c) | get (connection_type& c, | |||
binding& id, native_binding& idn, const Oid* idt) | ||||
{ | { | |||
if (p_ == 0) | if (p_ == 0) | |||
allocate (&c); | allocate (&c, &id, &idn, idt); | |||
return *p_; | return *p_; | |||
} | } | |||
private: | private: | |||
void | void | |||
allocate (connection_type*); | allocate (connection_type*, binding*, native_binding*, const Oid*); | |||
private: | private: | |||
T* p_; | T* p_; | |||
void (container_statement_cache_ptr::*deleter_) (connection_type*); | void (container_statement_cache_ptr::*deleter_) ( | |||
connection_type*, binding*, native_binding*, const Oid*); | ||||
}; | }; | |||
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, native_binding* idn, const Oid* idt) | ||||
{ | { | |||
// 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, *idn, idt); | |||
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 157 | |||
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_pgsql> object_traits; | |||
optimistic_data (bind*, char** nv, int* nl, int* nf); | optimistic_data (bind*, char** nv, int* nl, int* nf); | |||
// 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_; | |||
native_binding id_image_native_binding_; | native_binding id_image_native_binding_; | |||
details::shared_ptr<delete_statement> erase_; | details::shared_ptr<delete_statement> erase_; | |||
skipping to change at line 174 | skipping to change at line 181 | |||
struct optimistic_data<T, false> | struct optimistic_data<T, false> | |||
{ | { | |||
optimistic_data (bind*, char**, int*, int*) {} | optimistic_data (bind*, char**, int*, int*) {} | |||
}; | }; | |||
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_pgsql> 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 435 | skipping to change at line 442 | |||
false)); | false)); | |||
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_, | ||||
id_image_native_binding_, | ||||
object_traits::find_statement_types); | ||||
} | } | |||
public: | public: | |||
// select = total | // select = total | |||
// insert = total - inverse - managed_optimistic - auto_id | // insert = total - inverse - managed_optimistic - auto_id | |||
// 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 | 22 lines changed or added | |||
simple-object-statements.ixx | simple-object-statements.ixx | |||
---|---|---|---|---|
// file : odb/pgsql/simple-object-statements.ixx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
// | // | |||
// 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/pgsql/simple-object-statements.txx | // file : odb/pgsql/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/pgsql/connection.hxx> | #include <odb/pgsql/connection.hxx> | |||
namespace odb | namespace odb | |||
skipping to change at line 111 | skipping to change at line 111 | |||
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 147 | skipping to change at line 147 | |||
// 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/pgsql/statement-cache.hxx | // file : odb/pgsql/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_PGSQL_STATEMENT_CACHE_HXX | #ifndef ODB_PGSQL_STATEMENT_CACHE_HXX | |||
#define ODB_PGSQL_STATEMENT_CACHE_HXX | #define ODB_PGSQL_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 pgsql | namespace pgsql | |||
{ | { | |||
class LIBODB_PGSQL_EXPORT statement_cache | class LIBODB_PGSQL_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_pgsql>::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/pgsql/statement-cache.txx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
typename object_traits<T>::statements_type& statement_cache:: | typename object_traits_impl<T, id_pgsql>::statements_type& | |||
statement_cache:: | ||||
find_object () | find_object () | |||
{ | { | |||
typedef typename object_traits<T>::statements_type statements_type; | typedef | |||
typename object_traits_impl<T, id_pgsql>::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/pgsql/statement.hxx | // file : odb/pgsql/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_PGSQL_STATEMENT_HXX | #ifndef ODB_PGSQL_STATEMENT_HXX | |||
#define ODB_PGSQL_STATEMENT_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> | ||||
#include <odb/pgsql/binding.hxx> | #include <odb/pgsql/binding.hxx> | |||
#include <odb/pgsql/pgsql-fwd.hxx> // PGresult | #include <odb/pgsql/pgsql-fwd.hxx> // PGresult | |||
#include <odb/pgsql/connection.hxx> | ||||
#include <odb/pgsql/auto-handle.hxx> | #include <odb/pgsql/auto-handle.hxx> | |||
#include <odb/pgsql/details/export.hxx> | #include <odb/pgsql/details/export.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
class connection; | class connection; | |||
class LIBODB_PGSQL_EXPORT statement: public odb::statement | class LIBODB_PGSQL_EXPORT statement: public odb::statement | |||
{ | { | |||
public: | public: | |||
typedef pgsql::connection connection_type; | ||||
virtual | virtual | |||
~statement () = 0; | ~statement () = 0; | |||
const char* | const char* | |||
name () const | name () const | |||
{ | { | |||
return name_; | return name_; | |||
} | } | |||
virtual const char* | virtual const char* | |||
text () const; | text () const; | |||
virtual connection_type& | ||||
connection () | ||||
{ | ||||
return conn_; | ||||
} | ||||
void | void | |||
deallocate (); | deallocate (); | |||
// Adapt an ODB binding to a native PostgreSQL parameter binding. | // Adapt an ODB binding to a native PostgreSQL parameter binding. | |||
// | // | |||
static void | static void | |||
bind_param (native_binding&, const binding&); | bind_param (native_binding&, const binding&); | |||
// Populate an ODB binding given a PostgreSQL result. If the truncate d | // Populate an ODB binding given a PostgreSQL result. If the truncate d | |||
// argument is true, then only truncated columns are extracted. Retur n | // argument is true, then only truncated columns are extracted. Retur n | |||
skipping to change at line 65 | skipping to change at line 74 | |||
// more columns were truncated. | // more columns were truncated. | |||
// | // | |||
static bool | static bool | |||
bind_result (bind*, | bind_result (bind*, | |||
std::size_t count, | std::size_t count, | |||
PGresult*, | PGresult*, | |||
std::size_t row, | std::size_t row, | |||
bool truncated = false); | bool truncated = false); | |||
protected: | protected: | |||
statement (connection&, | statement (connection_type&, | |||
const std::string& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count); | std::size_t types_count); | |||
statement (connection&, | statement (connection_type&, | |||
const char* name, | const char* name, | |||
const char* text, | const char* text, | |||
bool copy_name_text, | bool copy_name_text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count); | std::size_t types_count); | |||
private: | private: | |||
void | void | |||
init (const Oid* types, std::size_t types_count); | init (const Oid* types, std::size_t types_count); | |||
protected: | protected: | |||
connection& conn_; | connection_type& conn_; | |||
std::string name_copy_; | std::string name_copy_; | |||
const char* name_; | const char* name_; | |||
std::string text_copy_; | std::string text_copy_; | |||
const char* text_; | const char* text_; | |||
private: | private: | |||
bool deallocated_; | bool deallocated_; | |||
}; | }; | |||
class LIBODB_PGSQL_EXPORT select_statement: public statement | class LIBODB_PGSQL_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& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
binding& result); | binding& result); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const char* name, | const char* name, | |||
const char* stmt, | const char* stmt, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
binding& result, | binding& result, | |||
bool copy_name_text = true); | bool copy_name_text = true); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const std::string& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
binding& result); | binding& result); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const char* name, | const char* name, | |||
const char* text, | const char* text, | |||
binding& result, | binding& result, | |||
bool copy_name_text = true); | bool copy_name_text = true); | |||
select_statement (connection& conn, | select_statement (connection_type& conn, | |||
const std::string& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
native_binding& native_param, | native_binding& native_param, | |||
binding& result); | binding& result); | |||
// Common select interface expected by the generated code. | // Common select interface expected by the generated code. | |||
// | // | |||
public: | public: | |||
skipping to change at line 231 | skipping to change at line 240 | |||
private: | private: | |||
select_statement& s_; | select_statement& s_; | |||
}; | }; | |||
class LIBODB_PGSQL_EXPORT insert_statement: public statement | class LIBODB_PGSQL_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& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
bool returning); | bool returning); | |||
insert_statement (connection& conn, | insert_statement (connection_type& conn, | |||
const char* name, | const char* name, | |||
const char* text, | const char* text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
bool returning, | bool returning, | |||
bool copy_name_text = true); | bool copy_name_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. | |||
skipping to change at line 280 | skipping to change at line 289 | |||
bool returning_; | bool returning_; | |||
unsigned long long id_; | unsigned long long id_; | |||
}; | }; | |||
class LIBODB_PGSQL_EXPORT update_statement: public statement | class LIBODB_PGSQL_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& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param); | native_binding& native_param); | |||
update_statement (connection& conn, | update_statement (connection_type& conn, | |||
const char* name, | const char* name, | |||
const char* text, | const char* text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
bool copy_name_text = true); | bool copy_name_text = true); | |||
unsigned long long | unsigned long long | |||
execute (); | execute (); | |||
skipping to change at line 315 | skipping to change at line 324 | |||
binding& param_; | binding& param_; | |||
native_binding& native_param_; | native_binding& native_param_; | |||
}; | }; | |||
class LIBODB_PGSQL_EXPORT delete_statement: public statement | class LIBODB_PGSQL_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& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param); | native_binding& native_param); | |||
delete_statement (connection& conn, | delete_statement (connection_type& conn, | |||
const char* name, | const char* name, | |||
const char* text, | const char* text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
binding& param, | binding& param, | |||
native_binding& native_param, | native_binding& native_param, | |||
bool copy_name_text = true); | bool copy_name_text = true); | |||
delete_statement (connection& conn, | delete_statement (connection_type& conn, | |||
const std::string& name, | const std::string& name, | |||
const std::string& text, | const std::string& text, | |||
const Oid* types, | const Oid* types, | |||
std::size_t types_count, | std::size_t types_count, | |||
native_binding& native_param); | native_binding& native_param); | |||
unsigned long long | unsigned long long | |||
execute (); | execute (); | |||
private: | private: | |||
End of changes. 21 change blocks. | ||||
17 lines changed or deleted | 26 lines changed or added | |||
statements-base.hxx | statements-base.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/statements-base.hxx | // file : odb/pgsql/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_PGSQL_STATEMENTS_BASE_HXX | #ifndef ODB_PGSQL_STATEMENTS_BASE_HXX | |||
#define ODB_PGSQL_STATEMENTS_BASE_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
tracer.hxx | tracer.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/tracer.hxx | // file : odb/pgsql/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_PGSQL_TRACER_HXX | #ifndef ODB_PGSQL_TRACER_HXX | |||
#define ODB_PGSQL_TRACER_HXX | #define ODB_PGSQL_TRACER_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/tracer.hxx> | #include <odb/tracer.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
traits.hxx | traits.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/traits.hxx | // file : odb/pgsql/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_PGSQL_TRAITS_HXX | #ifndef ODB_PGSQL_TRAITS_HXX | |||
#define ODB_PGSQL_TRAITS_HXX | #define ODB_PGSQL_TRAITS_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/details/config.hxx> // ODB_CXX11 | #include <odb/details/config.hxx> // ODB_CXX11 | |||
#include <string> | #include <string> | |||
skipping to change at line 44 | skipping to change at line 44 | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
enum database_type_id | enum database_type_id | |||
{ | { | |||
id_boolean, | id_boolean, | |||
id_smallint, | id_smallint, | |||
id_integer, | id_integer, | |||
id_bigint, | id_bigint, | |||
id_numeric, | id_numeric, // Internal PostgreSQL binary representation. | |||
id_real, | id_real, | |||
id_double, | id_double, | |||
id_date, | id_date, | |||
id_time, | id_time, | |||
id_timestamp, | id_timestamp, | |||
id_string, | id_string, | |||
id_bytea, | id_bytea, | |||
skipping to change at line 380 | skipping to change at line 380 | |||
static void | static void | |||
set_image (image_type& i, bool& is_null, T v) | set_image (image_type& i, bool& is_null, T v) | |||
{ | { | |||
is_null = false; | is_null = false; | |||
i = details::endian_traits::hton (image_type (v)); | i = details::endian_traits::hton (image_type (v)); | |||
} | } | |||
}; | }; | |||
// std::string specialization. | // std::string specialization. | |||
// | // | |||
class LIBODB_PGSQL_EXPORT string_value_traits | template <> | |||
struct LIBODB_PGSQL_EXPORT default_value_traits<std::string, id_string> | ||||
{ | { | |||
public: | ||||
typedef std::string value_type; | typedef std::string value_type; | |||
typedef std::string query_type; | typedef std::string query_type; | |||
typedef details::buffer image_type; | typedef details::buffer image_type; | |||
static void | static void | |||
set_value (std::string& v, | set_value (std::string& v, | |||
const details::buffer& b, | const details::buffer& b, | |||
std::size_t n, | std::size_t n, | |||
bool is_null) | bool is_null) | |||
{ | { | |||
skipping to change at line 406 | skipping to change at line 406 | |||
v.erase (); | v.erase (); | |||
} | } | |||
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 std::string&); | const std::string&); | |||
}; | }; | |||
template <> | // char*/const char* specialization | |||
struct LIBODB_PGSQL_EXPORT default_value_traits<std::string, id_numeric | ||||
>: | ||||
string_value_traits | ||||
{ | ||||
}; | ||||
template <> | ||||
struct LIBODB_PGSQL_EXPORT default_value_traits<std::string, id_string> | ||||
: | ||||
string_value_traits | ||||
{ | ||||
}; | ||||
// 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_PGSQL_EXPORT c_string_value_traits | class LIBODB_PGSQL_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_PGSQL_EXPORT default_value_traits<const char*, id_numeric | struct LIBODB_PGSQL_EXPORT default_value_traits<char*, id_string>: | |||
>: | c_string_value_traits {}; | |||
c_string_value_traits | ||||
{ | ||||
}; | ||||
template <> | template <> | |||
struct LIBODB_PGSQL_EXPORT default_value_traits<const char*, id_string> : | struct LIBODB_PGSQL_EXPORT default_value_traits<const char*, id_string> : | |||
c_string_value_traits | c_string_value_traits {}; | |||
{ | ||||
}; | ||||
template <std::size_t N> | // char[N] specializations. | |||
struct default_value_traits<char[N], id_numeric>: c_string_value_traits | // | |||
struct LIBODB_PGSQL_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<const char[N], id_numeric>: | struct default_value_traits<char[N], id_string> | |||
c_string_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); | ||||
} | ||||
}; | }; | |||
// std::array<char, N> (string) specialization. | ||||
// | ||||
#ifdef ODB_CXX11 | ||||
template <std::size_t N> | template <std::size_t N> | |||
struct default_value_traits<char[N], id_string>: c_string_value_traits | struct default_value_traits<std::array<char, N>, id_string> | |||
{ | { | |||
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); | ||||
} | ||||
}; | }; | |||
#endif | ||||
template <std::size_t N> | // char specialization. | |||
struct default_value_traits<const char[N], id_string>: | // | |||
c_string_value_traits | template <> | |||
struct LIBODB_PGSQL_EXPORT default_value_traits<char, id_string> | ||||
{ | { | |||
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); | ||||
} | ||||
}; | }; | |||
// std::vector<char> (buffer) specialization. | // std::vector<char> (buffer) specialization. | |||
// | // | |||
template <> | template <> | |||
struct LIBODB_PGSQL_EXPORT default_value_traits< | struct LIBODB_PGSQL_EXPORT default_value_traits< | |||
std::vector<char>, id_bytea> | std::vector<char>, id_bytea> | |||
{ | { | |||
public: | public: | |||
typedef std::vector<char> value_type; | typedef std::vector<char> value_type; | |||
skipping to change at line 543 | skipping to change at line 607 | |||
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_bytea> | struct default_value_traits<char[N], id_bytea> | |||
{ | { | |||
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 581 | skipping to change at line 645 | |||
} | } | |||
}; | }; | |||
// 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_bytea> | struct default_value_traits<unsigned char[N], id_bytea> | |||
{ | { | |||
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 883 | |||
// 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_bytea; | static const database_type_id db_type_id = id_bytea; | |||
}; | }; | |||
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_bytea; | static const database_type_id db_type_id = id_bytea; | |||
}; | }; | |||
#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_bytea; | static const database_type_id db_type_id = id_bytea; | |||
}; | }; | |||
#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_bytea; | static const database_type_id db_type_id = id_bytea; | |||
}; | }; | |||
#endif | #endif | |||
} | } | |||
} | } | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
End of changes. 27 change blocks. | ||||
45 lines changed or deleted | 120 lines changed or added | |||
transaction-impl.hxx | transaction-impl.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/transaction-impl.hxx | // file : odb/pgsql/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_PGSQL_TRANSACTION_IMPL_HXX | #ifndef ODB_PGSQL_TRANSACTION_IMPL_HXX | |||
#define ODB_PGSQL_TRANSACTION_IMPL_HXX | #define ODB_PGSQL_TRANSACTION_IMPL_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/transaction.hxx> | #include <odb/transaction.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/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/pgsql/transaction-impl.ixx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
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/pgsql/transaction.hxx | // file : odb/pgsql/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_PGSQL_TRANSACTION_HXX | #ifndef ODB_PGSQL_TRANSACTION_HXX | |||
#define ODB_PGSQL_TRANSACTION_HXX | #define ODB_PGSQL_TRANSACTION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/transaction.hxx> | #include <odb/transaction.hxx> | |||
#include <odb/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
transaction.ixx | transaction.ixx | |||
---|---|---|---|---|
// file : odb/pgsql/transaction.ixx | // file : odb/pgsql/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/pgsql/database.hxx> | #include <odb/pgsql/database.hxx> | |||
#include <odb/pgsql/transaction-impl.hxx> | #include <odb/pgsql/transaction-impl.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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/pgsql/version.hxx | // file : odb/pgsql/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_PGSQL_VERSION_HXX | #ifndef ODB_PGSQL_VERSION_HXX | |||
#define ODB_PGSQL_VERSION_HXX | #define ODB_PGSQL_VERSION_HXX | |||
#include <odb/pre.hxx> | #include <odb/pre.hxx> | |||
#include <odb/pgsql/details/config.hxx> | #include <odb/pgsql/details/config.hxx> | |||
#include <odb/version.hxx> | #include <odb/version.hxx> | |||
skipping to change at line 32 | skipping to change at line 32 | |||
// 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 | |||
// libodb-pgsql version: odb interface version plus the bugfix | // libodb-pgsql version: odb interface version plus the bugfix | |||
// version. | // version. | |||
// | // | |||
#define LIBODB_PGSQL_VERSION 2010100 | #define LIBODB_PGSQL_VERSION 2020000 | |||
#define LIBODB_PGSQL_VERSION_STR "2.1.1" | #define LIBODB_PGSQL_VERSION_STR "2.2.0" | |||
#include <odb/post.hxx> | #include <odb/post.hxx> | |||
#endif // ODB_PGSQL_VERSION_HXX | #endif // ODB_PGSQL_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/pgsql/view-result.hxx | // file : odb/pgsql/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_PGSQL_VIEW_RESULT_HXX | #ifndef ODB_PGSQL_VIEW_RESULT_HXX | |||
#define ODB_PGSQL_VIEW_RESULT_HXX | #define ODB_PGSQL_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/pgsql/version.hxx> | #include <odb/pgsql/version.hxx> | |||
#include <odb/pgsql/forward.hxx> // query, view_statements | #include <odb/pgsql/forward.hxx> // query_base, view_statements | |||
#include <odb/pgsql/statement.hxx> | #include <odb/pgsql/statement.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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_pgsql> 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: | |||
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/pgsql/view-result.txx | // file : odb/pgsql/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/pgsql/view-statements.hxx> | #include <odb/pgsql/view-statements.hxx> | |||
namespace odb | namespace odb | |||
{ | { | |||
namespace pgsql | namespace pgsql | |||
{ | { | |||
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) | |||
{ | { | |||
skipping to change at line 67 | skipping to change at line 80 | |||
if (im.version != statements_.image_version ()) | if (im.version != statements_.image_version ()) | |||
{ | { | |||
binding& b (statements_.image_binding ()); | binding& b (statements_.image_binding ()); | |||
view_traits::bind (b.bind, im); | view_traits::bind (b.bind, im); | |||
statements_.image_version (im.version); | statements_.image_version (im.version); | |||
b.version++; | b.version++; | |||
statement_->reload (); | statement_->reload (); | |||
} | } | |||
} | } | |||
odb::database& db (this->database ()); | view_traits::callback (this->db_, view, callback_event::pre_load); | |||
view_traits::init (view, im, &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, im, &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 (statement_->next ()) | if (statement_->next ()) | |||
count_++; | count_++; | |||
End of changes. 5 change blocks. | ||||
8 lines changed or deleted | 19 lines changed or added | |||
view-statements.hxx | view-statements.hxx | |||
---|---|---|---|---|
// file : odb/pgsql/view-statements.hxx | // file : odb/pgsql/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_PGSQL_VIEW_STATEMENTS_HXX | #ifndef ODB_PGSQL_VIEW_STATEMENTS_HXX | |||
#define ODB_PGSQL_VIEW_STATEMENTS_HXX | #define ODB_PGSQL_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 pgsql | namespace pgsql | |||
{ | { | |||
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_pgsql> 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/pgsql/view-statements.txx | // file : odb/pgsql/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 pgsql | namespace pgsql | |||
{ | { | |||
template <typename T> | template <typename T> | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||