DCL 4.0
Loading...
Searching...
No Matches
IBConnection Class Reference

#include <IBConnection.h>

Inheritance diagram for IBConnection:
SQL::Connection Object

Public Member Functions

void setErrorStatus (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorStatus (const ByteString &_message, const wchar_t *_filename, int _line)
isc_db_handle * dbHandlePtr ()
isc_tr_handle * trHandlePtr ()
short dialect () const
ISC_STATUS * statusVector ()
 IBConnection (const wchar_t *_serverTitle)
virtual void destroy ()
virtual ~IBConnection ()
virtual bool __open (const char *_connString, size_t _connlen)
virtual bool __close ()
virtual bool __execute (const char *_sql, size_t _sqllen)
virtual bool __startTrans ()
virtual bool __commitTrans ()
virtual bool __rollbackTrans ()
virtual bool __createQueryInstance (SQL::Query **_queryHandleOut)
virtual bool __getErrorMessage (char *_buf, size_t *_buflen)
virtual bool __getServerInfo (char *_buf, size_t *_buflen)
Public Member Functions inherited from SQL::Connection
long refCount () const
long addRef ()
long release ()
bool open (const char *_connString, size_t _connlen)
bool close ()
bool execute (const char *_sql, size_t _sqllen)
bool startTrans ()
bool commitTrans ()
bool rollbackTrans ()
bool getErrorMessage (char *_pbuf, size_t *_pn)
bool getServerInfo (char *_pbuf, size_t *_pn)
bool createQueryInstance (Query **_queryHandleOut)
bool destroyQueryInstance (Query *_queryHandle)
Error errorCode () const
bool canTransact () const
const wchar_t * serverTitle () const
bool inState (unsigned int uState) const
Public Member Functions inherited from Object
virtual String toString () const
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Additional Inherited Members

Public Types inherited from SQL::Connection
enum  State { stClosed = 0x0001 , stOpenned = 0x0002 , stInTransaction = 0x0004 }
Static Public Member Functions inherited from SQL::Connection
static size_t splitConnectionString (const char *_connString, size_t _strlen, ListedByteStringToByteStringMap &_map)
Public Attributes inherited from SQL::Connection
__PROTECTED : void setErrorStatus(Error _errorCode
__PROTECTED const wchar_t * _filename
__PROTECTED const wchar_t int _line
Protected Member Functions inherited from SQL::Connection
 Connection (const wchar_t *_serverTitle)
virtual ~Connection ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()
Protected Attributes inherited from SQL::Connection
bool __canTransact
const wchar_t * __serverTitle
Error __errorCode
const wchar_t * __errorFileName
int __errorLine
unsigned int __states

Detailed Description

Definition at line 14 of file IBConnection.h.

Constructor & Destructor Documentation

◆ IBConnection()

IBConnection::IBConnection ( const wchar_t * _serverTitle)

◆ ~IBConnection()

IBConnection::~IBConnection ( )
virtual

Definition at line 39 of file IBConnection.cpp.

40{
41}

Member Function Documentation

◆ __close()

bool IBConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 166 of file IBConnection.cpp.

167{
168 __DCL_ASSERT(__dbHandle != NULL);
169 __DCL_ASSERT(__trHandle == NULL);
170
171 if (isc_detach_database(
172 __status,
173 &__dbHandle)
174 ) {
175// __DCL_ASSERT(STATUS_FAILED(__status));
177 return false;
178 }
179 __dbHandle = NULL;
180 return true;
181}
#define NULL
Definition Config.h:340
#define __SET_ERROR(_error)
#define __DCL_ASSERT(expr)
Definition Object.h:371
@ eServerError
Definition SQLCore.h:21

◆ __commitTrans()

bool IBConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 264 of file IBConnection.cpp.

265{
266 __DCL_ASSERT(__trHandle != NULL);
267 if(isc_commit_transaction(
268 __status,
269 &__trHandle)
270 ) {
271// __DCL_ASSERT(STATUS_FAILED(__status));
273 return false;
274 }
275 __trHandle = NULL;
276
277 return true;
278}

◆ __createQueryInstance()

bool IBConnection::__createQueryInstance ( SQL::Query ** _queryHandleOut)
virtual

Implements SQL::Connection.

Definition at line 296 of file IBConnection.cpp.

297{
298 __DCL_ASSERT(_queryHandleOut != NULL);
299
300 SQL::Query* pNewQuery = new IBQuery(this);
301 if (!pNewQuery) {
303 return false;
304 }
305
306 *_queryHandleOut = pNewQuery;
307 return true;
308}
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

bool IBConnection::__execute ( const char * _sql,
size_t _sqllen )
virtual

Implements SQL::Connection.

Definition at line 211 of file IBConnection.cpp.

212{
214 __DCL_ASSERT(__dbHandle != NULL);
215 if(isc_dsql_execute_immediate(
216 __status,
217 &__dbHandle,
218 &__trHandle,
219 (unsigned short int)n,
220 (_CONST char*)_sql,
221 __dialect,
222 NULL)
223 ) {
224// __DCL_ASSERT(STATUS_FAILED(__status));
226 return false;
227 }
228
229 switch (__GetStmtType(_sql)) {
230 case StmtTransBegin :
232 __DCL_ASSERT(__trHandle != NULL);
233 break;
234 case StmtTransEnd :
236 __trHandle = NULL;
237 break;
238 default :
239 ;
240 }
241
242 return true;
243}
#define UINT16_MAX
Definition Config.h:322
#define _CONST
Definition Config.h:353
@ StmtTransEnd
@ StmtTransBegin
#define __UNSET_STATE(state)
Definition SQLCore.h:431
#define __SET_STATE(state)
Definition SQLCore.h:430
void CharsetConvertException *size_t n
Definition SQLField.cpp:253

◆ __getErrorMessage()

bool IBConnection::__getErrorMessage ( char * _buf,
size_t * _buflen )
virtual

Implements SQL::Connection.

Definition at line 310 of file IBConnection.cpp.

311{
312 ByteStringBuilder sb;
313 if (!__lastErrorMessage.isEmpty())
314 sb = __lastErrorMessage;
315 else {
316 char sz[512];
317 ISC_STATUS* pStatus = __status;
318 long nLen = 0;
319 for(size_t i = 0; (nLen = isc_interprete(sz, &pStatus))
320 && (i < ISC_STATUS_VECTOR_LENGTH); i++) {
321 if (i > 0)
322 sb += ", ";
323 sb.append(sz, 0, nLen);
324 }
325 }
326
327 if (sb.length() < *_buflen)
328 *_buflen = sb.length();
329
330 strncpy(_buf, sb.data(), *_buflen);
331
332 return true;
333}
#define ISC_STATUS_VECTOR_LENGTH
Definition IBConnection.h:6

◆ __getServerInfo()

bool IBConnection::__getServerInfo ( char * _buf,
size_t * _buflen )
virtual

Implements SQL::Connection.

Definition at line 341 of file IBConnection.cpp.

342{
343 char buffer[512];
344 if (isc_database_info (
345 __status,
346 &__dbHandle,
347 sizeof(database_info_items),
348 database_info_items,
349 sizeof(buffer),
350 buffer)) {
352 return false;
353 }
354
355 ByteString strVersion;
356 ByteString strDb;
357 ByteString strSite;
358
359 char* p = buffer;
360 char item;
361 unsigned short length;
362 __DCL_ASSERT(sizeof(unsigned short) == 2);
363 while(*p != isc_info_end) {
364 item = *p++;
365 length = (unsigned short)isc_vax_integer(p, 2);
366 p += 2;
367 if (item == isc_info_version) {
368 // __DCL_ASSERT(p[0] == 1);
369 //__DCL_TRACE1(L"[%d]\n", p[0]);
370 strVersion.assign(p, 2, p[1]);
371 }
372 else if (item == isc_info_db_id) {
373 char* t = p;
374 //__DCL_TRACE1(L"[%d]\n", *t);
375 //__DCL_ASSERT(*t == 2);
376 t++;
377 unsigned short nStrLen = *t++;
378 strDb.assign(t, nStrLen);
379 t += nStrLen;
380 nStrLen = *t++;
381 strSite.assign(t, nStrLen);
382 }
383 else {
385 return false;
386 }
387 p += length;
388 }
389
390 ByteString strInfo = "InterBase " + strVersion + " \"" + strSite + ':' + strDb + "\"";
391 if (strInfo.length() < *_buflen)
392 *_buflen = strInfo.length();
393
394 strncpy(_buf, strInfo.data(), *_buflen);
395 return true;
396}
@ eNotAvailable
Definition SQLCore.h:38

◆ __open()

bool IBConnection::__open ( const char * _connString,
size_t _connlen )
virtual

Implements SQL::Connection.

Definition at line 62 of file IBConnection.cpp.

63{
64 try {
65 if (Regex::test(__createDatabasePattern__, _connString, true)) {
66 // CREATE DATABASE
67 if(isc_dsql_execute_immediate(
68 __status,
69 &__dbHandle,
70 &__trHandle,
71 0,
72 (_CONST char*)_connString,
73 __dialect,
74 NULL)) {
76 return false;
77 }
78 return true;
79 }
80 }
81 catch(RegexException* e) {
82 e->destroy();
83 }
84
85 ListedByteStringToByteStringMap map;
86 Connection::splitConnectionString(_connString, _connlen, map);
87
88 ByteString strServer = map["SERVER"];
89 ByteString strDatabase = map["DATABASE"];
90 ByteString strUser = map["USER"];
91 ByteString strPassword = map["PASSWORD"];
92 ByteString strSqlDialect = map["SQL_DIALECT"];
93
94 if (!strSqlDialect.isEmpty()) {
95 int nDialect = SQL_DIALECT_CURRENT;
96 char* endptr;
97 long n = strtol(strSqlDialect, &endptr, 10);
98 if (n == LONG_MAX || n == LONG_MIN
99 || n < INT_MIN || INT_MAX < n
100 ) {
101 __SET_ERROR_MSG("연결 문자열이 잘못되었습니다. SQL_DIALECT="
102 + strSqlDialect);
103 return false;
104 }
105
106 nDialect = (int)n;
107
108 if (!(nDialect == SQL_DIALECT_V5
109 || nDialect == SQL_DIALECT_V6_TRANSITION
110 || nDialect == SQL_DIALECT_V6)) {
111 __SET_ERROR_MSG("\"SQL_DIALECT\"- invalid value");
112 return false;
113 }
114
115 __dialect = nDialect;
116 }
117
118 if ((strUser.length() > 127) || (strPassword.length() > 127)) {
119 // USER NAME 과 PASSWORD 의 길이는 127을 넘을 수 없다.
121 return false;
122 }
123
124 ByteString strDatabaseEnv;
125 if (!strServer.isEmpty())
126 strDatabaseEnv = strServer + ":";
127
128 if (!strDatabase.isEmpty())
129 strDatabaseEnv = strDatabaseEnv + strDatabase;
130
131 if (strDatabaseEnv.isEmpty()) {
133 return false;
134 }
135
136 // database parameter block
137 ByteStringBuilder dpb;
138 dpb = (char)isc_dpb_version1;
139 dpb += (char)isc_dpb_user_name;
140 dpb += (char)strUser.length();
141 dpb += strUser;
142 dpb += (char)isc_dpb_password;
143 dpb += (char)strPassword.length();
144 dpb += strPassword;
145
146 dpb += (char)isc_dpb_lc_ctype;
147 dpb += (char)4;
148 dpb += "UTF8";
149
150 if (isc_attach_database(
151 __status,
152 strDatabaseEnv.length(),
153 (_CONST char*)strDatabaseEnv.data(),
154 &__dbHandle,
155 dpb.length(),
156 (_CONST char*)dpb.data())
157 ) {
158// __DCL_ASSERT(STATUS_FAILED(__status));
160 __dbHandle = NULL;
161 return false;
162 }
163 return true;
164}
#define __SET_ERROR_MSG(str)
virtual void destroy()
Definition Exception.cpp:74
static bool test(const wchar_t *_regex, const wchar_t *_string, bool _icase=false) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:252
@ eInvalidConnectionString
Definition SQLCore.h:31

◆ __rollbackTrans()

bool IBConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 280 of file IBConnection.cpp.

281{
282 __DCL_ASSERT(__trHandle != NULL);
283 if(isc_rollback_transaction(
284 __status,
285 &__trHandle)
286 ) {
287// __DCL_ASSERT(STATUS_FAILED(__status));
289 return false;
290 }
291 __trHandle = NULL;
292
293 return true;
294}

◆ __startTrans()

bool IBConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 245 of file IBConnection.cpp.

246{
247 __DCL_ASSERT(__trHandle == NULL);
248 if (isc_start_transaction(
249 __status,
250 &__trHandle,
251 1,
252 &__dbHandle,
253 0,
254 NULL)
255 ) {
256// __DCL_ASSERT(STATUS_FAILED(__status));
258 return false;
259 }
260
261 return true;
262}

◆ dbHandlePtr()

isc_db_handle * IBConnection::dbHandlePtr ( )
inline

Definition at line 30 of file IBConnection.h.

30{ return &__dbHandle; }

◆ destroy()

void IBConnection::destroy ( )
virtual

파생클래스에서 new 연산자를 override했거나, 추가적인 행위가 필요하다면 이것도 override하라

Implements SQL::Connection.

Definition at line 43 of file IBConnection.cpp.

44{
45// cerr << "IBConnection::destory\n";
46 delete this;
47}

◆ dialect()

short IBConnection::dialect ( ) const
inline

Definition at line 32 of file IBConnection.h.

32{ return __dialect; }

◆ setErrorStatus() [1/2]

void IBConnection::setErrorStatus ( const ByteString & _message,
const wchar_t * _filename,
int _line )
inline

Definition at line 59 of file IBConnection.h.

61{
62 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
63 __lastErrorMessage = _message;
64}
__PROTECTED const wchar_t int _line
Definition SQLCore.h:390
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:390

◆ setErrorStatus() [2/2]

void IBConnection::setErrorStatus ( SQL::Error _error,
const wchar_t * _filename,
int _line )
inline

Definition at line 52 of file IBConnection.h.

54{
55 Connection::setErrorStatus(_error, _filename, _line);
56 __lastErrorMessage.clear();
57}

◆ statusVector()

ISC_STATUS * IBConnection::statusVector ( )
inline

Definition at line 33 of file IBConnection.h.

33{ return __status; }

◆ trHandlePtr()

isc_tr_handle * IBConnection::trHandlePtr ( )
inline

Definition at line 31 of file IBConnection.h.

31{ return &__trHandle; }

The documentation for this class was generated from the following files: