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

#include <PgQuery.h>

Inheritance diagram for PgQuery:
SQL::Query Object

Public Member Functions

 PgQuery (PgConnection *pConnection)
virtual ~PgQuery ()
virtual void __destroy ()
virtual bool __prepare (const char *_sql, size_t _sqllen, size_t _paramCount)
virtual bool __execute ()
virtual bool __fetch ()
virtual bool __getField (size_t _index, SQL::Field **_fieldHandleOut)
virtual bool __getParam (size_t _index, SQL::Param **_paramHandleOut)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

bool reset ()
bool initFields ()
bool initParams (size_t _paramCount)
Protected Member Functions inherited from SQL::Query
 Query (Connection *_connHandle)
virtual ~Query ()
virtual bool __nextResult ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

ByteString __statementID
ByteString __cursorID
sqlda_t * __outSQLDA
sqlda_t * __inSQLDA
bool __cursorDeclared
bool __cursorOpened
PgField__fields
PgParam__params
Protected Attributes inherited from SQL::Query
Connection__connHandle
bool __eof
int64_t __affectedRows
size_t __fieldCount
size_t __paramCount
wchar_t __placeholder
unsigned int __states

Additional Inherited Members

Public Types inherited from SQL::Query
enum  State { stStandBy = 0x0001 , stPrepared = 0x0002 , stExecuted = 0x0004 , stFetched = 0x0008 }

Detailed Description

Definition at line 9 of file PgQuery.h.

Constructor & Destructor Documentation

◆ PgQuery()

PgQuery::PgQuery ( PgConnection * pConnection)

◆ ~PgQuery()

PgQuery::~PgQuery ( )
virtual

Definition at line 59 of file PgQuery.cpp.

60{
61#ifdef __DCL_DEBUG
62 if (!reset()) {
63 ByteString s;
64 size_t n = 512;
65 ByteBuffer* buf = ByteBuffer::create(n);
66 bool b = conn()->__getErrorMessage(buf->data(), &n);
67 if (b) {
68 buf->__dataLength = n;
69 s = buf;
70 }
71 buf->release();
72
73 if (b) {
74 __DCL_TRACE1(__T("Warning! %s\n"), s.data());
75 }
76 else {
77 __DCL_TRACE0(__T("Warning! Query reset error\n"));
78 }
79 }
80#else
81 (void)reset();
82#endif
83}
#define __DCL_TRACE0(psz)
Definition Object.h:375
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:376
#define __T(str)
Definition Object.h:44
ByteBuffer * buf
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
bool reset()
Definition PgQuery.cpp:91

Member Function Documentation

◆ __destroy()

void PgQuery::__destroy ( )
virtual

Implements SQL::Query.

Definition at line 85 of file PgQuery.cpp.

86{
87// cerr << "PgQuery::destory\n";
88 delete this;
89}

◆ __execute()

bool PgQuery::__execute ( )
virtual

Implements SQL::Query.

Definition at line 311 of file PgQuery.cpp.

