From 7562227db4b80fb4246f0a460a5cc3cb86f22f71 Mon Sep 17 00:00:00 2001 From: lsces Date: Sun, 22 Feb 2026 10:58:44 +0000 Subject: Modify insert to retrun the generated value to replace pdo::lastInsertId(). This still needs a little improvement to perhaps identify the autoincrement field better. It also needs upstream code to avoid the pdo error. --- src/FirebirdConnection.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/FirebirdConnection.php b/src/FirebirdConnection.php index 7186d00..50080b4 100755 --- a/src/FirebirdConnection.php +++ b/src/FirebirdConnection.php @@ -12,6 +12,14 @@ use Xgrz\Firebird\Schema\Grammars\FirebirdGrammar as FirebirdSchemaGrammar; class FirebirdConnection extends DatabaseConnection { + /** + * The last inserted ID generated by the server. + * RETURNED by the insert statement + * + * @var string|int|null + */ + protected $lastInsertId; + /** * Get the default query grammar instance. * @@ -68,6 +76,41 @@ class FirebirdConnection extends DatabaseConnection ); } + /** + * Run an insert statement against the database. + * + * @param string $query + * @param array $bindings + * @param string|null $sequence + * @return bool + */ + public function insert($query, $bindings = [], $sequence = null) + { + return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) { + if ($this->pretending()) { + return true; + } + + $statement = $this->getPdo()->prepare($query); + + $this->bindValues($statement, $this->prepareBindings($bindings)); + + $this->recordsHaveBeenModified(); + + $result = $statement->execute(); + + // Fetch the RETURNING clause result to get the actual ID used + if ($result) { + $row = $statement->fetch(\PDO::FETCH_ASSOC); + if ($row) { + // Get the first (and typically only) returned value + $this->lastInsertId = reset($row); + } + } + + return $result; + }); + } /** * Execute a stored procedure. * -- cgit v1.3