Skip to content

Commit

Permalink
Fix Command::insertWithReturningPks() (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Rogachev <[email protected]>
  • Loading branch information
Tigrov and arogachev authored Dec 21, 2023
1 parent 1ae3f3d commit 0b28ffb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.2.1 under development

- Enh #248: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov)
- Bug #250: Fix `Command::insertWithReturningPks()` method for table without primary keys (@Tigrov)

## 1.2.0 November 12, 2023

Expand Down
15 changes: 11 additions & 4 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ final class Command extends AbstractPdoCommand
{
public function insertWithReturningPks(string $table, array $columns): bool|array
{
$tableSchema = $this->db->getSchema()->getTableSchema($table);
$returnColumns = $tableSchema?->getPrimaryKey() ?? [];

if ($returnColumns === []) {
if ($this->insert($table, $columns)->execute() === 0) {
return false;
}

return [];
}

$params = [];
$sql = $this->getQueryBuilder()->insert($table, $columns, $params);

$tableSchema = $this->db->getSchema()->getTableSchema($table);

$returnColumns = $tableSchema?->getPrimaryKey() ?? [];
$columnSchemas = $tableSchema?->getColumns() ?? [];

$returnParams = [];
$returning = [];

Expand Down

0 comments on commit 0b28ffb

Please sign in to comment.