summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2023-06-11 01:50:11 +0200
committerDamien Regad <dregad@mantisbt.org>2023-06-11 01:50:11 +0200
commit348d2631724b3e72e45b9785fa679ca064098e93 (patch)
tree7d342cf52806e69154cfff309e262d969755a253
parentb819440c251b1d916b663a91e32ac9eae2eaf57f (diff)
downloadadodb-348d2631724b3e72e45b9785fa679ca064098e93.tar.gz
adodb-348d2631724b3e72e45b9785fa679ca064098e93.tar.bz2
adodb-348d2631724b3e72e45b9785fa679ca064098e93.zip
PR #779 follow-up
- Add missing global var declaration - Coding guidelines - Comment usage of @ operator - Update changelog
-rw-r--r--docs/changelog.md2
-rw-r--r--drivers/adodb-postgres8.inc.php18
2 files changed, 14 insertions, 6 deletions
diff --git a/docs/changelog.md b/docs/changelog.md
index 597260b1..c15e481d 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -41,6 +41,8 @@ Older changelogs:
[#967](https://github.com/ADOdb/ADOdb/issues/967)
- pgsql: Fix PHP 8.1 deprecated warning
[#956](https://github.com/ADOdb/ADOdb/issues/956)
+- pgsql: avoid Insert_ID() failing when lastval() is not set
+ [#978](https://github.com/ADOdb/ADOdb/issues/978)
## [5.22.5] - 2023-04-03
diff --git a/drivers/adodb-postgres8.inc.php b/drivers/adodb-postgres8.inc.php
index 911ec178..58df47c6 100644
--- a/drivers/adodb-postgres8.inc.php
+++ b/drivers/adodb-postgres8.inc.php
@@ -45,13 +45,19 @@ class ADODB_postgres8 extends ADODB_postgres7
* @return int last inserted ID for given table/column, or the most recently
* returned one if $table or $column are empty
*/
- protected function _insertID( $table = '', $column = '' ){
- $sql = 'SELECT ';
- $sql .= empty($table) || empty($column) ? 'lastval()' : "currval(pg_get_serial_sequence('$table', '$column'))";
+ protected function _insertID( $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());
+ if ($result === false || $result == $ADODB_GETONE_EOF) {
+ if ($this->debug) {
+ ADOConnection::outp(__FUNCTION__ . "() failed : " . $this->errorMsg());
}
return false;
}