Re: libpq - PQsendQuery wait for complete result - Mailing list pgsql-general

From Albe Laurenz
Subject Re: libpq - PQsendQuery wait for complete result
Date
Msg-id D960CB61B694CF459DCFB4B0128514C208C0C9AD@exadv11.host.magwien.gv.at
Whole thread Raw
In response to libpq - PQsendQuery wait for complete result  (icholy <ilia.choly@gmail.com>)
Responses Re: libpq - PQsendQuery wait for complete result
List pgsql-general
icholy wrote:
> I'm having problem with libpq's *PQexec* function hanging on
intermittent
> connections.
> After searching around, the solution seems to be to use the
asynchronous
> functions *PQsendQuery*/*PQgetResult* and implement your own timeout.
>
> Now the issue I'm facing is that *PQgetResult* needs to be called
multiple
> times until it returns *null* and then you know it's done.
> However, the rest of my application expects a single *PQresult* object
per
> query.
>
> So my question is:
>
> *A.* Is there a way to concatenate/join the multiple *PQresults*?

If you have a single SQL statement, you will get only one
PQresult.  You get more than one if you send a query string
with more than one statement, e.g.

PQsendQuery(conn, "SELECT 42; SELECT 'Hello'");

would result in two PQresults.

You can get multiple PQresults only using asynchronous
command processing; the corresponding PQexec would return
only the PQresult of the *last* statement executed.

So you can get the same behaviour as PQexec by discarding
all PQresults except for the last one.

> *B. *Can I somehow use *PQisBusy* & *PQconsumeInput* to wait until all
the
> results are ready before calling *PQgetResult*?

That is not necessary, as it will not influence the
number of PQresults you get (as described above).

These functions are only necessary if you want to avoid
blocking when you call PQgetResult.

Yours,
Laurenz Albe


pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: UPDATE syntax
Next
From: "Albe Laurenz"
Date:
Subject: Re: About aggregates...