Skip to content

Fix #888 issue #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 152 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
804c637
Fix issue #762
evil1 Dec 25, 2024
13f23c7
Fix issue #762
evil1 Dec 25, 2024
fd253ea
Fix issue #762
evil1 Dec 25, 2024
966e214
Fix issue #762
evil1 Dec 25, 2024
7a5d737
Update src/Schema/SchemaInterface.php
evil1 Dec 26, 2024
1e281ab
Fix issue #762
evil1 Dec 26, 2024
2514ee0
Changelog update
evil1 Jan 4, 2025
c43d104
Removed redundant PHPDoc block
evil1 Jan 5, 2025
64f818c
Returned PHPDoc block to fix automated tests
evil1 Jan 5, 2025
219c7c6
Update tests/Common/CommonSchemaTest.php
Tigrov Jan 5, 2025
23c9235
Removed redundant PHPDoc block
evil1 Jan 5, 2025
905efb0
Merge remote-tracking branch 'origin/master'
evil1 Jan 5, 2025
028baf8
Fixed hasSchema tests
evil1 Jan 5, 2025
e42d4b6
Fixed hasSchema tests & formatting
evil1 Jan 5, 2025
c19ffde
Fixed hasSchema tests & formatting
evil1 Jan 5, 2025
3203b8b
Fixed hasSchema tests & formatting
evil1 Jan 5, 2025
4d6074f
Fixed hasView and hasTable tests tests
evil1 Jan 5, 2025
0beb7a2
Removed accidental file from the commit
evil1 Jan 7, 2025
ad6f4ad
Merge branch 'master' into master
vjik Mar 25, 2025
c770c9b
Replace customer table with category for testing
evil1 Mar 26, 2025
923fd32
Merge remote-tracking branch 'origin/master'
evil1 Mar 26, 2025
43ef361
Replace table name for testing
evil1 Mar 26, 2025
87ba24c
Replace table name for testing
evil1 Mar 26, 2025
1828d68
Replace dropTable() method call with raw SQL query
evil1 Mar 28, 2025
b34c105
Update UPGRADE docs
evil1 Mar 28, 2025
d126e1f
Test for 65535 records limit
evil1 Mar 28, 2025
020c3f3
Test for 65535 records limit
evil1 Mar 28, 2025
f723c72
Test for 65535 records limit
evil1 Mar 28, 2025
4b5d89c
Test for 65535 records limit
evil1 Mar 28, 2025
3973033
Test for 65535 records limit
evil1 Mar 28, 2025
449714d
Test for 65535 records limit
evil1 Mar 28, 2025
e267224
Test for 65535 records limit
evil1 Mar 28, 2025
4b3bc67
Test for 65535 records limit
evil1 Mar 28, 2025
eabb05b
Test for 65535 records limit
evil1 Mar 28, 2025
d8979b1
Close DB connection after test
evil1 Mar 28, 2025
c1bf4f8
Close all DB connection after tests
evil1 Mar 28, 2025
a808c98
Close all DB connection after tests
evil1 Mar 28, 2025
27a23e3
Merge branch 'yiisoft:master' into master
evil1 Mar 28, 2025
a8263e9
Merge branch 'yiisoft:master' into batchInsert
evil1 Mar 28, 2025
d9c59e7
Close all DB connection after tests
evil1 Mar 28, 2025
1503a92
Close all DB connection after tests
evil1 Mar 28, 2025
f44b968
Close all DB connection after tests
evil1 Mar 28, 2025
2dd73a0
Close all DB connection after tests
evil1 Mar 28, 2025
ead1311
Close all DB connection after tests
evil1 Mar 28, 2025
fc6d788
Close all DB connection after tests
evil1 Mar 28, 2025
915c3e0
Close all DB connection after tests
evil1 Mar 28, 2025
e6be689
Close all DB connection after tests
evil1 Mar 28, 2025
ecce7a3
Close all DB connection after tests
evil1 Mar 28, 2025
0c933d4
Close all DB connection after tests
evil1 Mar 28, 2025
ff0e7af
Close all DB connection after tests
evil1 Mar 28, 2025
0064ea4
Close all DB connection after tests
evil1 Mar 28, 2025
133ea38
Close all DB connection after tests
evil1 Mar 28, 2025
082d055
New object for handling multiple commands
evil1 Mar 29, 2025
f4fff70
New object for handling multiple commands
evil1 Mar 29, 2025
4be947f
Update src/Command/CommandsCollection.php
samdark Mar 31, 2025
3d1b474
Update src/Command/CommandsCollection.php
samdark Mar 31, 2025
221543c
Update src/Command/CommandsCollection.php
samdark Mar 31, 2025
7a54d2f
Update src/Connection/ConnectionInterface.php
samdark Mar 31, 2025
22a1906
Move BatchCommand into CommandInterface
evil1 Apr 1, 2025
7115b06
Merge remote-tracking branch 'origin/batchInsert' into batchInsert
evil1 Apr 1, 2025
951c0f7
Move BatchCommand into CommandInterface
evil1 Apr 1, 2025
87ff7b5
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
48df33f
Apply Rector changes (CI)
evil1 Apr 1, 2025
281f2ae
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
bbe1e43
Merge remote-tracking branch 'origin/batchInsert' into batchInsert
evil1 Apr 1, 2025
703ca43
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
f58ce6f
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
a684cc0
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
4139d81
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
9e3507c
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
5d43b04
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
32d8d7e
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
6100168
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
b48e8e2
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
31a09b4
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
a3202bd
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
4eed6d3
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
b1ec11e
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
fdf3066
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
05e72b0
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
aa8ef79
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
0fcdee0
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
0d57a8c
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
5a576f6
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
1dc6825
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
05ad7a7
Adjusted batch insert test according to a new design
evil1 Apr 1, 2025
08e1b72
Fix CI styling
evil1 Apr 1, 2025
2736a60
Fix CI styling
evil1 Apr 1, 2025
1bb5b2e
Fix CI styling
evil1 Apr 1, 2025
7189f0c
Fix CI styling
evil1 Apr 1, 2025
fdc5f2e
Fix CI styling
evil1 Apr 1, 2025
bb6a9ba
Test for new class added
evil1 Apr 1, 2025
041c42b
Test for new class added
evil1 Apr 1, 2025
1e0cd08
Test for new class added
evil1 Apr 1, 2025
a1237d4
Test for new class added
evil1 Apr 1, 2025
4fb566e
Test for new class added
evil1 Apr 1, 2025
ec45d61
Test for new class added
evil1 Apr 1, 2025
6f37004
Test for new class added
evil1 Apr 1, 2025
f95ba39
Test for new class added
evil1 Apr 1, 2025
c1bd00a
Merge branch 'master' into batchInsert
evil1 Apr 2, 2025
3d63c51
Refactor batchInsert method
evil1 Apr 3, 2025
38120ed
Apply Rector changes (CI)
evil1 Apr 3, 2025
ac2034d
Refactor batchInsert method
evil1 Apr 3, 2025
e6e25f1
Merge remote-tracking branch 'origin/batchInsert' into batchInsert
evil1 Apr 3, 2025
a12d48d
Refactor batchInsert method
evil1 Apr 3, 2025
42d4b5e
Refactor batchInsert method
evil1 Apr 3, 2025
9e2d1f4
Refactor batchInsert method
evil1 Apr 3, 2025
f2a9044
Refactor batchInsert method
evil1 Apr 3, 2025
6d328ea
Refactor batchInsert method
evil1 Apr 3, 2025
fe97ad0
Refactor batchInsert method
evil1 Apr 3, 2025
8685919
Refactor batchInsert method
evil1 Apr 3, 2025
e49b146
Refactor batchInsert method
evil1 Apr 3, 2025
ae82c6c
Refactor batchInsert method
evil1 Apr 3, 2025
efb1b87
Refactor batchInsert method
evil1 Apr 3, 2025
f833773
Refactor batchInsert method
evil1 Apr 3, 2025
2494cb8
Refactor batchInsert method
evil1 Apr 3, 2025
547ce2d
Apply Rector changes (CI)
evil1 Apr 3, 2025
309cf28
Refactor batchInsert method
evil1 Apr 3, 2025
acd8224
Merge remote-tracking branch 'origin/batchInsert' into batchInsert
evil1 Apr 3, 2025
390bd69
Refactor batchInsert method
evil1 Apr 3, 2025
1828754
Refactor batchInsert method
evil1 Apr 4, 2025
59e92f3
Refactor batchInsert method
evil1 Apr 4, 2025
5bc377e
Refactor batchInsert method
evil1 Apr 4, 2025
937a491
Refactor batchInsert method
evil1 Apr 4, 2025
8d233d7
Refactor batchInsert method
evil1 Apr 4, 2025
5bacb06
Refactor batchInsert method
evil1 Apr 4, 2025
597661f
Refactor batchInsert method
evil1 Apr 4, 2025
ab396bf
Refactor batchInsert method
evil1 Apr 4, 2025
fdaffb7
Refactor batchInsert method
evil1 Apr 4, 2025
088adda
Refactor batchInsert method
evil1 Apr 4, 2025
44165b8
Refactor batchInsert method
evil1 Apr 4, 2025
6cc0a89
Refactor batchInsert method
evil1 Apr 4, 2025
fc4c5d6
Refactor batchInsert method
evil1 Apr 4, 2025
fc0e269
Refactor batchInsert method
evil1 Apr 4, 2025
2a87ca6
Refactor batchInsert method
evil1 Apr 4, 2025
611ed45
Refactor batchInsert method
evil1 Apr 4, 2025
2df28c2
Merge branch 'master' into batchInsert
Tigrov Apr 5, 2025
1a09db6
Fix psalm typehinting
evil1 Apr 5, 2025
08c39f2
Merge remote-tracking branch 'origin/batchInsert' into batchInsert
evil1 Apr 5, 2025
91ffdf6
Fix psalm typehinting
evil1 Apr 5, 2025
c518a0d
Fix psalm typehinting
evil1 Apr 5, 2025
f11ee5c
Fix psalm typehinting
evil1 Apr 11, 2025
a4dc56a
Merge branch 'master' into batchInsert
evil1 Apr 11, 2025
ec50b75
Fix psalm typehinting
evil1 Apr 11, 2025
ab3f9a3
Merge branch 'master' into batchInsert
vjik Apr 16, 2025
78cb71d
Merge branch 'master' into batchInsert
vjik Apr 16, 2025
4e855e9
improve
vjik Apr 16, 2025
adaa1fe
improve
vjik Apr 16, 2025
0a3157c
Fix psalm typehinting
evil1 Apr 17, 2025
2b6b25f
Fix psalm typehinting
evil1 Apr 17, 2025
7905ed7
Fix psalm typehinting
evil1 Apr 17, 2025
b41aa4c
Fix psalm typehinting
evil1 Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use Throwable;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Query\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
Expand Down Expand Up @@ -201,22 +202,26 @@
*
* @deprecated Use {@see insertBatch()} instead. It will be removed in version 3.0.0.
*/
public function batchInsert(string $table, array $columns, iterable $rows): static
public function batchInsert(string $table, array $columns, iterable $rows): BatchCommand

