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: Open Package: PDO SQLite
PHP Version: Irrelevant OS: Ubuntu 20.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 04:01:30 2024 UTC