Skip to content
Open
Show file tree
Hide file tree
Changes from 53 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
1 change: 1 addition & 0 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function batchInsert(string $table, array $columns, iterable $rows): stat

public function insertBatch(string $table, iterable $rows, array $columns = []): static
{
//mark this as deprecated and remove in future versions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't it be done? i.e. phpdoc/annotation to add.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are in discussion stage. No clear vision of how it will be implemented yet. Thus it is here for a while. After we’ll come to an agreement, I will format the code and docs properly :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't can use several INSERT commands in one SQL statement, so we don't can resolve our task with current insertBatch method.

May be replace CommandCollection class to InsertBatchCommandCollection and return in CommandInterface::insertBatch() method this collection?

$table = $this->getQueryBuilder()->getQuoter()->getRawTableName($table);

$params = [];
Expand Down
111 changes: 111 additions & 0 deletions src/Command/CommandsCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
namespace Yiisoft\Db\Command;

use Iterator;
use Countable;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;

class CommandsCollection implements Iterator, Countable
{
/**
* @var int Current iterator position
Comment thread
samdark marked this conversation as resolved.
Outdated
*/
private int $position = 0;
/**
* @var CommandInterface[] Command of the collection
Comment thread
samdark marked this conversation as resolved.
Outdated
*/
private array $commands = [];

/**
* @param ConnectionInterface $connection Connection to a database
Comment thread
samdark marked this conversation as resolved.
Outdated
*/
public function __construct(private readonly ConnectionInterface $connection)
{
}

function rewind(): void {
$this->position = 0;
}

function current(): CommandInterface {
return $this->commands[$this->position];
}

function key(): int {
return $this->position;
}

function next(): void {
++$this->position;
}

function valid(): bool {
return isset($this->commands[$this->position]);
}

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

/**
* @throws InvalidConfigException
* @throws Exception
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

phpdoc needed.

public function insertBatch(string $table, array $rows, array $columns = []): static
{
$table = $this->connection->getQuoter()->getRawTableName($table);

$columnsCount = count($columns);
if ($columnsCount === 0 && count($rows) > 0) {
$columnsCount = count(array_keys($rows[array_key_first($rows)]));
}

$maxParamsQty = $this->connection->getParamsLimit();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$maxParamsQty = $this->connection->getParamsLimit();
$paramsLimit = $this->connection->getParamsLimit();

$totalInsertedParams = $columnsCount * count($rows);

if (!empty($maxParamsQty) && $totalInsertedParams > $maxParamsQty) {
$chunkSize = (int)floor($maxParamsQty / $columnsCount);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this rounding be a problem in edge cases?

$rowChunks = array_chunk($rows, $chunkSize);
foreach ($rowChunks as $rowChunk) {
$this->commands[] = $this->createInsertBatchCommand($table, $rowChunk, $columns);
}
} else {
$this->commands[] = $this->createInsertBatchCommand($table, $rows, $columns);
}

return $this;
}

/**
* @throws InvalidConfigException
* @throws Exception
*/
private function createInsertBatchCommand(string $table, array $rows, array $columns = []): CommandInterface
{
$command = $this->connection->createCommand();
$params = [];
$sql = $this->connection->getQueryBuilder()->insertBatch($table, $rows, $columns, $params);

$command->setRawSql($sql);
$command->bindValues($params);

return $command;
}

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

return $total;
}
}
15 changes: 15 additions & 0 deletions src/Connection/AbstractConnection.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\CommandsCollection;
use Yiisoft\Db\Query\BatchQueryResult;
use Yiisoft\Db\Query\BatchQueryResultInterface;
use Yiisoft\Db\Query\QueryInterface;
Expand Down Expand Up @@ -117,4 +118,18 @@ protected function rollbackTransactionOnLevel(TransactionInterface $transaction,
}
}
}

public function getParamsLimit(): int
{
//must be overriden in a DBMS package which has a limit
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
//must be overriden in a DBMS package which has a limit
// Must be overriden in a DBMS package which has a limit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should move that to method's phpdoc since that is used-facing documentation.

if ($this->getDriverName() === 'pgsql') {
Copy link
Copy Markdown
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;
}

public function createCommandsCollection(): CommandsCollection
{
return new CommandsCollection($this);
}
}
13 changes: 13 additions & 0 deletions src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Throwable;
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Command\CommandsCollection;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
Expand Down Expand Up @@ -228,4 +229,16 @@ 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 params for a DBMS. Default 0 - means unlimited.
Comment thread
samdark marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Returns maximum number of bound params for a DBMS. Default 0 - means unlimited.
* Returns maximum number of bound params for a DBMS. 0 means unlimited.

Interface don't define default value.

* @return int
*/
public function getParamsLimit(): int;
Copy link
Copy Markdown
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 getParamsLimit(): int;
public function getParametersLimit(): int;


/**
* Creates commands collection used for `insertBatch()`
* @return CommandsCollection
*/
public function createCommandsCollection(): CommandsCollection;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should it be connection responsibility?

}
63 changes: 63 additions & 0 deletions tests/AbstractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\IntegrityException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Profiler\Context\CommandContext;
use Yiisoft\Db\Profiler\ContextInterface;
use Yiisoft\Db\Profiler\ProfilerInterface;
use Yiisoft\Db\Schema\Column\ColumnBuilder;
use Yiisoft\Db\Tests\Support\DbHelper;
use Yiisoft\Db\Tests\Support\TestTrait;

Expand Down Expand Up @@ -48,6 +50,7 @@ public function testAutoQuoting(): void
),
$command->getSql(),
);
$db->close();
}

