Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Command::insertWithReturningPks() #250

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{
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;

Check warning on line 30 in src/Command.php

View check run for this annotation

Codecov / codecov/patch

src/Command.php#L30

Added line #L30 was not covered by tests
}

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
Loading