Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jan 4, 2024
1 parent 25bb9a8 commit c0aabf3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public function batchInsert(string $table, array $columns, iterable $rows, array
$columns,
);

$tableAndColumns .= ' (' . implode(', ', $quotedColumnNames) . ') VALUES ';
$tableAndColumns .= ' (' . implode(', ', $quotedColumnNames) . ')';
}

return 'INSERT ALL ' . $tableAndColumns . implode($tableAndColumns, $values) . ' SELECT 1 FROM SYS.DUAL';
$tableAndColumns .= ' VALUES ';

return 'INSERT ALL' . $tableAndColumns . implode($tableAndColumns, $values) . ' SELECT 1 FROM SYS.DUAL';
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function batchInsert(): array
$batchInsert = parent::batchInsert();

$batchInsert['multirow']['expected'] = <<<SQL
INSERT ALL INTO "type" ("int_col", "float_col", "char_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3) INTO "type" ("int_col", "float_col", "char_col", "bool_col") VALUES (:qp4, :qp5, :qp6, :qp7) SELECT 1 FROM SYS.DUAL
INSERT ALL INTO "type" ("int_col", "float_col", "char_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3) INTO "type" ("int_col", "float_col", "char_col", "bool_col") VALUES (:qp4, :qp5, :qp6, :qp7) SELECT 1 FROM SYS.DUAL
SQL;
$batchInsert['multirow']['expectedParams'][':qp3'] = '1';
$batchInsert['multirow']['expectedParams'][':qp7'] = '0';
Expand Down Expand Up @@ -55,6 +55,18 @@ public static function batchInsert(): array
'with shuffled indexes of values' => [
':qp0' => '1',
],
'empty columns and associative values' => [
':qp3' => '1',
],
'empty columns and objects' => [
':qp3' => '1',
],
'empty columns and Traversable' => [
':qp3' => '1',
],
'empty columns and indexed values' => [
':qp3' => '1',
],
];

foreach ($replaceParams as $key => $expectedParams) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public static function batchInsert(): array
DbHelper::changeSqlForOracleBatchInsert($batchInsert['bool-false, bool2-null']['expected']);

$batchInsert['wrong']['expected'] = <<<SQL
INSERT ALL INTO {{%type}} ("float_col", "time") VALUES (:qp0, now()) INTO {{%type}} ("float_col", "time") VALUES (:qp1, now()) SELECT 1 FROM SYS.DUAL
INSERT ALL INTO {{%type}} ("float_col", "time") VALUES (:qp0, now()) INTO {{%type}} ("float_col", "time") VALUES (:qp1, now()) SELECT 1 FROM SYS.DUAL
SQL;

DbHelper::changeSqlForOracleBatchInsert($batchInsert['bool-false, time-now()']['expected']);
DbHelper::changeSqlForOracleBatchInsert($batchInsert['column table names are not checked']['expected']);
DbHelper::changeSqlForOracleBatchInsert($batchInsert['empty columns and non-exists table']['expected']);

$batchInsert['bool-false, bool2-null']['expectedParams'][':qp0'] = '0';
$batchInsert['bool-false, time-now()']['expectedParams'][':qp0'] = '0';
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/Fixture/oci.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ CREATE TABLE "type" (
"int_col" integer NOT NULL,
"float_col" double precision NOT NULL,
"char_col" char(100) NOT NULL,
"blob_col" blob DEFAULT NULL,
"bool_col" char NOT NULL check ("bool_col" in (0,1)),
"int_col2" integer DEFAULT 1,
"tinyint_col" number(3) DEFAULT 1,
"smallint_col" smallint DEFAULT 1,
"char_col2" varchar2(100) DEFAULT 'some''thing',
"char_col3" varchar2(4000),
"nvarchar_col" nvarchar2(100) DEFAULT '',
"float_col2" double precision DEFAULT 1.23,
"blob_col" blob DEFAULT NULL,
"numeric_col" decimal(5,2) DEFAULT 33.22,
"timestamp_col" timestamp DEFAULT to_timestamp('2002-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') NOT NULL,
"time_col" interval day (0) to second(0) DEFAULT INTERVAL '0 10:33:21' DAY(0) TO SECOND(0),
"interval_day_col" interval day (1) to second(0) DEFAULT INTERVAL '2 04:56:12' DAY(1) TO SECOND(0),
"bool_col" char NOT NULL check ("bool_col" in (0,1)),
"bool_col2" char DEFAULT 1 check("bool_col2" in (0,1)),
"ts_default" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
"bit_col" number(3) DEFAULT 130 NOT NULL
Expand Down

0 comments on commit c0aabf3

Please sign in to comment.