From 38057ff4bf49b497804263f82246b2b9e377838f Mon Sep 17 00:00:00 2001 From: Nathan Gibbs Date: Sun, 11 Jun 2023 14:52:54 +0000 Subject: [PATCH] Fixes #978 for ADOdb 5.21x --- drivers/adodb-postgres8.inc.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/adodb-postgres8.inc.php b/drivers/adodb-postgres8.inc.php index 37c2aae14..f0a40f451 100644 --- a/drivers/adodb-postgres8.inc.php +++ b/drivers/adodb-postgres8.inc.php @@ -47,9 +47,21 @@ class ADODB_postgres8 extends ADODB_postgres7 */ protected function _insertID($table = '', $column = '') { - return empty($table) || empty($column) - ? $this->GetOne("SELECT lastval()") - : $this->GetOne("SELECT currval(pg_get_serial_sequence('$table', '$column'))"); + global $ADODB_GETONE_EOF; + + $sql = empty($table) || empty($column) + ? 'SELECT lastval()' + : "SELECT currval(pg_get_serial_sequence('$table', '$column'))"; + + // Squelch "ERROR: lastval is not yet defined in this session" (see #978) + $result = @$this->GetOne($sql); + if ($result === false || $result == $ADODB_GETONE_EOF) { + if ($this->debug) { + ADOConnection::outp(__FUNCTION__ . "() failed : " . $this->errorMsg()); + } + return false; + } + return $result; } }