From fb9f2a109c386b2ef1a114683021469310031971 Mon Sep 17 00:00:00 2001 From: Rustam Date: Wed, 20 Aug 2025 17:27:50 +0500 Subject: [PATCH 1/7] Adapt to db changes --- tests/CommandTest.php | 7 ++++--- tests/QueryBuilderTest.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 9d9ef251..c2aad991 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,12 @@ public function testNoTablenameReplacement(): void public function testUpdate( string $table, array $columns, - array|string $conditions, - array $params, + array|ExpressionInterface|string $conditions, + array|ExpressionInterface|string|null $from, array $expectedValues, int $expectedCount, ): void { - parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); + parent::testUpdate($table, $columns, $conditions, $from, $expectedValues, $expectedCount); } #[DataProviderExternal(CommandProvider::class, 'upsert')] diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 4c20585b..9cae6c18 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -468,12 +468,13 @@ 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); + parent::testUpdate($table, $columns, $condition, $from, $params, $expectedSql, $expectedParams); } #[DataProviderExternal(QueryBuilderProvider::class, 'upsert')] From 518cd47cca484d1d3529cbba152f5a6ec8c85dad Mon Sep 17 00:00:00 2001 From: Rustam Date: Thu, 4 Sep 2025 22:08:22 +0500 Subject: [PATCH 2/7] Override update method --- src/DMLQueryBuilder.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index a1cbaae4..acec2a39 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 { + /** + * Oracle does not support UPDATE ... FROM ... + */ + return parent::update($table, $columns, $condition, null, $params); + } + /** * @link https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606 */ From 0e93b807ebf779f088c58b679e58b752b437c554 Mon Sep 17 00:00:00 2001 From: Rustam Date: Fri, 5 Sep 2025 15:07:06 +0500 Subject: [PATCH 3/7] Fix tests --- tests/Provider/QueryBuilderProvider.php | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index c7f51bfd..6d2cd429 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -142,6 +142,51 @@ public static function insert(): array return $insert; } + public static function update(): array + { + $data = parent::update(); + foreach ($data as $key => $item) { + if ($item[3] !== null) { + unset($data[$key]); + } + } + return array_merge( + $data, + [ + [ + '{{table}}', + ['name' => '{{tmp}}.{{name}}'], + [], + 'tmp', + [], + self::replaceQuotes( + << new Param('{{tmp}}.{{name}}', DataType::STRING), + ], + ], + [ + '{{table}}', + ['name' => '{{tmp}}.{{name}}'], + [], + ['tmp' => self::getDb()->select()->from('{{tmp}}')], + [], + self::replaceQuotes( + << new Param('{{tmp}}.{{name}}', DataType::STRING), + ], + ], + ] + ); + } + public static function upsert(): array { $concreteData = [ From 4b0f95a4c433ee294e1f9668c03a358816b6fedd Mon Sep 17 00:00:00 2001 From: Rustam Date: Sun, 7 Sep 2025 11:43:16 +0500 Subject: [PATCH 4/7] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fc86ae1..46614336 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 From 8f6c0ed08326bf52c8ecdeb5d8e2923c864cbfb0 Mon Sep 17 00:00:00 2001 From: Rustam Date: Mon, 8 Sep 2025 19:13:06 +0500 Subject: [PATCH 5/7] Bring back $params argument --- tests/CommandTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index c2aad991..353d52de 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -486,10 +486,11 @@ public function testUpdate( array $columns, array|ExpressionInterface|string $conditions, array|ExpressionInterface|string|null $from, + array $params, array $expectedValues, int $expectedCount, ): void { - parent::testUpdate($table, $columns, $conditions, $from, $expectedValues, $expectedCount); + parent::testUpdate($table, $columns, $conditions, $from, $params, $expectedValues, $expectedCount); } #[DataProviderExternal(CommandProvider::class, 'upsert')] From f688bcfe485a25dfdd7264594779bebd3d4c323e Mon Sep 17 00:00:00 2001 From: Rustam Date: Tue, 9 Sep 2025 21:20:49 +0500 Subject: [PATCH 6/7] Prevent usage of unsupported UPDATE with FROM clause. Added exceptions in Oracle, MySQL, and SQL Server query builders to explicitly throw errors if the FROM clause is used in an UPDATE statement. This ensures clarity and avoids unexpected behavior in unsupported scenarios. --- src/DMLQueryBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index acec2a39..68dd48bf 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -62,9 +62,9 @@ public function update( array|string|ExpressionInterface|null $from = null, array &$params = [] ): string { - /** - * Oracle does not support UPDATE ... FROM ... - */ + if ($from !== null) { + throw new NotSupportedException('Oracle does not support UPDATE with FROM clause.'); + } return parent::update($table, $columns, $condition, null, $params); } From 1fa806e312423158cc59232601b579ef78558062 Mon Sep 17 00:00:00 2001 From: Rustam Date: Wed, 10 Sep 2025 14:08:53 +0500 Subject: [PATCH 7/7] Fix tests --- src/DMLQueryBuilder.php | 2 +- tests/CommandTest.php | 4 +++ tests/Provider/QueryBuilderProvider.php | 45 ------------------------- tests/QueryBuilderTest.php | 4 +++ 4 files changed, 9 insertions(+), 46 deletions(-) diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index 68dd48bf..93279011 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -63,7 +63,7 @@ public function update( array &$params = [] ): string { if ($from !== null) { - throw new NotSupportedException('Oracle does not support UPDATE with FROM clause.'); + throw new NotSupportedException('Oracle does not support FROM clause in UPDATE statement.'); } return parent::update($table, $columns, $condition, null, $params); } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 353d52de..482a619f 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -490,6 +490,10 @@ public function testUpdate( array $expectedValues, int $expectedCount, ): void { + 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); } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 6d2cd429..c7f51bfd 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -142,51 +142,6 @@ public static function insert(): array return $insert; } - public static function update(): array - { - $data = parent::update(); - foreach ($data as $key => $item) { - if ($item[3] !== null) { - unset($data[$key]); - } - } - return array_merge( - $data, - [ - [ - '{{table}}', - ['name' => '{{tmp}}.{{name}}'], - [], - 'tmp', - [], - self::replaceQuotes( - << new Param('{{tmp}}.{{name}}', DataType::STRING), - ], - ], - [ - '{{table}}', - ['name' => '{{tmp}}.{{name}}'], - [], - ['tmp' => self::getDb()->select()->from('{{tmp}}')], - [], - self::replaceQuotes( - << new Param('{{tmp}}.{{name}}', DataType::STRING), - ], - ], - ] - ); - } - public static function upsert(): array { $concreteData = [ diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 31787b67..b8d992de 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -482,6 +482,10 @@ public function testUpdate( string $expectedSql, array $expectedParams = [], ): void { + 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); }