From 62e234c114d2b6ead93a1d39593c66b648c3d0a6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 15:47:37 +0300 Subject: Turn libodb-oracle repository into package for muti-package repository --- libodb-oracle/odb/oracle/connection.cxx | 175 ++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 libodb-oracle/odb/oracle/connection.cxx (limited to 'libodb-oracle/odb/oracle/connection.cxx') diff --git a/libodb-oracle/odb/oracle/connection.cxx b/libodb-oracle/odb/oracle/connection.cxx new file mode 100644 index 0000000..5c2f7a7 --- /dev/null +++ b/libodb-oracle/odb/oracle/connection.cxx @@ -0,0 +1,175 @@ +// file : odb/oracle/connection.cxx +// license : ODB NCUEL; see accompanying LICENSE file + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace odb +{ + namespace oracle + { + connection:: + 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 (), + reinterpret_cast (&e), + OCI_HTYPE_ERROR, + 0, + 0); + + if (r != OCI_SUCCESS) + throw invalid_oci_handle (); + + error_.reset (e); + } + + auto_handle auth_info; + { + OCIAuthInfo* a (0); + r = OCIHandleAlloc (db.environment (), + reinterpret_cast (&a), + OCI_HTYPE_AUTHINFO, + 0, + 0); + + if (r != OCI_SUCCESS) + throw invalid_oci_handle (); + + auth_info.reset (a); + } + + r = OCIAttrSet ( + auth_info, + OCI_HTYPE_AUTHINFO, + reinterpret_cast (const_cast (db.user ().c_str ())), + static_cast (db.user ().size ()), + OCI_ATTR_USERNAME, + error_); + + if (r == OCI_ERROR || r == OCI_INVALID_HANDLE) + translate_error (error_, r); + + r = OCIAttrSet ( + auth_info, + OCI_HTYPE_AUTHINFO, + reinterpret_cast ( + const_cast (db.password ().c_str ())), + static_cast (db.password ().size ()), + OCI_ATTR_PASSWORD, + error_); + + if (r == OCI_ERROR || r == OCI_INVALID_HANDLE) + translate_error (error_, r); + + { + OCISvcCtx* s (0); + + r = OCISessionGet ( + db.environment (), + error_, + &s, + auth_info, + reinterpret_cast (const_cast (db.db ().c_str ())), + static_cast (db.db ().size ()), + 0, + 0, + 0, + 0, + 0, + OCI_SESSGET_STMTCACHE); + + if (r == OCI_ERROR || r == OCI_INVALID_HANDLE) + translate_error (error_, r); + + handle_.reset (s, error_); + } + } + + connection:: + 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 (), + reinterpret_cast (&e), + OCI_HTYPE_ERROR, + 0, + 0); + + if (r != OCI_SUCCESS) + throw invalid_oci_handle (); + + error_.reset (e); + } + + handle_.reset (handle, error_); + } + + connection:: + ~connection () + { + // Deallocate prepared statements before we close the connection. + // + recycle (); + clear_prepared_map (); + statement_cache_.reset (); + } + + transaction_impl* connection:: + begin () + { + return new transaction_impl (connection_ptr (inc_ref (this))); + } + + unsigned long long connection:: + execute (const char* s, std::size_t n) + { + 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