diff --git a/CHANGELOG.md b/CHANGELOG.md index bd49bd12..67d8f0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ - New #420, #427: Implement `ArrayMergeBuilder`, `LongestBuilder` and `ShortestBuilder` classes (@Tigrov) - Enh #423: Refactor `DMLQueryBuilder::upsert()` method (@Tigrov) - Chg #428: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov) +- Enh #442: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin) ## 1.2.0 March 21, 2024 diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index 7ecd3484..5c529b2a 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; use Yiisoft\Db\Schema\TableSchema; @@ -61,6 +62,19 @@ public function resetSequence(string $table, int|string|null $value = null): str EXECUTE autoincrement_stmt"; } + 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('MySQL does not support FROM clause in UPDATE statement.'); + } + return parent::update($table, $columns, $condition, null, $params); + } + public function upsert( string $table, array|QueryInterface $insertColumns, diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 58063842..f058582c 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Mysql\Tests\Provider\CommandProvider; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; @@ -118,12 +119,17 @@ public function testInsertReturningPksWithSubqueryAndNoAutoincrement(): 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('MySQL 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/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 096a50a3..6cdbba0a 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -298,8 +298,16 @@ public static function buildColumnDefinition(): array $values[PseudoType::UUID_PK_SEQ][0] = 'binary(16) PRIMARY KEY'; $values['uuidPrimaryKey()'][0] = 'binary(16) PRIMARY KEY'; $values['defaultValue($expression)'] = ['int DEFAULT 3', ColumnBuilder::integer()->defaultValue(3)]; - $values['timestamp(6)'] = ['timestamp(6) DEFAULT CURRENT_TIMESTAMP(6)', ColumnBuilder::timestamp(6)->defaultValue(new Expression('CURRENT_TIMESTAMP(6)'))]; - $values['timestamp(null)'] = ['timestamp DEFAULT CURRENT_TIMESTAMP', ColumnBuilder::timestamp(null)->defaultValue(new Expression('CURRENT_TIMESTAMP'))]; + $values['timestamp(6)'] = [ + 'timestamp(6) DEFAULT CURRENT_TIMESTAMP(6)', + ColumnBuilder::timestamp(6)->defaultValue(new Expression('CURRENT_TIMESTAMP(6)')), + ]; + $values['timestamp(null)'] = [ + 'timestamp DEFAULT CURRENT_TIMESTAMP', + ColumnBuilder::timestamp(null)->defaultValue( + new Expression('CURRENT_TIMESTAMP') + ), + ]; } return $values; diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 0ff74f26..f844b970 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -568,12 +568,17 @@ public function testResetSequence(): 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('MySQL does not support FROM clause in UPDATE statement.'); + } + parent::testUpdate($table, $columns, $condition, $from, $params, $expectedSql, $expectedParams); } #[DataProviderExternal(QueryBuilderProvider::class, 'upsert')]