Req #77116 [Com]: implement in_transaction handler for pdo_mysql
Edit report at https://bugs.php.net/bug.php?id=77116&edit=1
ID: 77116
Comment by: remyfox at hotmail dot com
Reported by: remy dot fox at hotmail dot com
Summary: implement in_transaction handler for pdo_mysql
Status: Open
Type: Feature/Change Request
Package: PDO MySQL
PHP Version: irrelevant
Block user comment: N
Private report: N
New Comment:
In MySQL table schema structure changes such as CREATE TABLE cause an automatic commit of the
transaction. PDO.inTransaction always reacted to this, so I suspect that it does not only check a
bit flipped by beginTransaction/rollBack/commit methods.
Previous Comments:
------------------------------------------------------------------------
[2018-11-08 17:21:59] requinix@php.net
The Python API gets its in_transaction from MYSQL->server_status & 1.
------------------------------------------------------------------------
[2018-11-08 16:22:03] adambaratz@php.net
What you're experiencing is maybe not the best behavior, but pdo_mysql performing as it's
written. This driver doesn't define an in_transaction method, so it defaults to checking the
status of the bit flipped by the beginTransaction/rollBack/commit methods.
An in_transaction method could be implemented in ext/pdo_mysql/mysql_driver.c (see the definition of
mysql_methods at the bottom of that file for where the connection is made). If there's a C API
for checking transaction status, that would likely be more reliable than running a query. See the
pgsql_handle_in_transaction function in ext/pdo_pgsql/pgsql_driver.c for an example of this. FWIW,
pdo_pgsql is the only PDO driver shipped with PHP that implements this function.
------------------------------------------------------------------------
[2018-11-07 11:51:57] remy dot fox at hotmail dot com
Description:
------------
PDO has a function called 'inTransaction', which verifies whether a transaction is
currently active. As far as I can see it calls a method 'in_transaction' here: https://github.com/php/php-src/blob/master/ext/pdo/pdo_dbh.c
(line 656).
When I start the transaction using SQL ("START TRANSACTION") instead of the PDO API, the
result of inTransaction is always false. However, I'm confident a transaction is running,
because calling "ROLLBACK" does not commit any changes. On MariaDB, the following query
results "1", too: SELECT SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE
VARIABLE_NAME = 'in_transaction'.
So I suspect that there is something wrong with the inTransaction method. It only seems to work when
it is called in combination with beginTransaction, rather than in any case that a transaction was
started.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77116&edit=1
Thread (6 messages)