summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlsces <lester@lsces.co.uk>2026-02-22 10:58:44 +0000
committerlsces <lester@lsces.co.uk>2026-02-22 10:58:44 +0000
commit7562227db4b80fb4246f0a460a5cc3cb86f22f71 (patch)
treee9a9f0859024a882a3f5fca08a0e36e3426d0600
parent7942cce5a37423ba02992cca9cfe7caafbff2aca (diff)
downloadilluminate-firebird-7562227db4b80fb4246f0a460a5cc3cb86f22f71.tar.gz
illuminate-firebird-7562227db4b80fb4246f0a460a5cc3cb86f22f71.tar.bz2
illuminate-firebird-7562227db4b80fb4246f0a460a5cc3cb86f22f71.zip
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.
-rwxr-xr-xsrc/FirebirdConnection.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/FirebirdConnection.php b/src/FirebirdConnection.php
index 7186d00..50080b4 100755
--- a/src/FirebirdConnection.php
+++ b/src/FirebirdConnection.php
@@ -13,6 +13,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.
*
* @return \Illuminate\Database\Query\Grammars\Grammar
@@ -69,6 +77,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.
*
* @param string $procedure