Check warning on line 205 in src/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/AbstractCommand.php#L205

Added line #L205 was not covered by tests
{
return $this->insertBatch($table, $rows, $columns);
}

public function insertBatch(string $table, iterable $rows, array $columns = []): static
public function insertBatch(string $table, iterable $rows, array $columns = [], int $rowsAtOnceLimit = 0): BatchCommand
{
$table = $this->getQueryBuilder()->getQuoter()->getRawTableName($table);
$db = $this->getConnection();

$params = [];
$sql = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $params);

$this->setRawSql($sql);
$this->bindValues($params);
$statements = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $rowsAtOnceLimit);
$commands = [];
foreach ($statements as $statement) {
$command = $db->createCommand();
$command->setRawSql($statement->sql);
$command->bindValues($statement->params);

return $this;
$commands[] = $command;
}
return new BatchCommand($commands);
}

abstract public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static;
Expand Down Expand Up @@ -521,6 +526,11 @@
return $this->setSql($sql)->bindValues($params);
}

/**
* @return ConnectionInterface The query builder instance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return ConnectionInterface The query builder instance.
* @return ConnectionInterface The connection instance.

*/
abstract protected function getConnection(): ConnectionInterface;

/**
* @return QueryBuilderInterface The query builder instance.
*/
Expand Down
44 changes: 44 additions & 0 deletions src/Command/BatchCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Command;