/**
Expand All @@ -69,6 +72,7 @@ public function testConstruct(): void

$this->assertSame($sql, $command->getSql());
$this->assertSame([':name' => 'John Doe'], $command->getParams());
$db->close();
}

/**
Expand Down Expand Up @@ -106,6 +110,7 @@ public function testGetParams(): void
$this->assertContainsOnlyInstancesOf(ParamInterface::class, $bindedValues);
$this->assertCount(3, $bindedValues);
$this->assertEquals($param, $bindedValues['int']);
$db->close();
}

/**
Expand All @@ -127,6 +132,7 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql
$command = $db->createCommand($sql, $params);

$this->assertSame($expectedRawSql, $command->getRawSql());
$db->close();
}

/**
Expand All @@ -148,6 +154,7 @@ public function testGetSetSql(): void
SQL;
$command->setSql($sql2);
$this->assertSame($sql2, $command->getSql());
$db->close();
}

/**
Expand All @@ -174,6 +181,7 @@ public function testPrepareCancel(): void
$command->cancel();

$this->assertNull($command->getPdoStatement());
$db->close();
}

/**
Expand All @@ -193,6 +201,7 @@ public function testSetRawSql(): void
);

$this->assertSame('SELECT 123', $command->getRawSql());
$db->close();
}

/**
Expand All @@ -211,6 +220,7 @@ public function testSetSql(): void
);

$this->assertSame('SELECT 123', $command->getSql());
$db->close();
}

/**
Expand All @@ -236,6 +246,7 @@ public function testProfiler(?string $sql = null): void
$db->setProfiler($profiler);

$db->createCommand($sql)->execute();
$db->close();
}

/**
Expand Down Expand Up @@ -276,5 +287,57 @@ public function end(string $token, ContextInterface|array $context = []): void
$db->setProfiler($profiler);

$db->createCommand($sql)->execute();
$db->close();
}

public function testBindParamsOverflowIssue(): void
{
$db = $this->getConnection();

if ($db->getDriverName() !== 'pgsql') {
$this->markTestSkipped('Test is intended for use with pgsql database.');
Copy link
Copy Markdown
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely it should be overridden in each DBMS package, returning the corresponding value. But for now for simplicity, as a temporary mock, in order to make the tests run without modifying db-pgsql package I put it here.

}

// $skipVersions = ['11', '12', '16'];
// $dbmsVersion = $db->getServerInfo()->getVersion();
// if (preg_match('/^(\d+)\.(\d+)/ui', $dbmsVersion, $matches)) {
// $dbmsVersion = $matches[1];
// }
// if (in_array($dbmsVersion, $skipVersions)) {
// $this->markTestSkipped('Test is not applicable to pgsql v' . $dbmsVersion);
// }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?


$tempTableName = 'testTempTable';
$db->createCommand()->createTable($tempTableName, [
'id' => ColumnBuilder::primaryKey(),
'first_name' => ColumnBuilder::string()->notNull(),
'last_name' => ColumnBuilder::string()->notNull(),
'birth_date' => ColumnBuilder::date(),
'country' => ColumnBuilder::string(),
'city' => ColumnBuilder::string(),
'address' => ColumnBuilder::string(),
])->execute();

$personData = [
'first_name' => 'IVAN',
'last_name' => 'PUPKIN',
'birth_date' => '1983-08-08',
'country' => 'Kazakhstan',
'city' => 'Almaty',
'address' => '7, Gagarin street, apartment 10',
];

//generate 66 000 params (6 fields x 11000 lines)
$insertData = [];
for ($i = 0; $i < 11000; $i++) {
$insertData[] = $personData;
}

$db->createCommandsCollection()->insertBatch($tempTableName, $insertData)->execute();

$countSql = 'SELECT COUNT(*) FROM ' . $db->getQuoter()->quoteTableName($tempTableName);
$this->assertEquals(11000, $db->createCommand($countSql)->queryScalar());
$db->createCommand()->dropTable($tempTableName)->execute();
$db->close();
}
}
8 changes: 8 additions & 0 deletions tests/AbstractConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testCreateBatchQueryResult(): void
$query = (new Query($db))->from('customer');

$this->assertInstanceOf(BatchQueryResult::class, $db->createBatchQueryResult($query));
$db->close();
}

/**
Expand All @@ -56,13 +57,15 @@ public function testCreateCommand(): void

$this->assertSame($sql, $command->getSql());
$this->assertSame($params, $command->getParams());
$db->close();
}

public function testGetDriverName(): void
{
$db = $this->getConnection();

$this->assertSame($this->getDriverName(), $db->getDriverName());
$db->close();
}

/**
Expand All @@ -84,6 +87,7 @@ function (PdoConnectionInterface $db) {
$db->beginTransaction();
}
);
$db->close();
}

public function testNotProfiler(): void
Expand All @@ -101,6 +105,7 @@ public function testNotProfiler(): void
$db->setProfiler(null);

$this->assertNull(Assert::getInaccessibleProperty($db, 'profiler'));
$db->close();
}

public function testProfiler(): void
Expand Down Expand Up @@ -128,6 +133,7 @@ public function end(string $token, ContextInterface|array $context = []): void
};
$db->setProfiler($profiler);
$db->open();
$db->close();
}

public function testSetTablePrefix(): void
Expand All @@ -137,6 +143,7 @@ public function testSetTablePrefix(): void
$db->setTablePrefix('pre_');

$this->assertSame('pre_', $db->getTablePrefix());
$db->close();
}

public function testSerialized(): void
Expand All @@ -151,6 +158,7 @@ public function testSerialized(): void
$this->assertNull($unserialized->getPDO());
$this->assertEquals(123, $unserialized->createCommand('SELECT 123')->queryScalar());
$this->assertNotNull($connection->getPDO());
$connection->close();
}

private function getProfiler(): ProfilerInterface
Expand Down
Loading