312{
313 /* exec sql begin declare section */
314
315
316
317
318#line 266 "PgQuery.pgc"
319 char * pszConnectionID = conn () -> connectionID () ;
320
321#line 267 "PgQuery.pgc"
322 char * pszStatementID = ( _CONST char * ) __statementID . data () ;
323
324#line 268 "PgQuery.pgc"
325 char * pszCursorID = ( _CONST char * ) __cursorID . data () ;
326/* exec sql end declare section */
327#line 269 "PgQuery.pgc"
328
329
330 { ECPGsetconn(__LINE__, pszConnectionID);}
331#line 271 "PgQuery.pgc"
332
333 if (SQLCODE < 0) {
334 __SET_ERROR_SQLCODE(SQLCODE);
335 return false;
336 }
337 __DCL_ASSERT(SQLCODE == 0);
338
339 if (__outSQLDA && __outSQLDA->sqld > 0) {
340 if (!__cursorDeclared) {
341 ECPGset_var( 0, &( pszCursorID ), __LINE__);\
342 /* declare $0 cursor for $1 */
343#line 280 "PgQuery.pgc"
344
345#line 280 "PgQuery.pgc"
346
347 if (SQLCODE < 0) {
348 __SET_ERROR_SQLCODE(SQLCODE);
349 return false;
350 }
351 __cursorDeclared = true;
352 }
353
354 if (__cursorOpened) {
355 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close $0",
356 ECPGt_char,&(pszCursorID),(long)0,(long)1,(1)*sizeof(char),
357 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
358#line 289 "PgQuery.pgc"
359
360 if (SQLCODE < 0) {
361 __SET_ERROR_SQLCODE(SQLCODE);
362 return false;
363 }
364 __cursorOpened = false;
365 }
366
367 if (__inSQLDA)
368 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1",
369 ECPGt_char,&(pszCursorID),(long)0,(long)1,(1)*sizeof(char),
370 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
371 ECPGt_char_variable,(ECPGprepared_statement(NULL, pszStatementID, __LINE__)),(long)1,(long)1,(1)*sizeof(char),
372 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
373 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
374 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
375#line 298 "PgQuery.pgc"
376
377 else
378 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1",
379 ECPGt_char,&(pszCursorID),(long)0,(long)1,(1)*sizeof(char),
380 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
381 ECPGt_char_variable,(ECPGprepared_statement(NULL, pszStatementID, __LINE__)),(long)1,(long)1,(1)*sizeof(char),
382 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
383#line 300 "PgQuery.pgc"
384
385
386 if (SQLCODE < 0) {
387 __SET_ERROR_SQLCODE(SQLCODE);
388 return false;
389 }
390
391 __cursorOpened = true;
392 __eof = false;
393 }
394 else {
395#if 0
396 // 2025.05.06 __outSQLDA 조건은 CURSOR로 처리 하므로
397 // 다음 EXEC SQL EXECUTE는 의미가 없다.
398 if (__outSQLDA && __inSQLDA)
399 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, pszStatementID,
400 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
401 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
402 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
403 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
404#line 316 "PgQuery.pgc"
405
406 else if (__outSQLDA)
407 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, pszStatementID, ECPGt_EOIT,
408 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
409 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
410#line 318 "PgQuery.pgc"
411
412 else
413#endif
414 if (__inSQLDA)
415 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, pszStatementID,
416 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
417 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
418#line 322 "PgQuery.pgc"
419
420 else
421 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, pszStatementID, ECPGt_EOIT, ECPGt_EORT);}
422#line 324 "PgQuery.pgc"
423
424
425 if (SQLCODE < 0) {
426 __SET_ERROR_SQLCODE(SQLCODE);
427 Query::__affectedRows = -1;
428 return false;
429 }
430
431 // INSERT, UPDATE, DELETE
432 Query::__affectedRows = sqlca.sqlerrd[2];
433 }
434
435 for(size_t i = 0; i < Query::__paramCount; i++) {
436 if (!(__params[i].onAfterExecute()))
437 return false;
438 }
439
440 return true;
441}
#define NULL
Definition Config.h:340
#define _CONST
Definition Config.h:353
#define __SET_ERROR_SQLCODE(SQLCODE)
#define __DCL_ASSERT(expr)
Definition Object.h:371
sqlda_t * __outSQLDA
Definition PgQuery.h:24
bool __cursorDeclared
Definition PgQuery.h:27
sqlda_t * __inSQLDA
Definition PgQuery.h:25
bool __cursorOpened
Definition PgQuery.h:28
PgParam * __params
Definition PgQuery.h:31
ByteString __statementID
Definition PgQuery.h:21
ByteString __cursorID
Definition PgQuery.h:22
bool __eof
Definition SQLCore.h:286

◆ __fetch()

bool PgQuery::__fetch ( )
virtual

Implements SQL::Query.

Definition at line 443 of file PgQuery.cpp.

444{
445 // SELECT, CALL
446 __DCL_ASSERT(!eof());
447 __DCL_ASSERT(__outSQLDA && __outSQLDA->sqld > 0);
448
449 /* exec sql begin declare section */
450
451
452#line 351 "PgQuery.pgc"
453 char * pszCursorID = ( _CONST char * ) __cursorID . data () ;
454/* exec sql end declare section */
455#line 352 "PgQuery.pgc"
456
457
458 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0",
459 ECPGt_char,&(pszCursorID),(long)0,(long)1,(1)*sizeof(char),
460 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
461 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
462 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
463#line 354 "PgQuery.pgc"
464
465
466 if (SQLCODE == ECPG_NO_ERROR) {
467#if 0
468 __DCL_TRACE1(L"[%p]\n", __outSQLDA);
469 __DCL_TRACE4(L"[%hs] [%ld] sqln[%d] sqld[%d]\n",
470 __outSQLDA->sqldaid, __outSQLDA->sqldabc,
471 __outSQLDA->sqln, __outSQLDA->sqld
472 );
473 for (int i = 0; i < __outSQLDA->sqld; i++) {
474 sqlvar_t* p = &(__outSQLDA->sqlvar[i]);
475 __DCL_TRACE4(L"[%19ls] [%hd] [%p] [%p]\n",
476 __dataTypeName(p), p->sqllen, p->sqldata, p->sqlind
477 );
478 }
479#endif
480 sqlvar_t* sqlvar = __outSQLDA->sqlvar;
481 for (size_t i = 0; i < Query::__fieldCount; i++) {
482 if (!__fields[i].onAfterFetch(sqlvar++))
483 return false;
484 }
485 return true;
486 }
487 else if (SQLCODE == ECPG_NOT_FOUND) {
488 Query::__eof = true;
489 return true;
490 }
491
492 __SET_ERROR_SQLCODE(SQLCODE);
493 return false;
494}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:290
#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4)
Definition Object.h:379
PgField * __fields
Definition PgQuery.h:30

