|
Session Class ReferenceODBC connection w/ busy state flag.
More...
#include <Session.h>
Collaboration diagram for Session:
List of all members.
Detailed Description
ODBC connection w/ busy state flag.
Definition at line 37 of file Session.h.
Constructor & Destructor Documentation
Session::~Session |
( |
|
) |
[virtual] |
|
Member Function Documentation
int Session::Connect |
( |
Database & |
, |
|
|
const std::string & |
, |
|
|
const std::string & |
, |
|
|
const std::string & |
|
|
) |
|
|
|
Definition at line 148 of file Session.cpp.
References Database::error(), m_hdbc, m_henv, and ShowErrorInfo(). 00149 {
00150 SQLRETURN retcode;
00151 int value;
00152
00153 if (!m_henv)
00154 {
00155
00156 retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_henv);
00157 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00158 {
00159 ShowErrorInfo(retcode, SQL_HANDLE_ENV, m_henv);
00160 }
00161 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00162 {
00163 db.error("Allocate environment handle (ENV) failed");
00164 return -1;
00165 }
00166
00167
00168 retcode = SQLSetEnvAttr(m_henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
00169 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00170 {
00171 ShowErrorInfo(retcode, SQL_HANDLE_ENV, m_henv);
00172 }
00173 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00174 {
00175 db.error("Set the ODBC version environment attribute failed");
00176 return -2;
00177 }
00178 }
00179
00180
00181 retcode = SQLAllocHandle(SQL_HANDLE_DBC, m_henv, &m_hdbc);
00182 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00183 {
00184 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00185 }
00186 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00187 {
00188 db.error("Allocate connection handle (DBC) failed");
00189 return -3;
00190 }
00191
00192
00193 value = 5;
00194 SQLSetConnectAttr(m_hdbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)&value, 0);
00195 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00196 {
00197 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00198 }
00199
00200
00201 retcode = SQLConnect(m_hdbc,
00202 (SQLCHAR*) dsn.c_str(), SQL_NTS,
00203 (SQLCHAR*) user.c_str(), SQL_NTS,
00204 (SQLCHAR*) password.c_str(), SQL_NTS);
00205
00206 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00207 {
00208 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00209 }
00210 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00211 {
00212 db.error("Connect to data source failed");
00213 db.error(dsn);
00214 return -4;
00215 }
00216
00217
00218
00219 return 0;
00220 }
|
int Session::Connect |
( |
Database & |
, |
|
|
const std::string & |
|
|
) |
|
|
|
Definition at line 62 of file Session.cpp.
References Database::error(), m_hdbc, m_henv, and ShowErrorInfo(). 00063 {
00064 SQLRETURN retcode;
00065 int value;
00066
00067 if (!m_henv)
00068 {
00069
00070 retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_henv);
00071 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00072 {
00073 ShowErrorInfo(retcode, SQL_HANDLE_ENV, m_henv);
00074 }
00075 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00076 {
00077 db.error("Allocate environment handle (ENV) failed");
00078 return -1;
00079 }
00080
00081
00082 retcode = SQLSetEnvAttr(m_henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
00083 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00084 {
00085 ShowErrorInfo(retcode, SQL_HANDLE_ENV, m_henv);
00086 }
00087 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00088 {
00089 db.error("Set the ODBC version environment attribute failed");
00090 return -2;
00091 }
00092 }
00093
00094
00095 retcode = SQLAllocHandle(SQL_HANDLE_DBC, m_henv, &m_hdbc);
00096 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00097 {
00098 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00099 }
00100 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00101 {
00102 db.error("Allocate connection handle (DBC) failed");
00103 return -3;
00104 }
00105
00106
00107 value = 5;
00108 SQLSetConnectAttr(m_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)&value, 0);
00109 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00110 {
00111 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00112 }
00113
00114
00115 {
00116 unsigned char slask[1024];
00117 SQLSMALLINT cbl = 0;
00118
00119 *slask = 0;
00120 retcode = SQLDriverConnect(m_hdbc, NULL,
00121 (unsigned char *)driverstring.c_str(), (SQLSMALLINT)driverstring.size(),
00122 slask, 1024, &cbl, SQL_DRIVER_PROMPT);
00123
00124 if (cbl >= 0 && cbl < 1024)
00125 {
00126 slask[cbl] = 0;
00127 }
00128
00129
00130 if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
00131 {
00132 ShowErrorInfo(retcode, SQL_HANDLE_DBC, m_hdbc);
00133 }
00134 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
00135 {
00136 db.error("Connect to data source failed");
00137 db.error(driverstring);
00138 return -4;
00139 }
00140 }
00141
00142
00143
00144 return 0;
00145 }
|
void Session::Disconnect |
( |
|
) |
|
|
void * Session::GetHandle |
( |
|
) |
|
|
int Session::GetLastError |
( |
std::string & |
strSqlState, |
|
|
std::string & |
strErrorMessage |
|
) |
|
|
void Session::ResetLastError |
( |
|
) |
|
|
void Session::SetBusy |
( |
bool |
|
) |
|
|
void Session::ShowErrorInfo |
( |
SQLRETURN |
, |
|
|
SQLSMALLINT |
, |
|
|
SQLHANDLE |
|
|
) |
|
|
|
Definition at line 265 of file Session.cpp.
References m_nLastError, m_strLastErrorMessage, m_strLastErrorSqlState, and REM_LEN.
Referenced by Connect(). 00266 {
00267 SQLRETURN retcode;
00268 SQLSMALLINT iRecord = 1;
00269 SQLCHAR szSqlState[REM_LEN];
00270 SQLINTEGER pfNativeError;
00271 SQLCHAR szErrorMsg[REM_LEN];
00272 SQLSMALLINT cbErrorMsgMax = REM_LEN - 1;
00273 SQLSMALLINT pcbErrorMsg;
00274
00275
00276
00277
00278
00279
00280 retcode = SQLGetDiagRec (hType, h,
00281 iRecord, szSqlState, &pfNativeError,
00282 szErrorMsg, cbErrorMsgMax, &pcbErrorMsg);
00283
00284
00285
00286
00287
00288
00289
00290 if (m_nLastError == 0)
00291 {
00292 m_nLastError = rc;
00293 m_strLastErrorSqlState = (char*)szSqlState;
00294 m_strLastErrorMessage = (char*)szErrorMsg;
00295 }
00296
00297 }
|
Member Data Documentation
The documentation for this class was generated from the following files:
|