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

#include <PeQuery.h>

Inheritance diagram for PeQuery:
SQL::Query Object

Public Member Functions

 PeQuery (PeConnection *pConnection)
virtual ~PeQuery ()
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 __moreResults (bool *_moreResults)
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
PeField__fields
PeParam__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 = (unsigned int) 0x0001 , stPrepared = 0x0002 , stExecuted = 0x0004 , stFetched = 0x0008 }

Detailed Description

Definition at line 9 of file PeQuery.h.

Constructor & Destructor Documentation

◆ PeQuery()

PeQuery::PeQuery ( PeConnection * pConnection)

◆ ~PeQuery()

PeQuery::~PeQuery ( )
virtual

Definition at line 66 of file PeQuery.cpp.

67{
68#ifdef __DCL_DEBUG
69 if (!reset()) {
70 char buf[256];
71 size_t buflen = sizeof(buf) - 1;
72 bool b = conn()->__getErrorMessage(buf, &buflen);
73 buf[b ? buflen : 0] = '\0';
74 __DCL_TRACE1(L"Warning! Query reset error! %hs\n", buf);
75 }
76#else
77 (void)reset();
78#endif
79}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
bool reset()
Definition PeQuery.cpp:87

Member Function Documentation

◆ __destroy()

void PeQuery::__destroy ( )
virtual

Implements SQL::Query.

Definition at line 81 of file PeQuery.cpp.

82{
83// cerr << "PeQuery::destory\n";
84 delete this;
85}

◆ __execute()

bool PeQuery::__execute ( )
virtual

Implements SQL::Query.

Definition at line 325 of file PeQuery.cpp.

326{
327#ifdef __DCL_DEBUG
328 for (size_t i = 0; i < Query::__paramCount; i++) {
329 __params[i].onBeforeExecute();
330 }
331#endif
332
333 /* exec sql begin declare section */
334
335
336
337
338#line 286 "PeQuery.pgc"
339 char * connID = conn () -> connectionID () ;
340
341#line 287 "PeQuery.pgc"
342 char * stmtID = ( _CONST char * ) __statementID . data () ;
343
344#line 288 "PeQuery.pgc"
345 char * cursorID = ( _CONST char * ) __cursorID . data () ;
346/* exec sql end declare section */
347#line 289 "PeQuery.pgc"
348
349
350 { ECPGsetconn(__LINE__, connID);}
351#line 291 "PeQuery.pgc"
352
353 if (SQLCODE < 0) {
354 __SET_ERROR_HANDLE(SQLCODE);
355 return false;
356 }
357 __DCL_ASSERT(SQLCODE == 0);
358
359 if (__outSQLDA && __outSQLDA->sqld > 0) {
360 if (!__cursorDeclared) {
361 ECPGset_var( 0, &( cursorID ), __LINE__);\
362 /* declare $0 cursor for $1 */
363#line 300 "PeQuery.pgc"
364
365#line 300 "PeQuery.pgc"
366
367 if (SQLCODE < 0) {
368 __SET_ERROR_HANDLE(SQLCODE);
369 return false;
370 }
371 __cursorDeclared = true;
372 }
373
374 if (__inSQLDA)
375 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1",
376 ECPGt_char,&(cursorID),(long)0,(long)1,(1)*sizeof(char),
377 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
378 ECPGt_char_variable,(ECPGprepared_statement(NULL, stmtID, __LINE__)),(long)1,(long)1,(1)*sizeof(char),
379 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
380 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
381 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
382#line 309 "PeQuery.pgc"
383
384 else
385 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1",
386 ECPGt_char,&(cursorID),(long)0,(long)1,(1)*sizeof(char),
387 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
388 ECPGt_char_variable,(ECPGprepared_statement(NULL, stmtID, __LINE__)),(long)1,(long)1,(1)*sizeof(char),
389 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
390#line 311 "PeQuery.pgc"
391
392
393 if (SQLCODE < 0) {
394 __SET_ERROR_HANDLE(SQLCODE);
395 return false;
396 }
397
398 __cursorOpened = true;
399 __eof = false;
400 }
401 else {
402#if 0
403 // 2025.05.06 __outSQLDA 조건은 CURSOR로 처리 하므로
404 // 다음 EXEC SQL EXECUTE는 의미가 없다.
405 if (__outSQLDA && __inSQLDA)
406 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, stmtID,
407 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
408 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
409 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
410 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
411#line 327 "PeQuery.pgc"
412
413 else if (__outSQLDA)
414 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, stmtID, ECPGt_EOIT,
415 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
416 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
417#line 329 "PeQuery.pgc"
418
419 else
420#endif
421 if (__inSQLDA)
422 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, stmtID,
423 ECPGt_sqlda, &__inSQLDA, 0L, 0L, 0L,
424 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
425#line 333 "PeQuery.pgc"
426
427 else
428 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, stmtID, ECPGt_EOIT, ECPGt_EORT);}
429#line 335 "PeQuery.pgc"
430
431
432 if (SQLCODE < 0) {
433 __SET_ERROR_HANDLE(SQLCODE);
434 Query::__affectedRows = -1;
435 return false;
436 }
437
438 // INSERT, UPDATE, DELETE
439 Query::__affectedRows = sqlca.sqlerrd[2];
440 }
441
442 for(size_t i = 0; i < Query::__paramCount; i++) {
443 if (!(__params[i].onAfterExecute()))
444 return false;
445 }
446
447 return true;
448}
#define NULL
Definition Config.h:312
#define _CONST
Definition Config.h:325
#define __SET_ERROR_HANDLE(_SQLCODE)
#define __DCL_ASSERT(expr)
Definition Object.h:394
sqlda_t * __inSQLDA
Definition PeQuery.h:20
sqlda_t * __outSQLDA
Definition PeQuery.h:19
ByteString __cursorID
Definition PeQuery.h:17
bool __cursorDeclared
Definition PeQuery.h:22
bool __cursorOpened
Definition PeQuery.h:23
PeParam * __params
Definition PeQuery.h:26
ByteString __statementID
Definition PeQuery.h:11
bool __eof
Definition SQLCore.h:303