◆ __getField()

bool PgQuery::__getField ( size_t _index,
SQL::Field ** _fieldHandleOut )
virtual

Implements SQL::Query.

Definition at line 496 of file PgQuery.cpp.

497{
498 __DCL_ASSERT(Query::__fieldCount > 0);
499 __DCL_ASSERT((0 <= _index) && (_index < Query::__fieldCount));
500 *_fieldHandleOut = &__fields[_index];
501 return true;
502}

◆ __getParam()

bool PgQuery::__getParam ( size_t _index,
SQL::Param ** _paramHandleOut )
virtual

Implements SQL::Query.

Definition at line 504 of file PgQuery.cpp.

505{
506 __DCL_ASSERT(Query::__paramCount > 0);
507 __DCL_ASSERT((0 <= _index) && (_index < Query::__paramCount));
508 *_paramHandleOut = &__params[_index];
509 return true;
510}

◆ __prepare()

bool PgQuery::__prepare ( const char * _sql,
size_t _sqllen,
size_t _paramCount )
virtual

Implements SQL::Query.

Definition at line 231 of file PgQuery.cpp.

233{
234 if(!reset())
235 return false;
236
237 /* exec sql begin declare section */
238
239
240
241
242#line 209 "PgQuery.pgc"
243 char * pszConnectionID = conn () -> connectionID () ;
244
245#line 210 "PgQuery.pgc"
246 char * pszStatementID = ( _CONST char * ) __statementID . data () ;
247
248#line 211 "PgQuery.pgc"
249 char * pszSQL = ( _CONST char * ) _sql ;
250/* exec sql end declare section */
251#line 212 "PgQuery.pgc"
252
253
254 { ECPGsetconn(__LINE__, pszConnectionID);}
255#line 214 "PgQuery.pgc"
256
257 if (SQLCODE < 0) {
258 __SET_ERROR_SQLCODE(SQLCODE);
259 return false;
260 }
261 __DCL_ASSERT(SQLCODE == 0);
262
263 { ECPGprepare(__LINE__, NULL, 0, pszStatementID, pszSQL);}
264#line 221 "PgQuery.pgc"
265
266
267 if (SQLCODE < 0) {
268 __SET_ERROR_SQLCODE(SQLCODE);
269 return false;
270 }
271
272 { ECPGdescribe(__LINE__, 0, 0, NULL, pszStatementID,
273 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
274 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
275#line 228 "PgQuery.pgc"
276
277
278 if (SQLCODE < 0) {
279 __SET_ERROR_SQLCODE(SQLCODE);
280 return false;
281 }
282
283 if (__outSQLDA) {
284#if 0
285 __DCL_TRACE1(L"[%p]\n", __outSQLDA);
286 __DCL_TRACE4(L"[%hs] [%ld] sqln[%d] sqld[%d]\n",
287 __outSQLDA->sqldaid, __outSQLDA->sqldabc,
288 __outSQLDA->sqln, __outSQLDA->sqld
289 );
290 for (int i = 0; i < __outSQLDA->sqld; i++) {
291 sqlvar_t* p = &(__outSQLDA->sqlvar[i]);
292 __DCL_TRACE4(L"[%19ls] [%hd] [%p] [%p]\n",
293 __dataTypeName(p), p->sqllen, p->sqldata, p->sqlind
294 );
295 }
296#endif
297 if (__outSQLDA->sqld > 0) {
298 if (!initFields())
299 return false;
300 }
301 }
302
303 if (_paramCount > 0) {
304 if (!initParams(_paramCount))
305 return false;
306 }
307
308 return true;
309}
bool initFields()
Definition PgQuery.cpp:174
bool initParams(size_t _paramCount)
Definition PgQuery.cpp:197

◆ initFields()

bool PgQuery::initFields ( )
protected

Definition at line 174 of file PgQuery.cpp.

175{
177 && (Query::__fieldCount == 0)
178 && (__outSQLDA != NULL)
179 && (__outSQLDA->sqld > 0));
180
181 Query::__fieldCount = __outSQLDA->sqld;
182 __fields = new PgField[Query::__fieldCount];
183 if (__fields == NULL) {
185 return false;
186 }
187
188 sqlvar_t* sqlvar = __outSQLDA->sqlvar;
189 for(size_t i = 0; i < Query::__fieldCount; i++, sqlvar++) {
190 if (!__fields[i].init(this, sqlvar))
191 return false;
192 }
193
194 return true;
195}
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:150
@ eOutOfMemory
Definition SQLCore.h:24

◆ initParams()

bool PgQuery::initParams ( size_t _paramCount)
protected

Definition at line 197 of file PgQuery.cpp.

198{
200 && (Query::__paramCount == 0)
201 && (__outSQLDA != NULL));
202
203 size_t nAllocSize = sizeof(sqlda_t)
204 + (sizeof(sqlvar_t) * _paramCount);
205 __inSQLDA = (sqlda_t*)malloc(nAllocSize);
206 if (__inSQLDA == NULL) {
208 return false;
209 }
210 memset(__inSQLDA, 0, nAllocSize);
211 __inSQLDA->sqln = (short)_paramCount;
212
213 Query::__paramCount = _paramCount;
214 __params = new PgParam[Query::__paramCount];
215 if (__params == NULL) {
217 return false;
218 }
219
220 sqlvar_t* sqlvar = __inSQLDA->sqlvar;
221 for(size_t i = 0; i < Query::__paramCount; i++, sqlvar++) {
222 if (!__params[i].init(this, sqlvar))
223 return false;
224 }
225
226 return true;
227}

