Bug #67462 [Opn->Ana]: PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction
Edit report at https://bugs.php.net/bug.php?id=67462&edit=1
ID: 67462
Updated by: mbeccati@php.net
Reported by: piotr dot m at shwrm dot com
-Summary: Postgres/PDO inTransaction() returns false while
transaction is still active.
+Summary: PDO_PGSQL::beginTransaction() wrongly throws
exception when not in transaction
-Status: Open
+Status: Analyzed
Type: Bug
Package: PDO PgSQL
-Operating System: Linux/Ubuntu 14.04
+Operating System: *
PHP Version: 5.5.13
-Assigned To:
+Assigned To: mbeccati
Block user comment: N
Private report: N
New Comment:
The expected result is wrong. It should be:
bool(true)
bool(false)
as in:
regression=# begin; create table t (a int not null primary key deferrable initially deferred);
insert into t values (1), (1);
BEGIN
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_pkey" for table
"t"
CREATE TABLE
INSERT 0 2
regression=# commit;
ERROR: duplicate key value violates unique constraint "t_pkey"
DETAIL: Key (a)=(1) already exists.
regression=# rollback;
NOTICE: there is no transaction in progress
ROLLBACK
However, no PDOException "There is already an active transaction" should be raised.
Previous Comments:
------------------------------------------------------------------------
[2014-06-17 11:57:52] piotr dot m at shwrm dot com
Description:
------------
PDOConnection->inTransaction() combined with PostgreSQL seems to return false after a failed
commit exception is caught by the try/catch block.
This problem seems to occur both in CLI mode and when called via FPM.
One more bit of information: the DB constraint that causes the duplicate key exception is in
"DEFERRABLE INITIALLY DEFERRED" mode so it will be checked after COMMIT is called, not
immediately after an update statement is executed.
PHP: 5.5.13-1~dotdeb.1 (both FPM and CLI)
Postgresql: "PostgreSQL 9.3.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5)
4.7.2, 64-bit"
Test script:
---------------
$con = new \PDO('pgsql:host=127.0.0.1;port=5432;dbname=;user=;password=');
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->beginTransaction();
$prod = $con->prepare(/** QUERY THAT CAUSES SQLSTATE[23505]: Unique violation: 7 ERROR:
duplicate key value**/);
$prod->execute();
try {
var_dump($con->inTransaction());
$con->commit();
} catch (\Exception $e) {
var_dump($con->inTransaction());
$con->inTransaction() or $con->beginTransaction();
}
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(true)
bool(false)
PHP Fatal error: Uncaught exception 'PDOException' with message 'There is already an
active transaction' in ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67462&edit=1
Thread (3 messages)