diff --git a/CHANGELOG.md b/CHANGELOG.md index 2498dfb15..4b21995d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ - New #988: Add `CaseExpression` and `CaseExpressionBuilder` to build `CASE-WHEN-THEN-ELSE` SQL expressions (@Tigrov) - Enh #991: Improve types in `ConnectionInterface::transaction()` (@kikara) - Chg #998: Add `yiisoft/db-implementation` virtual package as dependency (@vjik) +- Chg #999: Remove `requireTransaction()` method and `$isolationLevel` property from `AbstractCommand` (@vjik) ## 1.3.0 March 21, 2024 diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index c92872710..0e634df91 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -113,11 +113,6 @@ public function __construct( */ protected const QUERY_MODE_SCALAR = 32; - /** - * @var string|null Transaction isolation level. - */ - protected string|null $isolationLevel = null; - /** * @var ParamInterface[] Parameters to use. */ @@ -663,19 +658,6 @@ protected function requireTableSchemaRefresh(string $name): static return $this; } - /** - * Marks the command to execute in transaction. - * - * @param string|null $isolationLevel The isolation level to use for this transaction. - * - * {@see \Yiisoft\Db\Transaction\TransactionInterface::begin()} for details. - */ - protected function requireTransaction(?string $isolationLevel = null): static - { - $this->isolationLevel = $isolationLevel; - return $this; - } - /** * Resets the command object, so it can be reused to build another SQL statement. */ @@ -684,7 +666,6 @@ protected function reset(): void $this->sql = ''; $this->params = []; $this->refreshTableName = null; - $this->isolationLevel = null; $this->retryHandler = null; } diff --git a/src/Driver/Pdo/AbstractPdoCommand.php b/src/Driver/Pdo/AbstractPdoCommand.php index 1f914285c..905e89a3a 100644 --- a/src/Driver/Pdo/AbstractPdoCommand.php +++ b/src/Driver/Pdo/AbstractPdoCommand.php @@ -206,31 +206,18 @@ protected function getQueryMode(int $queryMode): string */ protected function internalExecute(): void { - $attempt = 0; - - while (true) { + for ($attempt = 0; ; ++$attempt) { try { - if ( - ++$attempt === 1 - && $this->isolationLevel !== null - && $this->db->getTransaction() === null - ) { - $this->db->transaction( - fn () => $this->internalExecute(), - $this->isolationLevel - ); - } else { - set_error_handler( - static fn(int $errorNumber, string $errorString): bool => - str_starts_with($errorString, 'Packets out of order. Expected '), - E_WARNING, - ); - - try { - $this->pdoStatement?->execute(); - } finally { - restore_error_handler(); - } + set_error_handler( + static fn(int $errorNumber, string $errorString): bool => + str_starts_with($errorString, 'Packets out of order. Expected '), + E_WARNING, + ); + + try { + $this->pdoStatement?->execute(); + } finally { + restore_error_handler(); } break; } catch (PDOException $e) { diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 79567961f..22bd12627 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Db\Tests\Common; use PHPUnit\Framework\Attributes\DataProviderExternal; -use ReflectionException; use Throwable; use Yiisoft\Db\Constant\DataType; use Yiisoft\Db\Command\Param; @@ -31,7 +30,6 @@ use Yiisoft\Db\Tests\Provider\CommandProvider; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\DbHelper; -use Yiisoft\Db\Transaction\TransactionInterface; use function array_filter; use function is_string; @@ -1128,68 +1126,6 @@ public function testExecuteWithoutSql(): void $db->close(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws ReflectionException - * @throws Throwable - */ - public function testExecuteWithTransaction(): void - { - $db = $this->getConnection(true); - - $this->assertNull($db->getTransaction()); - - $command = $db->createCommand( - <<execute(); - - $this->assertNull($db->getTransaction()); - - $this->assertEquals( - 1, - $db->createCommand( - <<queryScalar(), - ); - - $command = $db->createCommand( - <<execute(); - - $this->assertNull($db->getTransaction()); - - $this->assertEquals( - 1, - $db->createCommand( - <<queryScalar(), - ); - - $db->close(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws Throwable - */ public function testInsert(): void { $db = $this->getConnection(true); @@ -1878,12 +1814,6 @@ public function testRenameTable(): void $db->close(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws ReflectionException - * @throws Throwable - */ public function testSetRetryHandler(): void { $db = $this->getConnection(true); @@ -1942,47 +1872,6 @@ static function ($exception, $attempt) use (&$attempts, &$hitHandler) { $db->close(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws ReflectionException - * @throws Throwable - */ - public function testTransaction(): void - { - $db = $this->getConnection(true); - - $this->assertNull($db->getTransaction()); - - $command = $db->createCommand(); - $command = $command->setSql( - <<execute(); - - $this->assertNull($db->getTransaction()); - $this->assertEquals( - 1, - $command->setSql( - <<queryScalar(), - ); - - $db->close(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws Throwable - */ public function testTruncateTable(): void { $db = $this->getConnection(true);