◆ reset()

bool PgQuery::reset ( )
protected

Definition at line 91 of file PgQuery.cpp.

92{
93 /* exec sql begin declare section */
94
95
96
97
98#line 86 "PgQuery.pgc"
99 char * pszConnectionID = conn () -> connectionID () ;
100
101#line 87 "PgQuery.pgc"
102 char * pszStatementID = ( _CONST char * ) __statementID . data () ;
103
104#line 88 "PgQuery.pgc"
105 char * pszCursorID = ( _CONST char * ) __cursorID . data () ;
106/* exec sql end declare section */
107#line 89 "PgQuery.pgc"
108
109
110 { ECPGsetconn(__LINE__, pszConnectionID);}
111#line 91 "PgQuery.pgc"
112
113 if (SQLCODE < 0) {
114 __SET_ERROR_SQLCODE(SQLCODE);
115 return false;
116 }
117 __DCL_ASSERT(SQLCODE == 0);
118
119 if (__cursorOpened) {
120 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close $0",
121 ECPGt_char,&(pszCursorID),(long)0,(long)1,(1)*sizeof(char),
122 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
123#line 99 "PgQuery.pgc"
124
125 __cursorOpened = false;
126 }
127
128 if (__cursorDeclared) {
129 { ECPGdeallocate(__LINE__, 0, NULL, pszCursorID);}
130#line 104 "PgQuery.pgc"
131
132 __cursorDeclared = false;
133 }
134
135 if (__outSQLDA) {
136 { ECPGdeallocate(__LINE__, 0, NULL, pszStatementID);}
137#line 109 "PgQuery.pgc"
138
139 }
140
141 Query::__eof = true;
142 Query::__affectedRows = -1;
143
144 // clear fields
145 if (__fields) {
146 __DCL_ASSERT(Query::__fieldCount > 0);
147 delete[] __fields;
148 __fields = NULL;
149 Query::__fieldCount = 0;
150 }
151
152 // clear binds
153 if (__params) {
154 __DCL_ASSERT(Query::__paramCount > 0);
155 delete[] __params;
156 __params = NULL;
157 Query::__paramCount = 0;
158 }
159
160 if (__outSQLDA) {
161 // __outSQLDA는 Informix API에서 할당됨.
162 // DCLPgFree(__outSQLDA);
164 }
165
166 if (__inSQLDA) {
167 free(__inSQLDA);
168 __inSQLDA = NULL;
169 }
170
171 return true;
172}

Member Data Documentation

◆ __cursorDeclared

bool PgQuery::__cursorDeclared
protected

Definition at line 27 of file PgQuery.h.

◆ __cursorID

ByteString PgQuery::__cursorID
protected

Definition at line 22 of file PgQuery.h.

◆ __cursorOpened

bool PgQuery::__cursorOpened
protected

Definition at line 28 of file PgQuery.h.

◆ __fields

PgField* PgQuery::__fields
protected

Definition at line 30 of file PgQuery.h.

◆ __inSQLDA

sqlda_t* PgQuery::__inSQLDA
protected

Definition at line 25 of file PgQuery.h.

◆ __outSQLDA

sqlda_t* PgQuery::__outSQLDA
protected

Definition at line 24 of file PgQuery.h.

◆ __params

PgParam* PgQuery::__params
protected

Definition at line 31 of file PgQuery.h.

◆ __statementID

ByteString PgQuery::__statementID
protected

Definition at line 21 of file PgQuery.h.


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