use Yiisoft\Db\Exception\Exception;

/**
* Object used as batch commands container
*/
final class BatchCommand
{
/**
* @param CommandInterface[] $commands Query statements for execution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param CommandInterface[] $commands Query statements for execution
* @param CommandInterface[] $commands Query statements for execution.

*/
public function __construct(private readonly array $commands)
{
}

public function count(): int
{
return count($this->commands);
}
Comment on lines +20 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function count(): int
{
return count($this->commands);
}

Looks redundant.


public function getCommands(): array
{
return $this->commands;
}

/**
* @throws \Throwable
* @throws Exception
*/
public function execute(): int
{
$total = 0;
foreach ($this->commands as $command) {
$total += $command->execute();
}

return $total;
}
}
4 changes: 3 additions & 1 deletion src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
* @param string $table The name of the table to insert new rows into.
* @param iterable $rows The rows to be batch inserted into the table.
* @param string[] $columns The column names.
* @param int $rowsAtOnceLimit Limit number of rows inserted at once. Default 0 - means maximum allowed by DBMS. If
* provided value is greater, than supported by DBMS, then DBMS maximum value will be used.
*
* @throws Exception
* @throws InvalidArgumentException
Expand All @@ -201,7 +203,7 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
*
* Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
*/
public function insertBatch(string $table, iterable $rows, array $columns = []): static;
public function insertBatch(string $table, iterable $rows, array $columns = [], int $rowsAtOnceLimit = 0): BatchCommand;

