diff --git a/CHANGELOG.md b/CHANGELOG.md index 87481a7a..cd9a990c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,7 @@ - New #387: Realize `Schema::loadResultColumn()` method (@Tigrov) - New #393: Use `DateTimeColumn` class for datetime column types (@Tigrov) - Enh #396, #409: Refactor constraints (@Tigrov) -- New #394, #395, #398, #425, #435: Implement `Command::upsertReturning()` method (@Tigrov, @vjik) +- New #394, #395, #398, #425, #435, #437: Implement `Command::upsertReturning()` method (@Tigrov, @vjik) - Enh #394, #395: Refactor `Command::insertWithReturningPks()` method (@Tigrov) - Chg #399: Rename `insertWithReturningPks()` to `insertReturningPks()` in `Command` and `DMLQueryBuilder` classes (@Tigrov) - Enh #403: Refactor `DMLQueryBuilder::upsert()`, allow use `EXCLUDED` table alias to access inserted values (@Tigrov) @@ -53,7 +53,7 @@ - New #420, #427: Implement `ArrayMergeBuilder`, `LongestBuilder` and `ShortestBuilder` classes (@Tigrov) - Enh #423: Refactor `DMLQueryBuilder::upsert()` method (@Tigrov) - Chg #428: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov) -- Enh #442, #433: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin, @Tigrov) +- Enh #432, #433: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin, @Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Command.php b/src/Command.php index 6ba5b45e..9ec1d3d4 100644 --- a/src/Command.php +++ b/src/Command.php @@ -10,7 +10,6 @@ use Yiisoft\Db\Exception\IntegrityException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Query\QueryInterface; -use Yiisoft\Db\Schema\Column\ColumnInterface; use function in_array; use function str_starts_with; @@ -22,14 +21,13 @@ */ final class Command extends AbstractPdoCommand { - public function insertReturningPks(string $table, array|QueryInterface $columns): array|false + public function insertReturningPks(string $table, array|QueryInterface $columns): array { $tableSchema = $this->db->getSchema()->getTableSchema($table); $primaryKeys = $tableSchema?->getPrimaryKey() ?? []; $tableColumns = $tableSchema?->getColumns() ?? []; foreach ($primaryKeys as $name) { - /** @var ColumnInterface $column */ $column = $tableColumns[$name]; if ($column->isAutoIncrement()) { @@ -49,9 +47,7 @@ public function insertReturningPks(string $table, array|QueryInterface $columns) $insertSql = $this->db->getQueryBuilder()->insert($table, $columns, $params); $this->setSql($insertSql)->bindValues($params); - if ($this->execute() === 0) { - return false; - } + $this->execute(); if (empty($primaryKeys)) { return []; @@ -60,7 +56,6 @@ public function insertReturningPks(string $table, array|QueryInterface $columns) $result = []; foreach ($primaryKeys as $name) { - /** @var ColumnInterface $column */ $column = $tableColumns[$name]; if ($column->isAutoIncrement()) { @@ -85,7 +80,7 @@ public function upsertReturning( array|QueryInterface $insertColumns, array|bool $updateColumns = true, array|null $returnColumns = null, - ): array|false { + ): array { $returnColumns ??= $this->db->getTableSchema($table)?->getColumnNames(); if (empty($returnColumns)) { @@ -102,11 +97,11 @@ public function upsertReturning( /** @psalm-var PDOStatement $this->pdoStatement */ $this->pdoStatement->nextRowset(); - /** @psalm-var array|false $result */ + /** @psalm-var array $result */ $result = $this->pdoStatement->fetch(PDO::FETCH_ASSOC); $this->pdoStatement->closeCursor(); - if (!$this->phpTypecasting || $result === false) { + if (!$this->phpTypecasting) { return $result; }