Re: consequent PQsendQueryPrepared() failed: another command is already in progress

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Anton Maksimenkov <anton200(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: consequent PQsendQueryPrepared() failed: another command is already in progress
Date: 2010-06-16 17:43:57
Message-ID: 1276710237.5362.20.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2010-06-16 18:31:39 Re: hi,i write a function in postgresql source code, how to register this function?
Previous Message sunpeng 2010-06-16 16:42:25 hi, i write a function in postgresql source code, how to register this function?