◆ __fetch()

bool PeQuery::__fetch ( )
virtual

Implements SQL::Query.

Definition at line 450 of file PeQuery.cpp.

451{
452 // SELECT, CALL
453 __DCL_ASSERT(!eof());
454 __DCL_ASSERT(__outSQLDA && __outSQLDA->sqld > 0);
455
456 /* exec sql begin declare section */
457
458
459
460#line 362 "PeQuery.pgc"
461 char * connID = conn () -> connectionID () ;
462
463#line 363 "PeQuery.pgc"
464 char * cursorID = ( _CONST char * ) __cursorID . data () ;
465/* exec sql end declare section */
466#line 364 "PeQuery.pgc"
467
468
469 { ECPGsetconn(__LINE__, connID);}
470#line 366 "PeQuery.pgc"
471
472 if (SQLCODE < 0) {
473 __SET_ERROR_HANDLE(SQLCODE);
474 return false;
475 }
476 __DCL_ASSERT(SQLCODE == 0);
477
478 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0",
479 ECPGt_char,&(cursorID),(long)0,(long)1,(1)*sizeof(char),
480 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
481 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
482 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
483#line 373 "PeQuery.pgc"
484
485
486 if (SQLCODE == ECPG_NO_ERROR) {
487#if 0
488 __DCL_TRACE1(L"[%p]\n", __outSQLDA);
489 __DCL_TRACE4(L"[%hs] [%ld] sqln[%d] sqld[%d]\n",
490 __outSQLDA->sqldaid, __outSQLDA->sqldabc,
491 __outSQLDA->sqln, __outSQLDA->sqld
492 );
493 for (int i = 0; i < __outSQLDA->sqld; i++) {
494 sqlvar_t* p = &(__outSQLDA->sqlvar[i]);
495 __DCL_TRACE4(L"[%19ls] [%hd] [%p] [%p]\n",
496 __dataTypeName(p), p->sqllen, p->sqldata, p->sqlind
497 );
498 }
499#endif
500 sqlvar_t* sqlvar = __outSQLDA->sqlvar;
501 for (size_t i = 0; i < Query::__fieldCount; i++) {
502 if (!__fields[i].onAfterFetch(sqlvar++))
503 return false;
504 }
505 return true;
506 }
507 else if (SQLCODE == ECPG_NOT_FOUND) {
508 Query::__eof = true;
509 if (__cursorOpened) {
510 __cursorOpened = false;
511 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close $0",
512 ECPGt_char,&(cursorID),(long)0,(long)1,(1)*sizeof(char),
513 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
514#line 400 "PeQuery.pgc"
515
516 if (SQLCODE < 0) {
517 __SET_ERROR_HANDLE(SQLCODE);
518 return false;
519 }
520 }
521 return true;
522 }
523
524 __SET_ERROR_HANDLE(SQLCODE);
525 return false;
526}
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
Definition IFXField.cpp:304
#define __DCL_TRACE4(fmt, arg1, arg2, arg3, arg4)
Definition Object.h:402
PeField * __fields
Definition PeQuery.h:25

