From a148f0c56bba16efdf88f88f689096d08074f649 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 12 Nov 2023 11:57:49 +0700 Subject: [PATCH 1/3] Fix BC issues --- .github/workflows/bc.yml | 26 ++++++------------- src/Query/Query.php | 2 +- src/Query/QueryPartsInterface.php | 5 ++-- src/QueryBuilder/AbstractDMLQueryBuilder.php | 3 ++- src/QueryBuilder/AbstractQueryBuilder.php | 3 ++- src/QueryBuilder/DMLQueryBuilderInterface.php | 5 ++-- tests/AbstractQueryBuilderTest.php | 3 ++- tests/Db/QueryBuilder/QueryBuilderTest.php | 3 ++- 8 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index 00041a9f4..5970206c9 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -1,25 +1,15 @@ on: pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' - - 'psalm.xml' + paths: + - 'src/**' + - '.github/workflows/bc.yml' + - 'composer.json' push: branches: ['master'] - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' - - 'psalm.xml' + paths: + - 'src/**' + - '.github/workflows/bc.yml' + - 'composer.json' name: backwards compatibility diff --git a/src/Query/Query.php b/src/Query/Query.php index 4ba681e7b..98e69b962 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -662,7 +662,7 @@ 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, 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 8c3ddfd84..f6b9ca974 100644 --- a/src/Query/QueryPartsInterface.php +++ b/src/Query/QueryPartsInterface.php @@ -645,11 +645,10 @@ 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 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 string $alias The query alias in `WITH` construction. * @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, string $alias, bool $recursive = false): static; /** * Specifies the `WITH` query clause for the query. diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 1224e503f..9d07ccfa7 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\QueryBuilder; +use Generator; use JsonException; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\IndexConstraint; @@ -49,7 +50,7 @@ public function __construct( ) { } - public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string + public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string { if (empty($rows)) { return ''; diff --git a/src/QueryBuilder/AbstractQueryBuilder.php b/src/QueryBuilder/AbstractQueryBuilder.php index 53971f27b..f93c13bc9 100644 --- a/src/QueryBuilder/AbstractQueryBuilder.php +++ b/src/QueryBuilder/AbstractQueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\QueryBuilder; +use Generator; use Yiisoft\Db\Command\CommandInterface; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Query\QueryInterface; @@ -108,7 +109,7 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin return $this->ddlBuilder->alterColumn($table, $column, $type); } - public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string + public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string { return $this->dmlBuilder->batchInsert($table, $columns, $rows, $params); } diff --git a/src/QueryBuilder/DMLQueryBuilderInterface.php b/src/QueryBuilder/DMLQueryBuilderInterface.php index fdac752aa..3df1c2c8c 100644 --- a/src/QueryBuilder/DMLQueryBuilderInterface.php +++ b/src/QueryBuilder/DMLQueryBuilderInterface.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\QueryBuilder; +use Generator; use JsonException; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -33,7 +34,7 @@ interface DMLQueryBuilderInterface * * @param string $table The table to insert new rows into. * @param string[] $columns The column names of the table. - * @param iterable $rows The rows to batch-insert into the table. + * @param Generator|iterable $rows The rows to batch-insert into the table. * @param array $params The binding parameters. This parameter exists. * * @throws Exception @@ -48,7 +49,7 @@ interface DMLQueryBuilderInterface * - That the values in each row must match the corresponding column names. * - The method will escape the column names, and quote the values to insert. */ - public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string; + public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string; /** * Creates a `DELETE` SQL statement. diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index d6de07f63..31de64c71 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Tests; use Closure; +use Generator; use JsonException; use PHPUnit\Framework\TestCase; use stdClass; @@ -210,7 +211,7 @@ public function testAlterColumn(): void * * @psalm-param array $columns */ - public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void + public function testBatchInsert(string $table, array $columns, iterable|Generator $rows, string $expected): void { $db = $this->getConnection(); diff --git a/tests/Db/QueryBuilder/QueryBuilderTest.php b/tests/Db/QueryBuilder/QueryBuilderTest.php index 93356917f..79a1e382b 100644 --- a/tests/Db/QueryBuilder/QueryBuilderTest.php +++ b/tests/Db/QueryBuilder/QueryBuilderTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Tests\Db\QueryBuilder; +use Generator; use JsonException; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -47,7 +48,7 @@ public function testAddDefaultValue(): void /** * @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::batchInsert */ - public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void + public function testBatchInsert(string $table, array $columns, iterable|Generator $rows, string $expected): void { $db = $this->getConnection(); From e84c617f87cc95b148f611e0fb1e356d7dad91cf Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 12 Nov 2023 12:01:22 +0700 Subject: [PATCH 2/3] Remove BC test --- tests/Provider/QueryBuilderProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 8e04fc7b5..a70696668 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -1258,7 +1258,6 @@ 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 1795dadb6b196e5df5e9815db705dbcc7f8c5334 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 12 Nov 2023 11:52:34 +0300 Subject: [PATCH 3/3] revert removing `Generator` --- src/QueryBuilder/AbstractDMLQueryBuilder.php | 3 +-- src/QueryBuilder/AbstractQueryBuilder.php | 3 +-- src/QueryBuilder/DMLQueryBuilderInterface.php | 5 ++--- tests/AbstractQueryBuilderTest.php | 3 +-- tests/Db/QueryBuilder/QueryBuilderTest.php | 3 +-- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 9d07ccfa7..1224e503f 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -4,7 +4,6 @@ namespace Yiisoft\Db\QueryBuilder; -use Generator; use JsonException; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\IndexConstraint; @@ -50,7 +49,7 @@ public function __construct( ) { } - public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string + public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string { if (empty($rows)) { return ''; diff --git a/src/QueryBuilder/AbstractQueryBuilder.php b/src/QueryBuilder/AbstractQueryBuilder.php index f93c13bc9..53971f27b 100644 --- a/src/QueryBuilder/AbstractQueryBuilder.php +++ b/src/QueryBuilder/AbstractQueryBuilder.php @@ -4,7 +4,6 @@ namespace Yiisoft\Db\QueryBuilder; -use Generator; use Yiisoft\Db\Command\CommandInterface; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Query\QueryInterface; @@ -109,7 +108,7 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin return $this->ddlBuilder->alterColumn($table, $column, $type); } - public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string + public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string { return $this->dmlBuilder->batchInsert($table, $columns, $rows, $params); } diff --git a/src/QueryBuilder/DMLQueryBuilderInterface.php b/src/QueryBuilder/DMLQueryBuilderInterface.php index 3df1c2c8c..fdac752aa 100644 --- a/src/QueryBuilder/DMLQueryBuilderInterface.php +++ b/src/QueryBuilder/DMLQueryBuilderInterface.php @@ -4,7 +4,6 @@ namespace Yiisoft\Db\QueryBuilder; -use Generator; use JsonException; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -34,7 +33,7 @@ interface DMLQueryBuilderInterface * * @param string $table The table to insert new rows into. * @param string[] $columns The column names of the table. - * @param Generator|iterable $rows The rows to batch-insert into the table. + * @param iterable $rows The rows to batch-insert into the table. * @param array $params The binding parameters. This parameter exists. * * @throws Exception @@ -49,7 +48,7 @@ interface DMLQueryBuilderInterface * - That the values in each row must match the corresponding column names. * - The method will escape the column names, and quote the values to insert. */ - public function batchInsert(string $table, array $columns, iterable|Generator $rows, array &$params = []): string; + public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string; /** * Creates a `DELETE` SQL statement. diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index 31de64c71..d6de07f63 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Db\Tests; use Closure; -use Generator; use JsonException; use PHPUnit\Framework\TestCase; use stdClass; @@ -211,7 +210,7 @@ public function testAlterColumn(): void * * @psalm-param array $columns */ - public function testBatchInsert(string $table, array $columns, iterable|Generator $rows, string $expected): void + public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void { $db = $this->getConnection(); diff --git a/tests/Db/QueryBuilder/QueryBuilderTest.php b/tests/Db/QueryBuilder/QueryBuilderTest.php index 79a1e382b..93356917f 100644 --- a/tests/Db/QueryBuilder/QueryBuilderTest.php +++ b/tests/Db/QueryBuilder/QueryBuilderTest.php @@ -4,7 +4,6 @@ namespace Yiisoft\Db\Tests\Db\QueryBuilder; -use Generator; use JsonException; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -48,7 +47,7 @@ public function testAddDefaultValue(): void /** * @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::batchInsert */ - public function testBatchInsert(string $table, array $columns, iterable|Generator $rows, string $expected): void + public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void { $db = $this->getConnection();