From cd289175c7a1a8950a8ec76ee26da75b498d390a Mon Sep 17 00:00:00 2001 From: lsces Date: Sun, 22 Feb 2026 11:04:29 +0000 Subject: Add returning to the insert function --- src/Query/Grammars/FirebirdGrammar.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Query/Grammars/FirebirdGrammar.php b/src/Query/Grammars/FirebirdGrammar.php index 2ee0d26..8b9edd3 100755 --- a/src/Query/Grammars/FirebirdGrammar.php +++ b/src/Query/Grammars/FirebirdGrammar.php @@ -4,6 +4,7 @@ namespace Xgrz\Firebird\Query\Grammars; use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\Grammars\Grammar; +use Illuminate\Support\Collection; use Illuminate\Support\Str; class FirebirdGrammar extends Grammar @@ -112,6 +113,37 @@ class FirebirdGrammar extends Grammar return 'RAND()'; } + /** + * Compile an insert statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileInsert(Builder $query, array $values) + { + $table = $this->wrapTable($query->from); + + if (empty($values)) { + return "insert into {$table} default values"; + } + + if (! is_array(array_first($values))) { + $values = [$values]; + } + + $columns = $this->columnize(array_keys(array_first($values))); + + // We need to build a list of parameter place-holders of values that are bound + // to the query. Each insert should have the exact same number of parameter + // bindings so we will loop through the record and parameterize them all. + $parameters = (new Collection($values)) + ->map(fn ($record) => '('.$this->parameterize($record).')') + ->implode(', '); + + return "insert into $table ($columns) values $parameters returning *"; + } + /** * Wrap a union subquery in parentheses. * -- cgit v1.3