Skip to content

Commit 8152ca9

Browse files
authored
Adapt to db changes (#359)
1 parent 553a164 commit 8152ca9

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
- New #357, #363: Implement `ArrayMergeBuilder`, `LongestBuilder` and `ShortestBuilder` classes (@Tigrov)
6262
- Enh #360: Refactor `DMLQueryBuilder::upsert()` method (@Tigrov)
6363
- Chg #365: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov)
64+
- Enh #359: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin)
6465

6566
## 1.3.0 March 21, 2024
6667

src/DMLQueryBuilder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use InvalidArgumentException;
88
use Yiisoft\Db\Exception\NotSupportedException;
9+
use Yiisoft\Db\Expression\ExpressionInterface;
910
use Yiisoft\Db\Query\QueryInterface;
1011
use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder;
1112

@@ -54,6 +55,19 @@ public function insertReturningPks(string $table, array|QueryInterface $columns,
5455
throw new NotSupportedException(__METHOD__ . ' is not supported by Oracle.');
5556
}
5657

58+
public function update(
59+
string $table,
60+
array $columns,
61+
array|string|ExpressionInterface $condition,
62+
array|string|ExpressionInterface|null $from = null,
63+
array &$params = []
64+
): string {
65+
if ($from !== null) {
66+
throw new NotSupportedException('Oracle does not support FROM clause in UPDATE statement.');
67+
}
68+
return parent::update($table, $columns, $condition, null, $params);
69+
}
70+
5771
/**
5872
* @link https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606
5973
*/

tests/CommandTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Yiisoft\Db\Constraint\Index;
1111
use Yiisoft\Db\Exception\Exception;
1212
use Yiisoft\Db\Exception\NotSupportedException;
13+
use Yiisoft\Db\Expression\ExpressionInterface;
1314
use Yiisoft\Db\Oracle\Column\ColumnBuilder;
1415
use Yiisoft\Db\Oracle\IndexType;
1516
use Yiisoft\Db\Oracle\Tests\Provider\CommandProvider;
@@ -483,12 +484,17 @@ public function testNoTablenameReplacement(): void
483484
public function testUpdate(
484485
string $table,
485486
array $columns,
486-
array|string $conditions,
487+
array|ExpressionInterface|string $conditions,
488+
array|ExpressionInterface|string|null $from,
487489
array $params,
488490
array $expectedValues,
489491
int $expectedCount,
490492
): void {
491-
parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount);
493+
if ($from !== null) {
494+
$this->expectException(NotSupportedException::class);
495+
$this->expectExceptionMessage('Oracle does not support FROM clause in UPDATE statement.');
496+
}
497+
parent::testUpdate($table, $columns, $conditions, $from, $params, $expectedValues, $expectedCount);
492498
}
493499

494500
#[DataProviderExternal(CommandProvider::class, 'upsert')]

tests/QueryBuilderTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,17 @@ public function testSelectExists(): void
476476
public function testUpdate(
477477
string $table,
478478
array $columns,
479-
array|string $condition,
479+
array|ExpressionInterface|string $condition,
480+
array|ExpressionInterface|string|null $from,
480481
array $params,
481482
string $expectedSql,
482483
array $expectedParams = [],
483484
): void {
484-
parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams);
485+
if ($from !== null) {
486+
$this->expectException(NotSupportedException::class);
487+
$this->expectExceptionMessage('Oracle does not support FROM clause in UPDATE statement.');
488+
}
489+
parent::testUpdate($table, $columns, $condition, $from, $params, $expectedSql, $expectedParams);
485490
}
486491

487492
#[DataProviderExternal(QueryBuilderProvider::class, 'upsert')]

0 commit comments

Comments
 (0)