diff options
| author | lsces <lester@lsces.co.uk> | 2026-02-22 11:04:29 +0000 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2026-02-22 11:04:29 +0000 |
| commit | cd289175c7a1a8950a8ec76ee26da75b498d390a (patch) | |
| tree | 0ea38c1a7a61f3f1f450359b3860238cfc6c9d67 | |
| parent | ec61412bbdb5aa854638422d1e6a715276e68add (diff) | |
| download | illuminate-firebird-cd289175c7a1a8950a8ec76ee26da75b498d390a.tar.gz illuminate-firebird-cd289175c7a1a8950a8ec76ee26da75b498d390a.tar.bz2 illuminate-firebird-cd289175c7a1a8950a8ec76ee26da75b498d390a.zip | |
Add returning to the insert function
| -rwxr-xr-x | src/Query/Grammars/FirebirdGrammar.php | 32 |
1 files changed, 32 insertions, 0 deletions
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. * |
