Re: 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: Re: libpq: how to get a sequence of partial PGresult-s
Date: 2003-09-23 23:19:46
Message-ID: 200309240219.46163.igor@carcass.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

As far as I understand, the incomplete PGresult is completed when
CommandComplete message is recieved.
Basically it only reads/sets conn->result->cmdStatus.
PQreadNextResult would have to set a fake good result (in this usage scenario,
this is app's responsibility to rollback in case of error even if it appears
later).

Rows are added only via pqAddTuple(...), and it's called only on valid tuples
(complete DataRow message is recieved and converted to a tuple
(PGresAttValue)), so it seems that the last row is always ok.

On Wednesday 24 September 2003 02:00, Igor Shevchenko wrote:
> On Wednesday 24 September 2003 01:27, you wrote:
> > Igor Shevchenko <igor(at)carcass(dot)ath(dot)cx> writes:
> > > 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 );
> >
> > I think this is a really bad idea, because it destroys libpq's basic
> > concept that you get either success or failure for a command. Peeking
> > at a partially-arrived result might give you back some rows only to get
> > an error later (since the backend may fail partway through a query).
>
> Unfortunately there's no way to archieve both streaming an errorless
> PQgetResult, but in case of error, the application will recieve an error
> message later anyway. So, in this context, it can only be application's
> resposibility to rollback changes done by data that is already processed.
> Btw, the same can happen with cursors approach.
>
> > I'm not sure that the partially constructed result is valid anyway;
> > the last row may be in a funny state. And what happens if the
> > application does a PQclear() on it??
>
> The application would recieve a deep copy of PGresult, so PQclear()
> wouldn't affect current PGconn->result.
>
> Btw, I was thinking about PQgetNextResult only for the async/non-blocking
> context.

--
Best regards,
Igor Shevchenko

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Roman Bogorodskiy 2003-09-24 03:18:41 Re: troubles with getting data from tables
Previous Message Igor Shevchenko 2003-09-23 23:00:05 Re: libpq: how to get a sequence of partial PGresult-s