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

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: consequent PQsendQueryPrepared() failed: another command is already in progress
Дата
Msg-id 1276710237.5362.20.camel@jdavis
обсуждение исходный текст
Ответ на consequent PQsendQueryPrepared() failed: another command is already in progress  (Anton Maksimenkov <anton200@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Misunderstanding transactions and locks
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Dynamic triggers