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

#include <IFXConnection.h>

Inheritance diagram for IFXConnection:
SQL::Connection Object

Public Member Functions

void setErrorStatus (SQL::Error _error, long _SQLCODE, const wchar_t *_filename, int _line)
void setErrorStatus (const ByteString &_message, const wchar_t *_filename, int _line)
_CONST char * connectionID () const
virtual void destroy ()
 IFXConnection (const wchar_t *_serverTitle)
virtual ~IFXConnection ()
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 6 of file IFXConnection.h.

Constructor & Destructor Documentation

◆ IFXConnection()

IFXConnection::IFXConnection ( const wchar_t * _serverTitle)

Definition at line 46 of file IFXConnection.cpp.

47 : Connection(_serverTitle)
48{
49 __connectionID = ByteString::format("con:%ld", Thread::incrementAndGet(__connectionID__));
50}
Connection(const wchar_t *_serverTitle)
Definition SQLCore.cpp:653
static long incrementAndGet(volatile long &_n)

◆ ~IFXConnection()

IFXConnection::~IFXConnection ( )
virtual

Definition at line 52 of file IFXConnection.cpp.

53{
54}

Member Function Documentation

◆ __close()

bool IFXConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 178 of file IFXConnection.cpp.

179{
180/*
181 * EXEC SQL BEGIN DECLARE SECTION;
182 */
183#line 125 "ifxconnection.ec"
184#line 126 "ifxconnection.ec"
185 char *pszConnectionID = (_CONST char*) __connectionID.data();
186/*
187 * EXEC SQL END DECLARE SECTION;
188 */
189#line 127 "ifxconnection.ec"
190
191
192/*
193 * EXEC SQL DISCONNECT :pszConnectionID;
194 */
195#line 129 "ifxconnection.ec"
196 {
197#line 129 "ifxconnection.ec"
198 sqli_connect_close(0, pszConnectionID, 0, 0);
199#line 129 "ifxconnection.ec"
200 }
201 if (SQLCODE < 0) {
202 __SET_ERROR_SQLCODE(SQLCODE);
203 return false;
204 }
205
206 return true;
207}
#define _CONST
Definition Config.h:353
#define __SET_ERROR_SQLCODE(SQLCODE)

◆ __commitTrans()

bool IFXConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 349 of file IFXConnection.cpp.

350{
351/*
352 * EXEC SQL BEGIN DECLARE SECTION;
353 */
354#line 232 "ifxconnection.ec"
355#line 233 "ifxconnection.ec"
356 char *pszConnectionID = (_CONST char*) __connectionID.data();
357/*
358 * EXEC SQL END DECLARE SECTION;
359 */
360#line 234 "ifxconnection.ec"
361
362
363/*
364 * EXEC SQL SET CONNECTION :pszConnectionID;
365 */
366#line 236 "ifxconnection.ec"
367 {
368#line 236 "ifxconnection.ec"
369 sqli_connect_set(0, pszConnectionID, 0);
370#line 236 "ifxconnection.ec"
371 }
372 if (SQLCODE < 0) {
373 __SET_ERROR_SQLCODE(SQLCODE);
374 return false;
375 }
376
377/*
378 * EXEC SQL COMMIT WORK;
379 */
380#line 242 "ifxconnection.ec"
381 {
382#line 242 "ifxconnection.ec"
383 sqli_trans_commit();
384#line 242 "ifxconnection.ec"
385 }
386 if (SQLCODE < 0) {
387 __SET_ERROR_SQLCODE(SQLCODE);
388 return false;
389 }
390
392 return true;
393}
#define __UNSET_STATE(state)
Definition SQLCore.h:431

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 441 of file IFXConnection.cpp.

442{
443 __DCL_ASSERT(_queryHandleOut != NULL);
444
445 SQL::Query* pNewQuery = new IFXQuery(this);
446 if (!pNewQuery) {
448 return false;
449 }
450
451 *_queryHandleOut = pNewQuery;
452 return true;
453}
#define NULL
Definition Config.h:340
#define __SET_ERROR(_error)
#define __DCL_ASSERT(expr)
Definition Object.h:371
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

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