◆ __getField()

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

Implements SQL::Query.

Definition at line 528 of file PeQuery.cpp.

529{
530 __DCL_ASSERT(Query::__fieldCount > 0);
531 __DCL_ASSERT((0 <= _index) && (_index < Query::__fieldCount));
532 *_fieldHandleOut = &__fields[_index];
533 return true;
534}

◆ __getParam()

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

Implements SQL::Query.

Definition at line 536 of file PeQuery.cpp.

537{
538 __DCL_ASSERT(Query::__paramCount > 0);
539 __DCL_ASSERT((0 <= _index) && (_index < Query::__paramCount));
540 *_paramHandleOut = &__params[_index];
541 return true;
542}

◆ __prepare()

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

Implements SQL::Query.

Definition at line 245 of file PeQuery.cpp.

247{
248 if(!reset())
249 return false;
250
251 /* exec sql begin declare section */
252
253
254
255
256#line 223 "PeQuery.pgc"
257 char * connID = conn () -> connectionID () ;
258
259#line 224 "PeQuery.pgc"
260 char * stmtID = ( _CONST char * ) __statementID . data () ;
261
262#line 225 "PeQuery.pgc"
263 char * sql = ( _CONST char * ) _sql ;
264/* exec sql end declare section */
265#line 226 "PeQuery.pgc"
266
267
268 { ECPGsetconn(__LINE__, connID);}
269#line 228 "PeQuery.pgc"
270
271 if (SQLCODE < 0) {
272 __SET_ERROR_HANDLE(SQLCODE);
273 return false;
274 }
275 __DCL_ASSERT(SQLCODE == 0);
276
277 { ECPGprepare(__LINE__, NULL, 0, stmtID, sql);}
278#line 235 "PeQuery.pgc"
279
280
281 if (SQLCODE < 0) {
282 __SET_ERROR_HANDLE(SQLCODE);
283 return false;
284 }
285
286 { ECPGdescribe(__LINE__, 0, 0, NULL, stmtID,
287 ECPGt_sqlda, &__outSQLDA, 0L, 0L, 0L,
288 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
289#line 242 "PeQuery.pgc"
290
291
292 if (SQLCODE < 0) {
293 __SET_ERROR_HANDLE(SQLCODE);
294 return false;
295 }
296
297 if (__outSQLDA) {
298#if 0
299 __DCL_TRACE1(L"[%p]\n", __outSQLDA);
300 __DCL_TRACE4(L"[%hs] [%ld] sqln[%d] sqld[%d]\n",
301 __outSQLDA->sqldaid, __outSQLDA->sqldabc,
302 __outSQLDA->sqln, __outSQLDA->sqld
303 );
304 for (int i = 0; i < __outSQLDA->sqld; i++) {
305 sqlvar_t* p = &(__outSQLDA->sqlvar[i]);
306 __DCL_TRACE4(L"[%19ls] [%hd] [%p] [%p]\n",
307 __dataTypeName(p), p->sqllen, p->sqldata, p->sqlind
308 );
309 }
310#endif
311 if (__outSQLDA->sqld > 0) {
312 if (!initFields())
313 return false;
314 }
315 }
316
317 if (_paramCount > 0) {
318 if (!initParams(_paramCount))
319 return false;
320 }
321
322 return true;
323}
bool initParams(size_t _paramCount)
Definition PeQuery.cpp:210
bool initFields()
Definition PeQuery.cpp:185

◆ initFields()

bool PeQuery::initFields ( )
protected

Definition at line 185 of file PeQuery.cpp.

186{
188 (__fields == NULL)
189 && (Query::__fieldCount == 0)
190 && (__outSQLDA != NULL)
191 && (__outSQLDA->sqld > 0)
192 );
193
194 Query::__fieldCount = __outSQLDA->sqld;
195 __fields = new PeField[Query::__fieldCount];
196 if (__fields == NULL) {
198 return false;
199 }
200
201 sqlvar_t* sqlvar = __outSQLDA->sqlvar;
202 for(size_t i = 0; i < Query::__fieldCount; i++, sqlvar++) {
203 if (!__fields[i].init(this, sqlvar))
204 return false;
205 }
206
207 return true;
208}
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
@ eOutOfMemory
Definition SQLCore.h:24

◆ initParams()

bool PeQuery::initParams ( size_t _paramCount)
protected

Definition at line 210 of file PeQuery.cpp.

211{
213 && (Query::__paramCount == 0)
214 && (__outSQLDA != NULL)
215 );
216
217 size_t nAllocSize = sizeof(sqlda_t)
218 + (sizeof(sqlvar_t) * _paramCount);
219 __inSQLDA = (sqlda_t*)malloc(nAllocSize);
220 if (__inSQLDA == NULL) {
222 return false;
223 }
224 memset(__inSQLDA, 0, nAllocSize);
225 __inSQLDA->sqln = (short)_paramCount;
226
227 Query::__paramCount = _paramCount;
228 __params = new PeParam[Query::__paramCount];
229 if (__params == NULL) {
231 return false;
232 }
233
234 sqlvar_t* sqlvar = __inSQLDA->sqlvar;
235 for(size_t i = 0; i < Query::__paramCount; i++, sqlvar++) {
236 if (!__params[i].init(this, sqlvar))
237 return false;
238 }
239
240 return true;
241}

◆ reset()

bool PeQuery::reset ( )
protected

Definition at line 87 of file PeQuery.cpp.

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

Member Data Documentation

◆ __cursorDeclared

bool PeQuery::__cursorDeclared
protected

Definition at line 22 of file PeQuery.h.

◆ __cursorID

ByteString PeQuery::__cursorID
protected

Definition at line 17 of file PeQuery.h.

◆ __cursorOpened

bool PeQuery::__cursorOpened
protected

Definition at line 23 of file PeQuery.h.

◆ __fields

PeField* PeQuery::__fields
protected

Definition at line 25 of file PeQuery.h.

◆ __inSQLDA

sqlda_t* PeQuery::__inSQLDA
protected

Definition at line 20 of file PeQuery.h.

◆ __outSQLDA

sqlda_t* PeQuery::__outSQLDA
protected

Definition at line 19 of file PeQuery.h.

◆ __params

PeParam* PeQuery::__params
protected

Definition at line 26 of file PeQuery.h.

◆ __statementID

ByteString PeQuery::__statementID
protected

Definition at line 16 of file PeQuery.h.


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