257{
259
260 ByteString cursorID = ByteString::format(
"curs_%d",
__stmtNo);
261 ByteStringBuilder cmd(
__query.length() + 20);
262 cmd.assign(
"DECLARE ").append(cursorID).append(
" CURSOR FOR ").append(
__query);
263 PGresult* res = PQexecParams(conn()->connHandle(), cmd,
267 );
268 if (PQresultStatus(res) != PGRES_COMMAND_OK) {
270 PQclear(res);
271 return false;
272 }
273 PQclear(res);
275 Query::__eof = false;
276
277 res = PQdescribePortal(conn()->connHandle(), cursorID);
278 if (PQresultStatus(res) != PGRES_COMMAND_OK) {
280 PQclear(res);
281 return false;
282 }
283#if defined(__DCL_DEBUG) && __TRACE_THIS && 0
284 for (int i = 0; i < PQnfields(res); i++) {
285 Oid oid = PQftype(res, i);
287 PQfsize(res, i), PQfmod(res, i), PQfformat(res, i),
288 oid, PQfname(res, i)
289 );
290 }
291#endif
294 && (Query::__fieldCount == 0)
295 );
297 __fields =
new PqField[Query::__fieldCount];
300 return false;
301 }
302
303 for (size_t i = 0; i < Query::__fieldCount; i++) {
304 if (!
__fields[i].init(
this, (
int)i, res))
305 return false;
306 }
307 PQclear(res);
308 }
309 else {
310
311#if defined(__DCL_DEBUG) && __TRACE_THIS && 0
312 for (size_t i = 0; i < Query::__paramCount; i++) {
317 );
318 }
319#endif
320 PGresult* res = PQexecPrepared(conn()->connHandle(),
__stmtID,
321 (int)Query::__paramCount,
324 );
325 switch (PQresultStatus(res)) {
326 case PGRES_COMMAND_OK: {
327
328 char* psz = PQcmdTuples(res);
329 if (psz) {
330 Query::__affectedRows = strtoll(psz,
NULL, 10);
331 }
332 PQclear(res);
333 break;
334 }
335 case PGRES_TUPLES_OK: {
336 if (
__nfields != (
int)Query::__fieldCount) {
339 && (Query::__fieldCount == 0)
340 );
342 __fields =
new PqField[Query::__fieldCount];
345 return false;
346 }
347
348 for (size_t i = 0; i < Query::__fieldCount; i++) {
349 if (!
__fields[i].init(
this, (
int)i, res))
350 return false;
351 }
352 }
356 Query::__eof = false;
357 break;
358 }
359 default: {
361 PQclear(res);
362 return false;
363 }
364 }
365 }
366
367 for(size_t i = 0; i < Query::__paramCount; i++) {
372
373 if (!(
__params[i].onAfterExecute()))
374 return false;
375 }
376
377 return true;
378}
#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
#define __SET_ERROR_MSG(_message)
const wchar_t * __dataTypeName(const ifx_sqlvar_t *_sqlvar)
#define __DCL_TRACE6_N(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
#define __DCL_ASSERT(expr)
#define __SET_BIND_LENGTH(_index, _length)
#define __SET_BIND_VALUE(_index, _value)
#define __SET_BIND_FORMAT(_index, _format)
#define __SET_BIND_TYPE(_index, _type)
#define __CURSOR_ENABLED(_conn)
#define __SET_ERROR(_errorCode)