diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4f7ba0d..9548beb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,9 +18,10 @@ - Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov) - Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov) - Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov) -- Chg #840: Remove `Quoter::unquoteParts()` method (@Tigrov) -- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method +- Enh #840: Remove `Quoter::unquoteParts()` method (@Tigrov) +- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method and `AbstractPdoCommand::internalExecute()` method (@Tigrov) +- Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 571d45eb5..af5713827 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -76,3 +76,7 @@ $db->createCommand()->insertBatch('user', $values)->execute(); ### Remove deprecated constants - `SchemaInterface::TYPE_JSONB` + +### Other changes + +- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method diff --git a/src/Query/Query.php b/src/Query/Query.php index 1a2857811..60d635159 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -669,8 +669,11 @@ public function where(array|string|ExpressionInterface|null $condition, array $p return $this; } - public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static - { + public function withQuery( + QueryInterface|string $query, + ExpressionInterface|string $alias, + bool $recursive = false + ): static { $this->withQueries[] = ['query' => $query, 'alias' => $alias, 'recursive' => $recursive]; return $this; } diff --git a/src/Query/QueryPartsInterface.php b/src/Query/QueryPartsInterface.php index fbef76cef..784e722c9 100644 --- a/src/Query/QueryPartsInterface.php +++ b/src/Query/QueryPartsInterface.php @@ -680,10 +680,15 @@ public function where(array|string|ExpressionInterface|null $condition, array $p * Prepends an SQL statement using `WITH` syntax. * * @param QueryInterface|string $query The SQL statement to append using `UNION`. - * @param string $alias The query alias in `WITH` construction. + * @param ExpressionInterface|string $alias The query alias in `WITH` construction. + * To specify the alias in plain SQL, you may pass an instance of {@see ExpressionInterface}. * @param bool $recursive Its `true` if using `WITH RECURSIVE` and `false` if using `WITH`. */ - public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static; + public function withQuery( + QueryInterface|string $query, + ExpressionInterface|string $alias, + bool $recursive = false + ): static; /** * Specifies the `WITH` query clause for the query. diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 564493def..9c350bd9a 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -1527,6 +1527,7 @@ public static function cteAliases(): array 'with one column' => ['a(b)', '[[a]]([[b]])'], 'with columns' => ['a(b,c,d)', '[[a]]([[b]], [[c]], [[d]])'], 'with extra space' => ['a(b,c,d) ', 'a(b,c,d) '], + 'expression' => [new Expression('a(b,c,d)'), 'a(b,c,d)'], ]; }