Skip to content

Commit

Permalink
[fix] Oracle lastInsertId
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Oct 30, 2020
1 parent dc81255 commit dbd22ee
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ public function getFieldSqlExpression(Field $field, Expression $expression)

public function lastInsertId(Model $model): string
{
// TODO: Oracle does not support lastInsertId(), only for testing
// as this does not support concurrent inserts
if ($this->connection instanceof \atk4\dsql\Oracle\Connection) {
if ($model->id_field === false) {
return ''; // TODO code should never call lastInsertId() if id field is not defined
}

$query = $this->connection->dsql()->table($model->table);
$query->field($query->expr('max({id_col})', ['id_col' => $model->id_field]), 'max_id');

return $query->getOne();
}

return $this->connection->lastInsertId($this->getIdSequenceName($model));
}

Expand Down

0 comments on commit dbd22ee

Please sign in to comment.