X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 29DEED1C9E5 for ; Tue, 23 Sep 2003 22:10:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 56417-02 for ; Tue, 23 Sep 2003 19:10:13 -0300 (ADT) Received: from wind.ukr.net (wind.ukr.net [212.42.64.10]) by svr1.postgresql.org (Postfix) with ESMTP id C19C4D1B57D for ; Tue, 23 Sep 2003 19:10:10 -0300 (ADT) Received: from 82-20.odessa.dialup.ukr.net ([212.42.82.20]) by wind.ukr.net with esmtp ID 1A1vM9-0002aS-Tt for pgsql-interfaces@postgresql.org; Wed, 24 Sep 2003 01:10:05 +0300 From: Igor Shevchenko To: pgsql-interfaces@postgresql.org Subject: libpq: how to get a sequence of partial PGresult-s Date: Wed, 24 Sep 2003 01:09:17 +0300 User-Agent: KMail/1.5.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200309240109.17024.igor@carcass.ath.cx> X-WIND.UKR.NET-ID: 305044e19232becbcafc7873a39cd520 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/61 X-Sequence-Number: 4479 Hi, 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 function. 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