Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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


pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group