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

#include <PeConnection.h>

Inheritance diagram for PeConnection:
SQL::Connection Object

Public Member Functions

void setErrorHandle (SQL::Error _error, long _SQLCODE, const wchar_t *_filename, int _line)
void setErrorMessage (const ByteString &_message, const wchar_t *_filename, int _line)
_CONST char * connectionID () const
virtual void destroy ()
 PeConnection (const wchar_t *_serverTitle)
virtual ~PeConnection ()
virtual bool __open (const char *_conns, size_t _connslen)
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 6 of file PeConnection.h.

Constructor & Destructor Documentation

◆ PeConnection()

PeConnection::PeConnection ( const wchar_t * _serverTitle)

◆ ~PeConnection()

PeConnection::~PeConnection ( )
virtual

Definition at line 64 of file PeConnection.cpp.

65{
66 if (!__connectionID.isEmpty()) {
67 __DCL_TRACE0_N(L"Warning!! The connection was not closed\n");
68 close();
69 }
70}
#define __DCL_TRACE0_N(fmt)

Member Function Documentation

◆ __close()

bool PeConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 151 of file PeConnection.cpp.

152{
153 if (__connectionID.isEmpty()) {
155 return false;
156 }
157
158 /* exec sql begin declare section */
159
160
161#line 136 "PeConnection.pgc"
162 char * connID = ( _CONST char * ) __connectionID . data () ;
163/* exec sql end declare section */
164#line 137 "PeConnection.pgc"
165
166
167 { ECPGdisconnect(__LINE__, connID);}
168#line 139 "PeConnection.pgc"
169
170 if (SQLCODE < 0) {
171 __SET_ERROR_HANDLE(SQLCODE);
172 return false;
173 }
174
175 __connectionID.clear();
176 return true;
177}
#define _CONST
Definition Config.h:325
#define __SET_ERROR_HANDLE(_SQLCODE)
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
@ eNotConnected
Definition SQLCore.h:33

◆ __commitTrans()

bool PeConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 272 of file PeConnection.cpp.

273{
274 /* exec sql begin declare section */
275
276
277#line 236 "PeConnection.pgc"
278 char * connID = ( _CONST char * ) __connectionID . data () ;
279/* exec sql end declare section */
280#line 237 "PeConnection.pgc"
281
282
283 { ECPGsetconn(__LINE__, connID);}
284#line 239 "PeConnection.pgc"
285
286 if (SQLCODE < 0) {
287 __SET_ERROR_HANDLE(SQLCODE);
288 return false;
289 }
290
291 { ECPGtrans(__LINE__, NULL, "commit work");}
292#line 245 "PeConnection.pgc"
293
294 if (SQLCODE < 0) {
295 __SET_ERROR_HANDLE(SQLCODE);
296 return false;
297 }
298
300 return true;
301}
#define NULL
Definition Config.h:312
#define __UNSET_STATE(state)
Definition SQLCore.h:483

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 334 of file PeConnection.cpp.

335{
336 __DCL_ASSERT(_queryHandleOut != NULL);
337
338 SQL::Query* pNewQuery = new PeQuery(this);
339 if (!pNewQuery) {
341 return false;
342 }
343
344 *_queryHandleOut = pNewQuery;
345 return true;
346}
#define __DCL_ASSERT(expr)
Definition Object.h:394
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

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

Implements SQL::Connection.

Definition at line 210 of file PeConnection.cpp.

211{
212 // PostgreSQL에서 EXEC SQL EXECUTE IMMEDIATE는 DML만 사용할 수 있다!
213 PGconn* conn = ECPGget_PGconn(__connectionID.data());
214 PGresult* res = PQexec(conn, _sql);
215 ExecStatusType status = PQresultStatus(res);
216 if (status != PGRES_COMMAND_OK) {
217 ByteStringBuilder sb;
218 sb.format("ExecStatusType(%d)", status)
219 .append(PQresultErrorMessage(res));
220 __SET_ERROR_MSG(sb);
221 PQclear(res);
222 return false;
223 }
224 PQclear(res);
225
226 switch(__GetStmtType(_sql)) {
227 case StmtTransBegin :
229 break;
230 case StmtTransEnd :
232 break;
233 case StmtOther :
234 default :
235 ;
236 }
237
238 return true;
239}
#define __SET_ERROR_MSG(_message)
@ StmtTransEnd
@ StmtOther
@ StmtTransBegin
#define __SET_STATE(state)
Definition SQLCore.h:482

◆ __getErrorMessage()

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

Implements SQL::Connection.

Definition at line 365 of file PeConnection.cpp.

366{
367 __DCL_ASSERT(Connection::__errorCode == SQL::eServerError);
368 if (__lastErrorMessage.length() < *_buflen) {
369 *_buflen = __lastErrorMessage.length();
370 *(_buf + *_buflen) = '\0';
371 }
372 strncpy(_buf, __lastErrorMessage.data(), *_buflen);
373 return true;
374}
@ eServerError
Definition SQLCore.h:21

◆ __getServerInfo()

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

Implements SQL::Connection.

Definition at line 376 of file PeConnection.cpp.

377{
378 PGconn* conn = ECPGget_PGconn(__connectionID.data());
379 int serverVersion = PQserverVersion(conn);
380 int protocolVersion =
381#ifdef LIBPQ_HAS_FULL_PROTOCOL_VERSION
382 PQfullProtocolVersion(conn)
383#else
384 PQprotocolVersion(conn) * 10000
385#endif
386 ;
387 int libVersion = PQlibVersion();
388
389 ByteString s = ByteString::format("PostgreSQL %d.%d/%d.%d/%d.%d/ecpg",
390 serverVersion / 10000, serverVersion % 10000,
391 protocolVersion / 10000, protocolVersion % 10000,
392 libVersion / 10000, libVersion % 10000
393 );
394 if (s.length() < *_buflen) {
395 *_buflen = s.length();
396 *(_buf + *_buflen) = '\0';
397 }
398 strncpy(_buf, s.data(), *_buflen);
399 return true;
400}

