Skip to content

Commit 94498ba

Browse files
authored
Simplify insertEx (#178)
1 parent f23765c commit 94498ba

2 files changed

Lines changed: 6 additions & 31 deletions

File tree

src/CommandPDO.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,6 @@
1313

1414
final class CommandPDO extends AbstractCommandPDO
1515
{
16-
/**
17-
* @inheritDoc
18-
*/
19-
public function insertEx(string $table, array $columns): bool|array
20-
{
21-
$params = [];
22-
$sql = $this->db->getQueryBuilder()->insertEx($table, $columns, $params);
23-
$this->setSql($sql)->bindValues($params);
24-
25-
if (!$this->execute()) {
26-
return false;
27-
}
28-
29-
$tableSchema = $this->db->getSchema()->getTableSchema($table);
30-
$tablePrimaryKeys = $tableSchema?->getPrimaryKey() ?? [];
31-
32-
$result = [];
33-
foreach ($tablePrimaryKeys as $name) {
34-
if ($tableSchema?->getColumn($name)?->isAutoIncrement()) {
35-
$result[$name] = $this->db->getLastInsertID((string) $tableSchema?->getSequenceName());
36-
continue;
37-
}
38-
39-
/** @psalm-var mixed */
40-
$result[$name] = $columns[$name] ?? $tableSchema?->getColumn($name)?->getDefaultValue();
41-
}
42-
43-
return $result;
44-
}
45-
4616
public function queryBuilder(): QueryBuilderInterface
4717
{
4818
return $this->db->getQueryBuilder();

tests/QueryBuilderTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,12 @@ public function testInsertEx(
399399
string $expectedSQL,
400400
array $expectedParams
401401
): void {
402-
parent::testInsertEx($table, $columns, $params, $expectedSQL, $expectedParams);
402+
$this->expectException(NotSupportedException::class);
403+
$this->expectExceptionMessage('Yiisoft\Db\QueryBuilder\DMLQueryBuilder::insertEx() is not supported by this DBMS.');
404+
405+
$db = $this->getConnection(true);
406+
$qb = $db->getQueryBuilder();
407+
$qb->insertEx($table, $columns, $params);
403408
}
404409

405410
/**

0 commit comments

Comments
 (0)