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

#include <IBConnection.h>

Inheritance diagram for IBConnection:
SQL::Connection Object

Public Member Functions

void setErrorHandle (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorMessage (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 *_conns, 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 *_conn, size_t _connlen)
bool close ()
bool execute (const char *_sql, size_t _sqllen)
bool startTrans ()
bool commitTrans ()
bool rollbackTrans ()
bool getErrorMessage (char *_buf, size_t *_buflen)
bool getServerInfo (char *_buf, size_t *_buflen)
bool createQueryInstance (Query **_queryHandle)
bool destroyQueryInstance (Query *_queryHandle)
Error errorCode () const
bool canTransact () const
const wchar_t * serverTitle () const
bool inState (unsigned int _state) 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 splitConnStr (const char *_connstr, size_t _strlen, ListedByteStringToByteStringMap &_results)
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 16 of file IBConnection.h.

Constructor & Destructor Documentation

◆ IBConnection()

IBConnection::IBConnection ( const wchar_t * _serverTitle)

◆ ~IBConnection()

IBConnection::~IBConnection ( )
virtual

Definition at line 59 of file IBConnection.cpp.

60{
61 if (__dbHandle) {
62 __DCL_TRACE0_N(L"Warning!! The connection was not closed\n");
63 close();
64 }
65}
#define __DCL_TRACE0_N(fmt)

Member Function Documentation

◆ __close()

bool IBConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 207 of file IBConnection.cpp.

208{
209 if (!__dbHandle) {
211 return false;
212 }
213 __DCL_ASSERT(__trHandle == NULL_HANDLE);
214
215 if (isc_detach_database(
216 __status,
217 &__dbHandle
218 )) {
219// __DCL_ASSERT(STATUS_FAILED(__status));
221 return false;
222 }
223 __dbHandle = NULL_HANDLE;
224 return true;
225}
#define NULL_HANDLE
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
@ eServerError
Definition SQLCore.h:21
@ eNotConnected
Definition SQLCore.h:33

◆ __commitTrans()

bool IBConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 308 of file IBConnection.cpp.

309{
310 __DCL_ASSERT(__trHandle != NULL_HANDLE);
311 if(isc_commit_transaction(
312 __status,
313 &__trHandle
314 )) {
315// __DCL_ASSERT(STATUS_FAILED(__status));
317 return false;
318 }
319 __trHandle = NULL_HANDLE;
320
321 return true;
322}

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 340 of file IBConnection.cpp.

341{
342 __DCL_ASSERT(_queryHandleOut != NULL);
343
344 SQL::Query* newQuery = new IBQuery(this);
345 if (!newQuery) {
347 return false;
348 }
349
350 *_queryHandleOut = newQuery;
351 return true;
352}
#define NULL
Definition Config.h:312
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

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

Implements SQL::Connection.

Definition at line 255 of file IBConnection.cpp.

256{
258 __DCL_ASSERT(__dbHandle != NULL_HANDLE);
259 if(isc_dsql_execute_immediate(
260 __status,
261 &__dbHandle,
262 &__trHandle,
263 (unsigned short int)n,
264 (_CONST char*)_sql,
265 __dialect,
266 NULL
267 )) {
268// __DCL_ASSERT(STATUS_FAILED(__status));
270 return false;
271 }
272
273 switch (__GetStmtType(_sql)) {
274 case StmtTransBegin :
276 __DCL_ASSERT(__trHandle != NULL_HANDLE);
277 break;
278 case StmtTransEnd :
280 __trHandle = NULL_HANDLE;
281 break;
282 default :
283 ;
284 }
285
286 return true;
287}
#define UINT16_MAX
Definition Config.h:294
#define _CONST
Definition Config.h:325
@ StmtTransEnd
@ StmtTransBegin
#define __UNSET_STATE(state)
Definition SQLCore.h:483
#define __SET_STATE(state)
Definition SQLCore.h:482

◆ __getErrorMessage()

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

Implements SQL::Connection.

Definition at line 354 of file IBConnection.cpp.

355{
356 ByteStringBuilder sb;
357 if (!__lastErrorMessage.isEmpty())
358 sb = __lastErrorMessage;
359 else {
360 char buf[512];
361 ISC_STATUS* status = __status;
362 size_t len = 0;
363#ifdef FIREBIRD_IBASE_H
364#define isc_interprete(buf, pp) fb_interpret(buf, sizeof(buf), (const ISC_STATUS**) pp)
365#endif
366 for(size_t i = 0; (len = isc_interprete(buf, &status))
367 && (i < ISC_STATUS_VECTOR_LENGTH); i++) {
368 if (i > 0)
369 sb += ", ";
370 sb.append(buf, 0, len);
371 }
372 }
373
374 if (sb.length() < *_buflen) {
375 *_buflen = sb.length();
376 *(_buf + *_buflen) = '\0';
377 }
378 strncpy(_buf, sb.data(), *_buflen);
379 return true;
380}
#define ISC_STATUS_VECTOR_LENGTH

◆ __getServerInfo()

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

Implements SQL::Connection.

Definition at line 388 of file IBConnection.cpp.

389{
390 char buffer[512];
391 if (isc_database_info (
392 __status,
393 &__dbHandle,
394 sizeof(database_info_items),
395 database_info_items,
396 sizeof(buffer),
397 buffer
398 )) {
400 return false;
401 }
402
403 ByteString version;
404 ByteString dbId;
405 ByteString site;
406
407 char* p = buffer;
408 char item;
409 unsigned short length;
410 __DCL_ASSERT(sizeof(unsigned short) == 2);
411 while(*p != isc_info_end) {
412 item = *p++;
413 length = (unsigned short)isc_vax_integer(p, 2);
414 p += 2;
415 if (item == isc_info_version) {
416 // __DCL_ASSERT(p[0] == 1);
417 //__DCL_TRACE1(L"[%d]\n", p[0]);
418 version.assign(p, 2, p[1]);
419 }
420 else if (item == isc_info_db_id) {
421 char* t = p;
422 //__DCL_TRACE1(L"[%d]\n", *t);
423 //__DCL_ASSERT(*t == 2);
424 t++;
425 unsigned short strlen = *t++;
426 dbId.assign(t, strlen);
427 t += strlen;
428 strlen = *t++;
429 site.assign(t, strlen);
430 }
431 else {
433 return false;
434 }
435 p += length;
436 }
437
438 ByteString info =
439#ifndef FIREBIRD_IBASE_H
440 "InterBase " + version
441#else
442 version
443#endif
444 // +" \"" + site + ':' + dbId + "\""
445 ;
446
447 if (info.length() < *_buflen)
448 *_buflen = info.length();
449
450 strncpy(_buf, info.data(), *_buflen);
451 return true;
452}
@ eNotAvailable
Definition SQLCore.h:38

◆ __open()

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

Implements SQL::Connection.

Definition at line 85 of file IBConnection.cpp.

86{
87 try {
88 if (Regex::test(__createDatabasePattern__, _conns, true)) {
89 // CREATE DATABASE
90 if(isc_dsql_execute_immediate(
91 __status,
92 &__dbHandle,
93 &__trHandle,
94 0,
95 (_CONST char*)_conns,
96 __dialect,
97 NULL
98 )) {
100 return false;
101 }
102 return true;
103 }
104 }
105 catch(RegexException* e) {
106 e->destroy();
107 }
108
109 ListedByteStringToByteStringMap map;
110 Connection::splitConnStr(_conns, _connlen, map);
111
112 ByteString _SERVER = map["SERVER"];
113 ByteString _DATABASE = map["DATABASE"];
114 ByteString _USER = map["USER"];
115 ByteString _PASSWORD = map["PASSWORD"];
116 ByteString _SQL_DIALECT = map["SQL_DIALECT"];
117
118 if (!_SQL_DIALECT.isEmpty()) {
119 int nDialect = SQL_DIALECT_CURRENT;
120 char* endptr;
121 long n = strtol(_SQL_DIALECT, &endptr, 10);
122 if (n == LONG_MAX || n == LONG_MIN
123 || n < INT_MIN || INT_MAX < n
124 ) {
125 __SET_ERROR_MSG("연결 문자열이 잘못되었습니다. SQL_DIALECT="
126 + _SQL_DIALECT);
127 return false;
128 }
129
130 nDialect = (int)n;
131
132 if (!(nDialect == SQL_DIALECT_V5
133 || nDialect == SQL_DIALECT_V6_TRANSITION
134 || nDialect == SQL_DIALECT_V6)
135 ) {
136 __SET_ERROR_MSG("\"SQL_DIALECT\"- invalid value");
137 return false;
138 }
139
140 __dialect = nDialect;
141 }
142
143 if ((_USER.length() > 127) || (_PASSWORD.length() > 127)) {
144 // USER NAME 과 PASSWORD 의 길이는 127을 넘을 수 없다.
146 return false;
147 }
148
149 ByteString dbEnv;
150 if (!_SERVER.isEmpty())
151 dbEnv = _SERVER + ":";
152
153 if (!_DATABASE.isEmpty())
154 dbEnv = dbEnv + _DATABASE;
155
156 if (dbEnv.isEmpty()) {
158 return false;
159 }
160
161 // database parameter block
162 ByteStringBuilder dpb;
163 dpb = (char)isc_dpb_version1;
164 dpb += (char)isc_dpb_user_name;
165 dpb += (char)_USER.length();
166 dpb += _USER;
167 dpb += (char)isc_dpb_password;
168 dpb += (char)_PASSWORD.length();
169 dpb += _PASSWORD;
170
171 static const char __UTF8__[] = "UTF8";
172 dpb += (char)isc_dpb_lc_ctype;
173 dpb += (char)(sizeof(__UTF8__) - 1);
174 dpb += __UTF8__;
175
176#if defined(FIREBIRD_IBASE_H) && FB_API_VER >= 40
177 static const char __SET_BIND__[] =
178 "DECFLOAT TO VARCHAR;" // 20
179 "INT128 TO VARCHAR;" // 18
180 "TIME ZONE TO EXTENDED"; // 21
181 dpb += (char)isc_dpb_set_bind;
182 dpb += (char)(sizeof(__SET_BIND__) - 1);
183 dpb += __SET_BIND__;
184#endif
185
186#ifdef FIREBIRD_IBASE_H
187 #undef _CONST
188 #define _CONST const
189#endif
190
191 if (isc_attach_database(
192 __status,
193 (short) dbEnv.length(),
194 (_CONST char*) dbEnv.data(),
195 &__dbHandle,
196 (short) dpb.length(),
197 (_CONST char*) dpb.data())
198 ) {
199// __DCL_ASSERT(STATUS_FAILED(__status));
201 __dbHandle = NULL_HANDLE;
202 return false;
203 }
204 return true;
205}
#define __SET_ERROR_MSG(_message)
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:250
@ eInvalidConnectionString
Definition SQLCore.h:31

◆ __rollbackTrans()

bool IBConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 324 of file IBConnection.cpp.

325{
326 __DCL_ASSERT(__trHandle != NULL_HANDLE);
327 if(isc_rollback_transaction(
328 __status,
329 &__trHandle
330 )) {
331// __DCL_ASSERT(STATUS_FAILED(__status));
333 return false;
334 }
335 __trHandle = NULL_HANDLE;
336
337 return true;
338}

◆ __startTrans()

bool IBConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 289 of file IBConnection.cpp.

290{
291 __DCL_ASSERT(__trHandle == NULL_HANDLE);
292 if (isc_start_transaction(
293 __status,
294 &__trHandle,
295 1,
296 &__dbHandle,
297 0,
298 NULL
299 )) {
300// __DCL_ASSERT(STATUS_FAILED(__status));
302 return false;
303 }
304
305 return true;
306}

◆ dbHandlePtr()

isc_db_handle * IBConnection::dbHandlePtr ( )
inline

Definition at line 37 of file IBConnection.h.

37{ return &__dbHandle; }

◆ destroy()

void IBConnection::destroy ( )
virtual

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

Implements SQL::Connection.

Definition at line 67 of file IBConnection.cpp.

68{
69 delete this;
70}

◆ dialect()

short IBConnection::dialect ( ) const
inline

Definition at line 39 of file IBConnection.h.

39{ return __dialect; }

◆ setErrorHandle()

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

Definition at line 59 of file IBConnection.h.

63{
64 Connection::setErrorStatus(_error, _filename, _line);
65 __lastErrorMessage.clear();
66}
_PROTECTED const wchar_t * _filename
Definition SQLCore.h:439
_PROTECTED const wchar_t int _line
Definition SQLCore.h:441

◆ setErrorMessage()

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

Definition at line 68 of file IBConnection.h.

72{
73 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
74 __lastErrorMessage = _message;
75}

◆ statusVector()

ISC_STATUS * IBConnection::statusVector ( )
inline

Definition at line 40 of file IBConnection.h.

40{ return __status; }

◆ trHandlePtr()

isc_tr_handle * IBConnection::trHandlePtr ( )
inline

Definition at line 38 of file IBConnection.h.

38{ return &__trHandle; }

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