Обсуждение: PQexecPrepared with cursor to fetch single results

Поиск
Список
Период
Сортировка

PQexecPrepared with cursor to fetch single results

От
Maurizio Oristanio
Дата:
if you need a scrollable cursor for a prepared statement (to fetch
single rows from huge result sets)
while still being able to execute statements on the same connection
you can do it this way:

PGresult* res = PQprepare( con, "statement1", "declare cu1 scroll
cursor with hold for select * from table where col1=$1", 0, NULL );
PGresult* res2 = PQdescribePrepared( con, "statement1" );
//now use PQnparams and PQnparamtype to determine parameter
information
//and set paramCount, paramValues and paramLength accordingly
PGresult* res3 = PQexecPrepared( con, "statement1", paramCount,
paramValues, paramLength, paramFormat, 0 );
PGresult* res4 = PQexec( con, "fetch forward 100 from cu1" ); //to
receive 100 rows from the server
//now with PQnfields, PQftype and PQfname and PQgetvalue access the
result - and other queries can be executed on the same connection