-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
batchInsert()
with associative arrays
- Loading branch information
Showing
2 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,7 +339,7 @@ public static function batchInsert(): array | |
':qp3' => false, | ||
], | ||
], | ||
'with associative values' => [ | ||
'with associative values with different keys' => [ | ||
'type', | ||
['int_col', 'float_col', 'char_col', 'bool_col'], | ||
'values' => [['int' => '1.0', 'float' => '2', 'char' => 10, 'bool' => 1]], | ||
|
@@ -356,6 +356,90 @@ public static function batchInsert(): array | |
':qp3' => true, | ||
], | ||
], | ||
'with associative values with different keys and columns with keys' => [ | ||
'type', | ||
['a' => 'int_col', 'b' => 'float_col', 'c' => 'char_col', 'd' => 'bool_col'], | ||
'values' => [['int' => '1.0', 'float' => '2', 'char' => 10, 'bool' => 1]], | ||
'expected' => DbHelper::replaceQuotes( | ||
<<<SQL | ||
INSERT INTO [[type]] ([[int_col]], [[float_col]], [[char_col]], [[bool_col]]) VALUES (:qp0, :qp1, :qp2, :qp3) | ||
SQL, | ||
static::$driverName, | ||
), | ||
'expectedParams' => [ | ||
':qp0' => 1, | ||
':qp1' => 2.0, | ||
':qp2' => '10', | ||
':qp3' => true, | ||
], | ||
], | ||
'with associative values with keys of column names' => [ | ||
'type', | ||
['int_col', 'float_col', 'char_col', 'bool_col'], | ||
'values' => [['bool_col' => 1, 'char_col' => 10, 'int_col' => '1.0', 'float_col' => '2']], | ||
'expected' => DbHelper::replaceQuotes( | ||
<<<SQL | ||
INSERT INTO [[type]] ([[int_col]], [[float_col]], [[char_col]], [[bool_col]]) VALUES (:qp2, :qp3, :qp1, :qp0) | ||
SQL, | ||
static::$driverName, | ||
), | ||
'expectedParams' => [ | ||
':qp0' => true, | ||
':qp1' => '10', | ||
':qp2' => 1, | ||
':qp3' => 2.0, | ||
], | ||
], | ||
'with associative values with keys of column keys' => [ | ||
'type', | ||
['int' => 'int_col', 'float' => 'float_col', 'char' => 'char_col', 'bool' => 'bool_col'], | ||
'values' => [['bool' => 1, 'char' => 10, 'int' => '1.0', 'float' => '2']], | ||
'expected' => DbHelper::replaceQuotes( | ||
<<<SQL | ||
INSERT INTO [[type]] ([[int_col]], [[float_col]], [[char_col]], [[bool_col]]) VALUES (:qp2, :qp3, :qp1, :qp0) | ||
SQL, | ||
static::$driverName, | ||
), | ||
'expectedParams' => [ | ||
':qp0' => true, | ||
':qp1' => '10', | ||
':qp2' => 1, | ||
':qp3' => 2.0, | ||
], | ||
], | ||
'with shuffled indexes of values' => [ | ||
'type', | ||
['int_col', 'float_col', 'char_col', 'bool_col'], | ||
'values' => [[3 => 1, 2 => 10, 0 => '1.0', 1 => '2']], | ||
'expected' => DbHelper::replaceQuotes( | ||
<<<SQL | ||
INSERT INTO [[type]] ([[int_col]], [[float_col]], [[char_col]], [[bool_col]]) VALUES (:qp2, :qp3, :qp1, :qp0) | ||
SQL, | ||
static::$driverName, | ||
), | ||
'expectedParams' => [ | ||
':qp0' => true, | ||
':qp1' => '10', | ||
':qp2' => 1, | ||
':qp3' => 2.0, | ||
], | ||
], | ||
'with empty columns' => [ | ||
'customer', | ||
[], | ||
'values' => [['10.0', '[email protected]']], | ||
'expected' => DbHelper::replaceQuotes( | ||
<<<SQL | ||
INSERT INTO [[customer]] (`id`, `email`) VALUES (:qp0, :qp1) | ||
SQL, | ||
static::$driverName, | ||
), | ||
'expectedParams' => [ | ||
':qp0' => 10, | ||
':qp1' => '[email protected]', | ||
], | ||
4, | ||
], | ||
]; | ||
} | ||
|
||
|