Implements SQL::Connection.

Definition at line 242 of file IFXConnection.cpp.

243{
244/*
245 * EXEC SQL BEGIN DECLARE SECTION;
246 */
247#line 173 "ifxconnection.ec"
248#line 174 "ifxconnection.ec"
249 char *pszConnectionID = (_CONST char*) __connectionID.data();
250 char *pszSqlStatement = (_CONST char*) _sql;
251/*
252 * EXEC SQL END DECLARE SECTION;
253 */
254#line 176 "ifxconnection.ec"
255
256
257/*
258 * EXEC SQL SET CONNECTION :pszConnectionID;
259 */
260#line 178 "ifxconnection.ec"
261 {
262#line 178 "ifxconnection.ec"
263 sqli_connect_set(0, pszConnectionID, 0);
264#line 178 "ifxconnection.ec"
265 }
266 if (SQLCODE < 0) {
267 __SET_ERROR_SQLCODE(SQLCODE);
268 return false;
269 }
270
271/*
272 * EXEC SQL EXECUTE IMMEDIATE :pszSqlStatement;
273 */
274#line 184 "ifxconnection.ec"
275 {
276#line 184 "ifxconnection.ec"
277 sqli_exec_immed(pszSqlStatement);
278#line 184 "ifxconnection.ec"
279 }
280 if (SQLCODE < 0) {
281 __SET_ERROR_SQLCODE(SQLCODE);
282 return false;
283 }
284
285 switch(__GetStmtType(_sql)) {
286 case StmtTransBegin :
288 break;
289 case StmtTransEnd :
291 break;
292 case StmtDatabase :
293 reset();
294 break;
295 case StmtOther :
296 default :
297 ;
298 }
299
300 return true;
301}
@ StmtTransEnd
@ StmtOther
@ StmtTransBegin
@ StmtDatabase
#define __SET_STATE(state)
Definition SQLCore.h:430

◆ __getErrorMessage()

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

Implements SQL::Connection.

Definition at line 503 of file IFXConnection.cpp.

504{
505 __DCL_ASSERT(Connection::__errorCode == SQL::eServerError);
506 if (__lastErrorMessage.length() < *_buflen)
507 *_buflen = __lastErrorMessage.length();
508 strncpy(_buf, __lastErrorMessage.data(), *_buflen);
509 return true;
510}
@ eServerError
Definition SQLCore.h:21

◆ __getServerInfo()

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

Implements SQL::Connection.

Definition at line 512 of file IFXConnection.cpp.

513{
514 IFXQuery* pQuery = new IFXQuery(this);
515 if (pQuery == NULL) {
517 return false;
518 }
519
520 bool localTrans = false;
522 __startTrans();
523 localTrans = true;
524 }
525
526 const char* _sql =
527 "SELECT DBINFO('version', 'full')"
528 " FROM systables WHERE tabid = 1";
529 for (; ; ) {
530 if (!pQuery->prepare(_sql, ByteString::length(_sql), 0))
531 break;
532
533 if (!pQuery->execute())
534 break;
535
536 if (!pQuery->fetch())
537 break;
538
539 if (pQuery->eof()) {
541 break;
542 }
543
544 IFXField* pField = NULL;
545 if (!pQuery->__getField(0, (SQL::Field**)&pField))
546 break;
547
548 if (pField->isNull()) {
550 break;
551 }
552
553 if (!pField->__getData(_buf, _buflen, SQL::typeText))
554 break;
555
556 pQuery->__destroy();
557 pQuery = NULL;
558
559 if (localTrans) {
561 }
562 return true;
563 }
564
565 if (pQuery) {
566 pQuery->__destroy();
567 }
568
569 if (localTrans) {
571 }
572 return false;
573}
virtual bool __startTrans()
virtual bool __commitTrans()
virtual bool __rollbackTrans()
virtual bool __getField(size_t _index, SQL::Field **_fieldHandleOut)
Definition IFXQuery.cpp:696
virtual void __destroy()
Definition IFXQuery.cpp:116
bool inState(unsigned int uState) const
Definition SQLCore.inl:99
virtual bool __getData(void *_pv, size_t *_pn, DataType _dataType)=0
virtual bool isNull() const =0
@ typeText
Definition SQLCore.h:75
@ eNotAvailable
Definition SQLCore.h:38