◆ __open()

bool PeConnection::__open ( const char * _conns,
size_t _connslen )
virtual

Implements SQL::Connection.

Definition at line 85 of file PeConnection.cpp.

86{
87 ListedByteStringToByteStringMap map;
88 Connection::splitConnStr(_conns, _connslen, map);
89
90 ByteString _USER = map["USER"];
91 ByteString _PASSWORD = map["PASSWORD"];
92 ByteString _SERVER = map["SERVER"];
93 ByteString _PORT = map["PORT"];
94 ByteString _DATABASE = map["DATABASE"];
95 ByteString _TARGET;
96
97 {
98 ByteStringBuilder sb;
99 if (!_SERVER.isEmpty()) {
100 sb.append("tcp:postgresql://").append(_SERVER);
101 if (!_PORT.isEmpty()) {
102 sb.append(":").append(_PORT);
103 }
104 }
105 if (!_DATABASE.isEmpty()) {
106 if (!sb.isEmpty()) {
107 sb += "/";
108 }
109 sb += _DATABASE;
110 }
111 _TARGET = sb.toByteString();
112 __DCL_TRACE1_N(L"TARGET [%hs]\n", _TARGET.data());
113 }
114
115 ByteString connectionID = ByteString::format("conn_%zx", (size_t)this);
116
117 /* exec sql begin declare section */
118
119
120
121
122
123#line 110 "PeConnection.pgc"
124 char * user = ( _CONST char * ) _USER . data () ;
125
126#line 111 "PeConnection.pgc"
127 char * pass = ( _CONST char * ) _PASSWORD . data () ;
128
129#line 112 "PeConnection.pgc"
130 char * target = ( _CONST char * ) _TARGET . data () ;
131
132#line 113 "PeConnection.pgc"
133 char * connID = ( _CONST char * ) connectionID . data () ;
134/* exec sql end declare section */
135#line 114 "PeConnection.pgc"
136
137
138 { ECPGconnect(__LINE__, 0, target , user , pass , connID, 0); }
139#line 117 "PeConnection.pgc"
140
141
142 if (SQLCODE < 0) {
143 __SET_ERROR_HANDLE(SQLCODE);
144 return false;
145 }
146 __connectionID = connectionID;
147
148 return true;
149}
#define __DCL_TRACE1_N(fmt, arg)
_CONST char * connectionID() const

◆ __rollbackTrans()

bool PeConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 303 of file PeConnection.cpp.

304{
305 /* exec sql begin declare section */
306
307
308#line 258 "PeConnection.pgc"
309 char * connID = ( _CONST char * ) __connectionID . data () ;
310/* exec sql end declare section */
311#line 259 "PeConnection.pgc"
312
313
314 { ECPGsetconn(__LINE__, connID);}
315#line 261 "PeConnection.pgc"
316
317 if (SQLCODE < 0) {
318 __SET_ERROR_HANDLE(SQLCODE);
319 return false;
320 }
321
322 { ECPGtrans(__LINE__, NULL, "rollback work");}
323#line 267 "PeConnection.pgc"
324
325 if (SQLCODE < 0) {
326 __SET_ERROR_HANDLE(SQLCODE);
327 return false;
328 }
329
331 return true;
332}

◆ __startTrans()

bool PeConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 241 of file PeConnection.cpp.

242{
243 /* exec sql begin declare section */
244
245
246#line 214 "PeConnection.pgc"
247 char * connID = ( _CONST char * ) __connectionID . data () ;
248/* exec sql end declare section */
249#line 215 "PeConnection.pgc"
250
251
252 { ECPGsetconn(__LINE__, connID);}
253#line 217 "PeConnection.pgc"
254
255 if (SQLCODE < 0) {
256 __SET_ERROR_HANDLE(SQLCODE);
257 return false;
258 }
259
260 { ECPGtrans(__LINE__, NULL, "begin work");}
261#line 223 "PeConnection.pgc"
262
263 if (SQLCODE < 0) {
264 __SET_ERROR_HANDLE(SQLCODE);
265 return false;
266 }
267
269 return true;
270}

◆ connectionID()

_CONST char * PeConnection::connectionID ( ) const
inline

Definition at line 51 of file PeConnection.h.

52{
53 return (_CONST char*)__connectionID.data();
54}

◆ destroy()

void PeConnection::destroy ( )
virtual

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

Implements SQL::Connection.

Definition at line 72 of file PeConnection.cpp.

73{
74 delete this;
75}

◆ setErrorHandle()

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

Definition at line 348 of file PeConnection.cpp.

352{
353 Connection::setErrorStatus(_error, _filename, _line);
354 if (_SQLCODE == 0 /* ECPG_NO_ERROR */) {
355 __lastErrorMessage.clear();
356 }
357 else {
358 ByteStringBuilder sb;
359 sb.format("SQLCODE(%d) ", _SQLCODE);
360 sb.append(sqlca.sqlerrm.sqlerrmc, sqlca.sqlerrm.sqlerrml);
361 __lastErrorMessage = sb.toByteString();
362 }
363}
_PROTECTED const wchar_t * _filename
Definition SQLCore.h:439
_PROTECTED const wchar_t int _line
Definition SQLCore.h:441

◆ setErrorMessage()

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

Definition at line 42 of file PeConnection.h.

46{
47 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
48 __lastErrorMessage = _message;
49}

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