From dd06a265a06dd1510b849f78738356e09ef8cf7a Mon Sep 17 00:00:00 2001 From: halnique Date: Tue, 16 Jan 2024 16:21:12 +0900 Subject: [PATCH] fix: fixed an error when rolling back a transaction that did not execute begin (#166) * fix: fixed an error when rolling back a transaction that did not execute begin * test: fix cursor rollback * chore: update CHANGELOG * chore: fill release date --- CHANGELOG.md | 5 +++++ src/Concerns/ManagesTransactions.php | 2 +- tests/SessionNotFoundTest.php | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cdf774c..5fd04358 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ Changed Fixed - `Schema\Grammar::compileAdd()` `Schema\Grammar::compileChange()` `Schema\Grammar::compileChange()` now create separate statements (#159) +# v6.1.2 (2024-01-16) + +Fixed +- Fixed an error when rolling back a transaction that did not execute begin (#166) + # v6.1.1 (2023-12-11) Fixed diff --git a/src/Concerns/ManagesTransactions.php b/src/Concerns/ManagesTransactions.php index 368245a9..a79a602b 100644 --- a/src/Concerns/ManagesTransactions.php +++ b/src/Concerns/ManagesTransactions.php @@ -168,7 +168,7 @@ protected function performRollBack($toLevel) if ($this->currentTransaction !== null) { try { - if ($this->currentTransaction->state() === Transaction::STATE_ACTIVE) { + if ($this->currentTransaction->state() === Transaction::STATE_ACTIVE && $this->currentTransaction->id() !== null) { $this->currentTransaction->rollBack(); } } finally { diff --git a/tests/SessionNotFoundTest.php b/tests/SessionNotFoundTest.php index af2859f6..089993bd 100644 --- a/tests/SessionNotFoundTest.php +++ b/tests/SessionNotFoundTest.php @@ -160,13 +160,13 @@ public function test_session_not_found_on_cursor(): void $passes = 0; $conn->transaction(function () use ($conn, &$passes) { - $cursor = $conn->cursor('SELECT 12345'); - if ($passes === 0) { $this->deleteSession($conn); $passes++; } + $cursor = $conn->cursor('SELECT 12345'); + $this->assertEquals([12345], $cursor->current()); $passes++;