php.net |  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
Description:
------------
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:
---------------
$db->exec("BEGIN EXCLUSIVE TRANSACTION");
$alwaysFalse = $db->inTransaction();


Expected result:
----------------
$db->exec("BEGIN EXCLUSIVE TRANSACTION");
$shouldBeTrue = $db->inTransaction();

Actual result:
--------------
$db->exec("BEGIN EXCLUSIVE TRANSACTION");
$false = $db->inTransaction();

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-06 15:18 UTC] cmb@php.net
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] <https://sqlite.org/draft/c3ref/txn_state.html>
 [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] cmb@php.net
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] git@php.net
Automatic comment on behalf of nielsdos (author) and web-flow (committer)
Revision: https://github.com/php/php-src/commit/b7bf846f72c19548021a5c6e792dffddbb2a6436
Log: Fix bug #81227: PDO::inTransaction reports false when in transaction (#14268)
 [2024-05-20 11:59 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 04:01:29 2024 UTC