1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix bug #81227: PDO::inTransaction reports false when in transaction (#14268)

This commit is contained in:
Niels Dossche
2024-05-20 13:59:26 +02:00
committed by GitHub
parent 9aa3a0d702
commit b7bf846f72
3 changed files with 42 additions and 1 deletions

2
NEWS
View File

@@ -179,6 +179,8 @@ PHP NEWS
- PDO_SQLITE:
. Added class PdoSqlite. (danack, kocsismate)
. Fixed bug #81227 (PDO::inTransaction reports false when in transaction).
(nielsdos)
- PGSQL:
. Added the possibility to have no conditions for pg_select. (OmarEmaraDev)

View File

@@ -282,6 +282,15 @@ static int pdo_sqlite_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return
return 1;
}
static bool pdo_sqlite_in_transaction(pdo_dbh_t *dbh)
{
pdo_sqlite_db_handle* H = (pdo_sqlite_db_handle*) dbh->driver_data;
/* It's not possible in sqlite3 to explicitly turn autocommit off other
* than manually starting a transaction. Manual transactions always are
* the mode of operation when autocommit is off. */
return H->db && sqlite3_get_autocommit(H->db) == 0;
}
static bool pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
@@ -733,7 +742,7 @@ static const struct pdo_dbh_methods sqlite_methods = {
NULL, /* check_liveness: not needed */
get_driver_methods,
pdo_sqlite_request_shutdown,
NULL, /* in transaction, use PDO's internal tracking mechanism */
pdo_sqlite_in_transaction,
pdo_sqlite_get_gc
};

View File

@@ -0,0 +1,30 @@
--TEST--
Bug #81227 (PDO::inTransaction reports false when in transaction)
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
$db = new PDO("sqlite::memory:");
var_dump($db->inTransaction());
$db->exec("BEGIN EXCLUSIVE TRANSACTION");
var_dump($db->inTransaction());
try {
$db->beginTransaction();
} catch (PDOException $e) {
echo $e->getMessage(), "\n";
}
$db->commit();
var_dump($db->inTransaction());
$db->beginTransaction();
var_dump($db->inTransaction());
?>
--EXPECT--
bool(false)
bool(true)
There is already an active transaction
bool(false)
bool(true)