PQexecPrepared with cursor to fetch single results

From: Maurizio Oristanio <maurizio(dot)oristanio(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQexecPrepared with cursor to fetch single results
Date: 2008-04-28 12:21:49
Message-ID: d2148b0c-1da6-4296-b104-25e298816521@l42g2000hsc.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2008-04-28 14:00:34 Re: pgstat SRF?
Previous Message Tom Dunstan 2008-04-28 11:49:32 Re: Re: [COMMITTERS] pgsql: Update: < * Allow adding enumerated values to an existing