Skip to content

Commit

Permalink
Merge branch 'master' into marin-db-pgsql
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored May 16, 2024
2 parents 3b7ceda + 19c98cd commit fbe79ff
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.0.0 under development

- Enh #336: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov)
- Chg #348: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
2 changes: 1 addition & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ private function createColumnSchema(string $name): ColumnSchema
*/
protected function getCacheKey(string $name): array
{
return array_merge([self::class], $this->generateCacheKey(), [$this->getRawTableName($name)]);
return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function testAddDefaultValue(): void
*/
public function testBatchInsert(
string $table,
array $columns,
iterable $values,
array $columns,
string $expected,
array $expectedParams = [],
int $insertedRow = 1
): void {
parent::testBatchInsert($table, $columns, $values, $expected, $expectedParams, $insertedRow);
parent::testBatchInsert($table, $values, $columns, $expected, $expectedParams, $insertedRow);
}

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testBooleanValuesBatchInsert(): void
$db = $this->getConnection(true);

$command = $db->createCommand();
$command->batchInsert('{{bool_values}}', ['bool_col'], [[true], [false]]);
$command->insertBatch('{{bool_values}}', [[true], [false]], ['bool_col']);

$this->assertSame(2, $command->execute());

Expand Down
16 changes: 8 additions & 8 deletions tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public static function batchInsert(): array
{
$batchInsert = parent::batchInsert();

$batchInsert['batchInsert binds params from jsonExpression'] = [
$batchInsert['binds params from jsonExpression'] = [
'{{%type}}',
['json_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
[
[
new JsonExpression(
Expand All @@ -32,6 +31,7 @@ public static function batchInsert(): array
false,
],
],
['json_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
'expected' => <<<SQL
INSERT INTO "type" ("json_col", "int_col", "float_col", "char_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3, :qp4)
SQL,
Expand All @@ -44,30 +44,30 @@ public static function batchInsert(): array
],
];

$batchInsert['batchInsert binds params from arrayExpression'] = [
$batchInsert['binds params from arrayExpression'] = [
'{{%type}}',
['intarray_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
[[new ArrayExpression([1,null,3], 'int'), 1, 1, '', false]],
['intarray_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
'expected' => <<<SQL
INSERT INTO "type" ("intarray_col", "int_col", "float_col", "char_col", "bool_col") VALUES (ARRAY[:qp0, :qp1, :qp2]::int[], :qp3, :qp4, :qp5, :qp6)
SQL,
'expectedParams' => [':qp0' => 1, ':qp1' => null, ':qp2' => 3, ':qp3' => 1, ':qp4' => 1.0, ':qp5' => '', ':qp6' => false],
];

$batchInsert['batchInsert casts string to int according to the table schema'] = [
$batchInsert['casts string to int according to the table schema'] = [
'{{%type}}',
['int_col', 'float_col', 'char_col', 'bool_col'],
[['3', '1.1', '', false]],
['int_col', 'float_col', 'char_col', 'bool_col'],
'expected' => <<<SQL
INSERT INTO "type" ("int_col", "float_col", "char_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3)
SQL,
'expectedParams' => [':qp0' => 3, ':qp1' => 1.1, ':qp2' => '', ':qp3' => false],
];

$batchInsert['batchInsert binds params from jsonbExpression'] = [
$batchInsert['binds params from jsonbExpression'] = [
'{{%type}}',
['jsonb_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
[[new JsonExpression(['a' => true]), 1, 1.1, '', false]],
['jsonb_col', 'int_col', 'float_col', 'char_col', 'bool_col'],
'expected' => <<<SQL
INSERT INTO "type" ("jsonb_col", "int_col", "float_col", "char_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3, :qp4)
SQL,
Expand Down
4 changes: 2 additions & 2 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ public function testAddUnique(string $name, string $table, array|string $columns
*/
public function testBatchInsert(
string $table,
array $columns,
iterable $rows,
array $columns,
string $expected,
array $expectedParams = [],
): void {
parent::testBatchInsert($table, $columns, $rows, $expected, $expectedParams);
parent::testBatchInsert($table, $rows, $columns, $expected, $expectedParams);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testBooleanValues(): void
$db = $this->getConnection(true);

$command = $db->createCommand();
$command->batchInsert('bool_values', ['bool_col'], [[true], [false]])->execute();
$command->insertBatch('bool_values', [[true], [false]], ['bool_col'])->execute();

$this->assertSame(1, (new Query($db))->from('bool_values')->where('bool_col = TRUE')->count());
$this->assertSame(1, (new Query($db))->from('bool_values')->where('bool_col = FALSE')->count());
Expand Down

0 comments on commit fbe79ff

Please sign in to comment.