◆ __open()

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

Implements SQL::Connection.

Definition at line 120 of file IFXConnection.cpp.

121{
122 ListedByteStringToByteStringMap map;
123 Connection::splitConnectionString(_connString, _connlen, map);
124
125 ByteString strServer = map["SERVER"];
126 ByteString strUser = map["USER"];
127 ByteString strPassword = map["PASSWORD"];
128 ByteString strDatabase = map["DATABASE"];
129
130 ByteString strDatabaseEnv = strDatabase;
131 if (!strServer.isEmpty()) {
132 strDatabaseEnv = strDatabaseEnv + "@" + strServer;
133 }
134 //__DCL_TRACE1(L"[%hs]\n", strDatabaseEnv.data());
135
136/*
137 * EXEC SQL BEGIN DECLARE SECTION;
138 */
139#line 100 "ifxconnection.ec"
140#line 101 "ifxconnection.ec"
141 char *pszUserName = (_CONST char*) strUser.data();
142 char *pszPassword = (_CONST char*) strPassword.data();
143 char *pszDatabaseEnv = (_CONST char*) strDatabaseEnv.data();
144 char *pszConnectionID = NULL;
145/*
146 * EXEC SQL END DECLARE SECTION;
147 */
148#line 105 "ifxconnection.ec"
149
150
151 pszConnectionID = (_CONST char*) __connectionID.data();
152
153/*
154 * EXEC SQL CONNECT TO :pszDatabaseEnv AS :pszConnectionID
155 * USER :pszUserName USING :pszPassword
156 * WITH CONCURRENT TRANSACTION;
157 */
158#line 109 "ifxconnection.ec"
159 {
160#line 111 "ifxconnection.ec"
161 ifx_conn_t *_sqiconn;
162 _sqiconn = (ifx_conn_t *)ifx_alloc_conn_user(pszUserName, pszPassword);
163 sqli_connect_open(ESQLINTVERSION, 0, pszDatabaseEnv, pszConnectionID, _sqiconn, 1);
164 ifx_free_conn_user(&_sqiconn);
165#line 111 "ifxconnection.ec"
166 }
167 if (SQLCODE < 0) {
168 __SET_ERROR_SQLCODE(SQLCODE);
169 return false;
170 }
171
172 if (!strDatabase.isEmpty())
173 reset();
174
175 return true;
176}

◆ __rollbackTrans()

bool IFXConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 395 of file IFXConnection.cpp.

396{
397/*
398 * EXEC SQL BEGIN DECLARE SECTION;
399 */
400#line 254 "ifxconnection.ec"
401#line 255 "ifxconnection.ec"
402 char *pszConnectionID = (_CONST char*) __connectionID.data();
403/*
404 * EXEC SQL END DECLARE SECTION;
405 */
406#line 256 "ifxconnection.ec"
407
408
409/*
410 * EXEC SQL SET CONNECTION :pszConnectionID;
411 */
412#line 258 "ifxconnection.ec"
413 {
414#line 258 "ifxconnection.ec"
415 sqli_connect_set(0, pszConnectionID, 0);
416#line 258 "ifxconnection.ec"
417 }
418 if (SQLCODE < 0) {
419 __SET_ERROR_SQLCODE(SQLCODE);
420 return false;
421 }
422
423/*
424 * EXEC SQL ROLLBACK WORK;
425 */
426#line 264 "ifxconnection.ec"
427 {
428#line 264 "ifxconnection.ec"
429 sqli_trans_rollback();
430#line 264 "ifxconnection.ec"
431 }
432 if (SQLCODE < 0) {
433 __SET_ERROR_SQLCODE(SQLCODE);
434 return false;
435 }
436
438 return true;
439}

