8 #define SOCI_ORACLE_SOURCE 18 #pragma warning(disable:4355) 26 std::string
const & userName, std::string
const & password,
int mode,
27 bool decimals_as_strings)
28 : envhp_(NULL), srvhp_(NULL), errhp_(NULL), svchp_(NULL), usrhp_(NULL)
29 , decimals_as_strings_(decimals_as_strings)
34 res = OCIEnvCreate(&
envhp_, OCI_THREADED | OCI_ENV_NO_MUTEX,
36 if (res != OCI_SUCCESS)
42 res = OCIHandleAlloc(
envhp_, reinterpret_cast<dvoid**>(&
srvhp_),
43 OCI_HTYPE_SERVER, 0, 0);
44 if (res != OCI_SUCCESS)
47 throw soci_error(
"Cannot create server handle");
51 res = OCIHandleAlloc(
envhp_, reinterpret_cast<dvoid**>(&
errhp_),
52 OCI_HTYPE_ERROR, 0, 0);
53 if (res != OCI_SUCCESS)
56 throw soci_error(
"Cannot create error handle");
60 sb4 serviceNameLen =
static_cast<sb4
>(serviceName.size());
62 reinterpret_cast<text*>(const_cast<char*>(serviceName.c_str())),
63 serviceNameLen, OCI_DEFAULT);
64 if (res != OCI_SUCCESS)
74 res = OCIHandleAlloc(
envhp_, reinterpret_cast<dvoid**>(&
svchp_),
75 OCI_HTYPE_SVCCTX, 0, 0);
76 if (res != OCI_SUCCESS)
79 throw soci_error(
"Cannot create service context");
85 if (res != OCI_SUCCESS)
95 res = OCIHandleAlloc(
envhp_, reinterpret_cast<dvoid**>(&
usrhp_),
96 OCI_HTYPE_SESSION, 0, 0);
97 if (res != OCI_SUCCESS)
100 throw soci_error(
"Cannot allocate user session handle");
104 sb4 userNameLen =
static_cast<sb4
>(userName.size());
105 res = OCIAttrSet(
usrhp_, OCI_HTYPE_SESSION,
106 reinterpret_cast<dvoid*>(const_cast<char*>(userName.c_str())),
107 userNameLen, OCI_ATTR_USERNAME,
errhp_);
108 if (res != OCI_SUCCESS)
115 sb4 passwordLen =
static_cast<sb4
>(password.size());
116 res = OCIAttrSet(
usrhp_, OCI_HTYPE_SESSION,
117 reinterpret_cast<dvoid*>(const_cast<char*>(password.c_str())),
118 passwordLen, OCI_ATTR_PASSWORD,
errhp_);
119 if (res != OCI_SUCCESS)
127 OCI_CRED_RDBMS, mode);
128 if (res != OCI_SUCCESS)
139 0, OCI_ATTR_SESSION,
errhp_);
140 if (res != OCI_SUCCESS)
169 sword res = OCITransCommit(
svchp_,
errhp_, OCI_DEFAULT);
170 if (res != OCI_SUCCESS)
178 sword res = OCITransRollback(
svchp_,
errhp_, OCI_DEFAULT);
179 if (res != OCI_SUCCESS)
192 if (
usrhp_) { OCIHandleFree(
usrhp_, OCI_HTYPE_SESSION); }
193 if (
svchp_) { OCIHandleFree(
svchp_, OCI_HTYPE_SVCCTX); }
197 OCIHandleFree(
srvhp_, OCI_HTYPE_SERVER);
~oracle_session_backend()
oracle_session_backend(std::string const &serviceName, std::string const &userName, std::string const &password, int mode, bool decimals_as_strings=false)
virtual oracle_rowid_backend * make_rowid_backend()
void get_error_details(sword res, OCIError *errhp, std::string &msg, int &errNum)
void throw_oracle_soci_error(sword res, OCIError *errhp)
virtual oracle_statement_backend * make_statement_backend()
virtual oracle_blob_backend * make_blob_backend()