From 476f21938f75553d6bff5e8780b537f7182c5675 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 9 Nov 2015 18:14:37 +0200 Subject: Make database class move-constructible This means it can be returned by value from a function in C++11. --- odb/oracle/connection.cxx | 48 +++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'odb/oracle/connection.cxx') diff --git a/odb/oracle/connection.cxx b/odb/oracle/connection.cxx index bb06121..79f35c0 100644 --- a/odb/oracle/connection.cxx +++ b/odb/oracle/connection.cxx @@ -22,18 +22,19 @@ namespace odb namespace oracle { connection:: - connection (database_type& db) - : odb::connection (db), - db_ (db), + connection (connection_factory& cf) + : odb::connection (cf), failed_ (false), statement_cache_ (new statement_cache_type (*this)), lob_buffer_ (0) { sword r (0); + database_type& db (database ()); + { OCIError* e (0); - r = OCIHandleAlloc (db_.environment (), + r = OCIHandleAlloc (db.environment (), reinterpret_cast (&e), OCI_HTYPE_ERROR, 0, @@ -48,7 +49,7 @@ namespace odb auto_handle auth_info; { OCIAuthInfo* a (0); - r = OCIHandleAlloc (db_.environment (), + r = OCIHandleAlloc (db.environment (), reinterpret_cast (&a), OCI_HTYPE_AUTHINFO, 0, @@ -63,8 +64,8 @@ namespace odb r = OCIAttrSet ( auth_info, OCI_HTYPE_AUTHINFO, - reinterpret_cast (const_cast (db_.user ().c_str ())), - static_cast (db_.user ().size ()), + reinterpret_cast (const_cast (db.user ().c_str ())), + static_cast (db.user ().size ()), OCI_ATTR_USERNAME, error_); @@ -75,8 +76,8 @@ namespace odb auth_info, OCI_HTYPE_AUTHINFO, reinterpret_cast ( - const_cast (db_.password ().c_str ())), - static_cast (db_.password ().size ()), + const_cast (db.password ().c_str ())), + static_cast (db.password ().size ()), OCI_ATTR_PASSWORD, error_); @@ -87,12 +88,12 @@ namespace odb OCISvcCtx* s (0); r = OCISessionGet ( - db_.environment (), + db.environment (), error_, &s, auth_info, - reinterpret_cast (const_cast (db_.db ().c_str ())), - static_cast (db_.db ().size ()), + reinterpret_cast (const_cast (db.db ().c_str ())), + static_cast (db.db ().size ()), 0, 0, 0, @@ -108,18 +109,19 @@ namespace odb } connection:: - connection (database_type& db, OCISvcCtx* handle) - : odb::connection (db), - db_ (db), + connection (connection_factory& cf, OCISvcCtx* handle) + : odb::connection (cf), failed_ (false), statement_cache_ (new statement_cache_type (*this)), lob_buffer_ (0) { sword r (0); + database_type& db (database ()); + { OCIError* e (0); - r = OCIHandleAlloc (db_.environment (), + r = OCIHandleAlloc (db.environment (), reinterpret_cast (&e), OCI_HTYPE_ERROR, 0, @@ -156,5 +158,19 @@ namespace odb generic_statement st (*this, string (s, n)); return st.execute (); } + + // connection_factory + // + connection_factory:: + ~connection_factory () + { + } + + void connection_factory:: + database (database_type& db) + { + odb::connection_factory::db_ = &db; + db_ = &db; + } } } -- cgit v1.1