From 30efb75f6a6f8c5b663999099f09ff3a195e69ec Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 9 May 2024 18:42:06 +0700 Subject: [PATCH 1/2] Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method --- CHANGELOG.md | 5 +++-- UPGRADE.md | 4 ++++ src/Query/Query.php | 2 +- src/Query/QueryPartsInterface.php | 5 +++-- tests/Provider/QueryBuilderProvider.php | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) 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..ac44a8e67 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -669,7 +669,7 @@ 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..72b0db0ae 100644 --- a/src/Query/QueryPartsInterface.php +++ b/src/Query/QueryPartsInterface.php @@ -680,10 +680,11 @@ 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)'], ]; } From cec3d6f275c7bf303f35faffb5a7651da4c0ea3a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 9 May 2024 18:47:41 +0700 Subject: [PATCH 2/2] Move parameters to a new line --- src/Query/Query.php | 7 +++++-- src/Query/QueryPartsInterface.php | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Query/Query.php b/src/Query/Query.php index ac44a8e67..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, ExpressionInterface|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 72b0db0ae..784e722c9 100644 --- a/src/Query/QueryPartsInterface.php +++ b/src/Query/QueryPartsInterface.php @@ -684,7 +684,11 @@ public function where(array|string|ExpressionInterface|null $condition, array $p * 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, ExpressionInterface|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.