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

libpq: how to get a sequence of partial PGresult-s

From: Igor Shevchenko <igor(at)carcass(dot)ath(dot)cx>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: libpq: how to get a sequence of partial PGresult-s
Date: 2003-09-23 22:09:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces

I use PostgreSQL as a database for my gui app.
Some queries can take alot of time (e.g. app's search function), and I'd like 
to show recieved data as soon as it arrives. I've played with non-blocking 
mode and PQconsumeInput and as far as I can see, backend sends data (almost?) 
as soon as it's found. The libpq library (protocol v3) reads incoming data 
(DataRow messages) but returns PGresult only when the CommandComplete message 
is recieved. Is there any way to get/process this partial PGresult in my 
app ? I haven't found any API function for this, so I thought about an 
additional function for the libpq's API -

PGresult* PQgetNextResult ( PGconn* conn );

It'd make a tupleless copy of conn->result (PGresult), assign it to conn-
>result and return the old conn->result object, i.e. something like this :

PGresult* PQgetNextResult ( PGconn* conn ) {
	if ( !conn->result )
		return NULL;
	PGresult* res = conn->result;
	conn->result = pgMakeTuplelessCopy ( res );
	return res;

It's ok to return an empty PGresult (PQntuples(res) == 0);
NULL return value would still indicate the end of the query.
Libpq would still be able to recieve/process remaining DataRow results.
This would be a better counterpart to mysql's mysql_fetch_row(...) api 

Does this makes sence ?

Btw I know about sql cursors but I'd have to repeat "fetch next from mycursor" 
for all resulting tuples, which is a big processing/network overhead.

Best regards,
Igor Shevchenko


pgsql-interfaces by date

Next:From: Tom LaneDate: 2003-09-23 22:27:29
Subject: Re: libpq: how to get a sequence of partial PGresult-s
Previous:From: Ryan MooneyDate: 2003-09-23 21:12:07
Subject: ECPG insert into table name as a variable

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