Re: consequent PQsendQueryPrepared() failed: another command is already in progress - Mailing list pgsql-general

From Jeff Davis
Subject Re: consequent PQsendQueryPrepared() failed: another command is already in progress
Date
Msg-id 1276710237.5362.20.camel@jdavis
Whole thread Raw
In response to consequent PQsendQueryPrepared() failed: another command is already in progress  (Anton Maksimenkov <anton200@gmail.com>)
List pgsql-general
On Wed, 2010-06-16 at 10:26 +0600, Anton Maksimenkov wrote:
>     if ((res = PQgetResult(conn)) == NULL) {
>         fprintf(stderr, "PQgetResult() res == NULL");
>         PQfinish(conn);
>         return -1;
>     }
>     if (PQresultStatus(res) != PGRES_TUPLES_OK) {
>         fprintf(stderr, "PQgetResult() failed: %s", PQerrorMessage(conn));
>         PQclear(res);
>         PQfinish(conn);
>         return -1;
>     }
>


> SECOND: PQsendQueryPrepared() failed: another command is already in progress
>
> Where I was wrong?
>

You need to call PQgetResult() again. From the docs
http://www.postgresql.org/docs/9.0/static/libpq-async.html :

"PQgetResult must be called repeatedly until it returns a null pointer,
indicating that the command is done."

After you get a NULL back from PQgetResult, you can execute another
command.


>
> And another question. Is it possible to simultaneously keep a number
> of prepared queries and run any of them from time to time?

Yes, although a prepared query lasts only as long as the connection.
When you disconnect and reconnect, you will need to prepare them again.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Misunderstanding transactions and locks
Next
From: Adrian Klaver
Date:
Subject: Re: Dynamic triggers