diff --git a/CHANGELOG b/CHANGELOG index e464267470..410d537aab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Version 1.1.32 under development - Enh #4587: Add socket connection support to `CRedisCache` (mateusmetzker) - Bug #4591: Fix deprecation in `CCaptchaAction` for PHP 8.1+ (rob006) +- Bug #4596: Fix transaction not commit when using dblib (icyzyy) Version 1.1.31 April 10, 2025 -------------------------------- diff --git a/framework/db/schema/mssql/CMssqlPdoAdapter.php b/framework/db/schema/mssql/CMssqlPdoAdapter.php index 9862d55792..b09373b71b 100644 --- a/framework/db/schema/mssql/CMssqlPdoAdapter.php +++ b/framework/db/schema/mssql/CMssqlPdoAdapter.php @@ -29,18 +29,36 @@ public function lastInsertId ($sequence=NULL) return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn(); } + /** + * Checks if inside a transaction + * + * Checks if a transaction is currently active within the driver. + * This method always true if PHP below 5.4.0 to make it able to exec 'COMMIT TRANSACTION' + * @return boolean + */ + function inTransaction() + { + if(version_compare(PHP_VERSION,'5.4.0','>=')) + return parent::inTransaction(); + else + return true; + } + /** * Begin a transaction * * Is is necessary to override pdo's method, as mssql pdo drivers - * does not support transaction + * does not support transaction for PHP below 5.4.0 * * @return boolean */ #[ReturnTypeWillChange] public function beginTransaction () { - $this->exec('BEGIN TRANSACTION'); + if(version_compare(PHP_VERSION,'5.4.0','>=')) + parent::beginTransaction(); + else + $this->exec('BEGIN TRANSACTION'); return true; } @@ -48,14 +66,17 @@ public function beginTransaction () * Commit a transaction * * Is is necessary to override pdo's method, as mssql pdo drivers - * does not support transaction + * does not support transaction for PHP below 5.4.0 * * @return boolean */ #[ReturnTypeWillChange] public function commit () { - $this->exec('COMMIT TRANSACTION'); + if(version_compare(PHP_VERSION,'5.4.0','>=')) + parent::commit(); + else + $this->exec('COMMIT TRANSACTION'); return true; } @@ -63,14 +84,17 @@ public function commit () * Rollback a transaction * * Is is necessary to override pdo's method, ac mssql pdo drivers - * does not support transaction + * does not support transaction for PHP below 5.4.0 * * @return boolean */ #[ReturnTypeWillChange] public function rollBack () { - $this->exec('ROLLBACK TRANSACTION'); + if(version_compare(PHP_VERSION,'5.4.0','>=')) + parent::rollBack(); + else + $this->exec('ROLLBACK TRANSACTION'); return true; } }