PQexecPrepared with cursor to fetch single results - Mailing list pgsql-hackers

From Maurizio Oristanio
Subject PQexecPrepared with cursor to fetch single results
Date
Msg-id d2148b0c-1da6-4296-b104-25e298816521@l42g2000hsc.googlegroups.com
Whole thread Raw
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: we don't have a bugzilla
Next
From: Magnus Hagander
Date:
Subject: Re: pgstat SRF?