|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81227 PDO::inTransaction reports false when in transaction
Submitted: 2021-07-06 14:33 UTC Modified: 2021-07-07 17:25 UTC
From: shariefjamiel at gmail dot com Assigned:
Status: Closed Package: PDO SQLite
PHP Version: Irrelevant OS: Ubuntu 20.04
Private report: No CVE-ID: None
 [2021-07-06 14:33 UTC] shariefjamiel at gmail dot com
Using PHP 8.0.1 on Ubuntu 20.04 focal

I am executing `BEGIN EXCLUSIVE TRANSACTION` due to a locking issue, but the problem is PDO::inTransaction returns false despite being in a transaction, which leads to errors later on.

Test script:
$alwaysFalse = $db->inTransaction();

Expected result:
$shouldBeTrue = $db->inTransaction();

Actual result:
$false = $db->inTransaction();


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-06 15:18 UTC]
PDO_SQLite does not implement an in_txn handler, and so the
transaction status is only tracked according to
PDO::beginTransaction() and friends.  To be able to implement the
in_txn handler, we would need to employ the sqlite3_txn_state()
function, which is only available as of SQLite3 3.34.0
(2020-12-01), and still marked as draft in the docs[1].

[1] <>
 [2021-07-06 15:34 UTC] shariefjamiel at gmail dot com
I am getting a race condition with sqlite when executing a script at the exact same second, hence why I am trying to use this exclusive transaction feature. 
Would it make more sense to add an option to beginTransaction method, to offer better backwards compatibility.
 [2021-07-07 17:25 UTC]
I think using sqlite3_txn_state() when/where available is way less
controversial, because it only affects PDO_SQLite.
 [2024-05-20 11:59 UTC]
Automatic comment on behalf of nielsdos (author) and web-flow (committer)
Log: Fix bug #81227: PDO::inTransaction reports false when in transaction (#14268)
 [2024-05-20 11:59 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 15:01:29 2024 UTC