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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to