diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fc86ae..4661433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ - New #357, #363: Implement `ArrayMergeBuilder`, `LongestBuilder` and `ShortestBuilder` classes (@Tigrov) - Enh #360: Refactor `DMLQueryBuilder::upsert()` method (@Tigrov) - Chg #365: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov) +- Enh #359: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin) ## 1.3.0 March 21, 2024 diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index a1cbaae..9327901 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder; @@ -54,6 +55,19 @@ public function insertReturningPks(string $table, array|QueryInterface $columns, throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.'); } + public function update( + string $table, + array $columns, + array|string|ExpressionInterface $condition, + array|string|ExpressionInterface|null $from = null, + array &$params = [] + ): string { + if ($from !== null) { + throw new NotSupportedException('Oracle does not support FROM clause in UPDATE statement.'); + } + return parent::update($table, $columns, $condition, null, $params); + } + /** * @link https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606 */ diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 9d9ef25..482a619 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -10,6 +10,7 @@ use Yiisoft\Db\Constraint\Index; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Oracle\Column\ColumnBuilder; use Yiisoft\Db\Oracle\IndexType; use Yiisoft\Db\Oracle\Tests\Provider\CommandProvider; @@ -483,12 +484,17 @@ public function testNoTablenameReplacement(): void public function testUpdate( string $table, array $columns, - array|string $conditions, + array|ExpressionInterface|string $conditions, + array|ExpressionInterface|string|null $from, array $params, array $expectedValues, int $expectedCount, ): void { - parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); + if ($from !== null) { + $this->expectException(NotSupportedException::class); + $this->expectExceptionMessage('Oracle does not support FROM clause in UPDATE statement.'); + } + parent::testUpdate($table, $columns, $conditions, $from, $params, $expectedValues, $expectedCount); } #[DataProviderExternal(CommandProvider::class, 'upsert')] diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 99898b9..b8d992d 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -476,12 +476,17 @@ public function testSelectExists(): void public function testUpdate( string $table, array $columns, - array|string $condition, + array|ExpressionInterface|string $condition, + array|ExpressionInterface|string|null $from, array $params, string $expectedSql, array $expectedParams = [], ): void { - parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams); + if ($from !== null) { + $this->expectException(NotSupportedException::class); + $this->expectExceptionMessage('Oracle does not support FROM clause in UPDATE statement.'); + } + parent::testUpdate($table, $columns, $condition, $from, $params, $expectedSql, $expectedParams); } #[DataProviderExternal(QueryBuilderProvider::class, 'upsert')]