/**
* Binds a parameter to the SQL statement to be executed.
Expand Down
19 changes: 19 additions & 0 deletions src/Command/QueryStatement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Command;

/**
* Represents an SQL statement used for batch commands execution.
*/
class QueryStatement
{
/**
* @param string $sql SQL query.
* @param array $params Parameters for query execution.
*/
public function __construct(public string $sql, public array $params = [])
{
}
}
9 changes: 9 additions & 0 deletions src/Connection/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ protected function rollbackTransactionOnLevel(TransactionInterface $transaction,
}
}
}

public function getParametersLimit(): int
{
// Must be overridden in a DBMS package which has a limit
if ($this->getDriverName() === 'pgsql') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be moved to PostgreSQL package?

return 65535;
}
return 0;
}
}
6 changes: 6 additions & 0 deletions src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,10 @@ public function setTablePrefix(string $value): void;
* @psalm-param Closure(ConnectionInterface):mixed|Closure(ConnectionInterface):void $closure
*/
public function transaction(Closure $closure, ?string $isolationLevel = null): mixed;

/**
* Returns maximum number of bound parameters for a DBMS. Default is 0 which means unlimited.
* @return int
*/
public function getParametersLimit(): int;
}
7 changes: 4 additions & 3 deletions src/Debug/CommandInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use Throwable;
use Yiisoft\Db\Command\BatchCommand;
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Query\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
Expand Down Expand Up @@ -99,11 +100,11 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
}

/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedReturnStatement
*/
public function insertBatch(string $table, iterable $rows, array $columns = []): static
public function insertBatch(string $table, iterable $rows, array $columns = [], int $rowsAtOnceLimit = 0): BatchCommand
{
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
return $this->decorated->{__FUNCTION__}(...func_get_args());
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Debug/ConnectionInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ public function getDriverName(): string
{
return $this->connection->getDriverName();
}

public function getParametersLimit(): int
{
return $this->connection->getParametersLimit();
}
}
6 changes: 6 additions & 0 deletions src/Driver/Pdo/AbstractPdoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Yiisoft\Db\Command\AbstractCommand;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Exception\ConvertException;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidParamException;
Expand Down Expand Up @@ -165,6 +166,11 @@ protected function bindPendingParams(): void
}
}

protected function getConnection(): ConnectionInterface
{
return $this->db;
}

protected function getQueryBuilder(): QueryBuilderInterface
{
return $this->db->getQueryBuilder();
Expand Down
Loading
Loading