Bug #67462 [Ana->Csd]: PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction

From: Date: Fri, 31 Oct 2014 18:00:45 +0000
Subject: Bug #67462 [Ana->Csd]: PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188389@lists.php.net to get a copy of this message
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: PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction -Status: Analyzed +Status: Closed Type: Bug Package: PDO PgSQL Operating System: * PHP Version: 5.5.13 Assigned To: mbeccati Block user comment: N Private report: N New Comment: Automatic comment on behalf of mbeccati Revision: http://git.php.net/?p=php-src.git;a=commit;h=9580fcfeddf85f6510217fec2f596f6f5169f251 Log: Fixed bug #67462 PDO_PGSQL::beginTransaction() wrongly throws exception when not in transaction Previous Comments: ------------------------------------------------------------------------ [2014-10-31 16:44:47] mbeccati@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#188389) next »