Re: pg_transaction_status() unreliable?!

Поиск
Список
Период
Сортировка
От ljb
Тема Re: pg_transaction_status() unreliable?!
Дата
Msg-id gtitqq$26l3$1@news.hub.org
обсуждение исходный текст
Ответ на pg_transaction_status() unreliable?!  (Bill Moran <wmoran@potentialtech.com>)
Ответы Re: pg_transaction_status() unreliable?!  (Bill Moran <wmoran@potentialtech.com>)
Список pgsql-php
wmoran@potentialtech.com wrote:
>
> I'm having some ugly fun here.  It doesn't seem as if
> pg_transaction_status() is reliable in the least.
>
> For example, I'm doing the equivalent of the following:
>
> pg_send_query_params($conn, 'BEGIN', array());
> pg_get_result($conn);
> ... some other queries, each using pg_send_query_params() and
>  pg_get_result() ...
> pg_send_query_params($conn, 'COMMIT', array());
> pg_get_result($conn);
> echo pg_transaction_status($conn);
>
> Now, amazingly enough, pg_transaction_status() returns
> PGSQL_TRANSACTION_ACTIVE after the commit.  This makes no sense to
> me at all ... it should return PGSQL_TRANSACTION_IDLE, since the
> connection is no longer in a transaction.
>
> Is anyone else seeing this?  I have assertions failing all over the
> place because my code thinks that transactions have been left
> uncommitted.

One needs to loop on pg_get_result() until it returns False. Are you doing
this? I think perhaps you are not. You can sometimes sort of get away
with a single call, but it isn't a good idea to rely on it.

I duplicated your result by doing the COMMIT but only doing
pg_get_result once; then pg_transaction_status gave me the odd
PGSQL_TRANSACTION_ACTIVE. But if I loop on pg_get_result (it returns a
result handle, then false the next time), I get the expected IDLE status.


В списке pgsql-php по дате отправления:

Предыдущее
От: Bill Moran
Дата:
Сообщение: pg_transaction_status() unreliable?!
Следующее
От: Bill Moran
Дата:
Сообщение: Re: pg_transaction_status() unreliable?!