◆ __startTrans()

bool IFXConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 303 of file IFXConnection.cpp.

304{
305/*
306 * EXEC SQL BEGIN DECLARE SECTION;
307 */
308#line 210 "ifxconnection.ec"
309#line 211 "ifxconnection.ec"
310 char *pszConnectionID = (_CONST char*) __connectionID.data();
311/*
312 * EXEC SQL END DECLARE SECTION;
313 */
314#line 212 "ifxconnection.ec"
315
316
317/*
318 * EXEC SQL SET CONNECTION :pszConnectionID;
319 */
320#line 214 "ifxconnection.ec"
321 {
322#line 214 "ifxconnection.ec"
323 sqli_connect_set(0, pszConnectionID, 0);
324#line 214 "ifxconnection.ec"
325 }
326 if (SQLCODE < 0) {
327 __SET_ERROR_SQLCODE(SQLCODE);
328 return false;
329 }
330
331/*
332 * EXEC SQL BEGIN WORK;
333 */
334#line 220 "ifxconnection.ec"
335 {
336#line 220 "ifxconnection.ec"
337 sqli_trans_begin2((mint)1);
338#line 220 "ifxconnection.ec"
339 }
340 if (SQLCODE < 0) {
341 __SET_ERROR_SQLCODE(SQLCODE);
342 return false;
343 }
344
346 return true;
347}
int mint
Definition IFXParam.cpp:11

◆ connectionID()

_CONST char * IFXConnection::connectionID ( ) const
inline

Definition at line 45 of file IFXConnection.h.

46{
47 return (_CONST char*)__connectionID.data();
48}

◆ destroy()

void IFXConnection::destroy ( )
virtual

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

Implements SQL::Connection.

Definition at line 56 of file IFXConnection.cpp.

57{
58 delete this;
59}

◆ setErrorStatus() [1/2]

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

Definition at line 38 of file IFXConnection.h.

40{
41 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
42 __lastErrorMessage = _message;
43}
__PROTECTED const wchar_t int _line
Definition SQLCore.h:390
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:390

◆ setErrorStatus() [2/2]

void IFXConnection::setErrorStatus ( SQL::Error _error,
long _SQLCODE,
const wchar_t * _filename,
int _line )

Definition at line 455 of file IFXConnection.cpp.

457{
458 Connection::setErrorStatus(_error, _filename, _line);
459 if (_SQLCODE == 0) {
460 __lastErrorMessage.clear();
461 return;
462 }
463
464 __DCL_ASSERT(_SQLCODE == sqlca.sqlcode);
465
466 ByteStringBuilder sb;
467 sb.format("SQLCODE(%d) ", _SQLCODE);
468
469 char buf[600];
470 mint actual = 0;
471 mint r = rgetlmsg(_SQLCODE, buf, sizeof(buf), &actual);
472 if (!r) {
473 while (actual > 0) {
474 if (!isspace(buf[actual - 1]))
475 break;
476 actual--;
477 }
478 buf[actual] = '\0';
479 sb.format(buf, sqlca.sqlerrm);
480 }
481 else {
482 sb.format("(%d)", r);
483 switch (r) {
484 case -1227:
485 sb.append("Message file not found");
486 break;
487 case -1228:
488 sb.append("Message number not found in message file");
489 break;
490 case -1231:
491 sb.append("Cannot seek within messge file");
492 break;
493 case -1232:
494 sb.append("Message buffer too small");
495 break;
496 default:
497 sb.append("Unkndown");
498 }
499 }
500 __lastErrorMessage = sb.toByteString();
501}
ByteString r
ByteBuffer * buf

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