Skip to content

Commit

Permalink
PR #779 follow-up
Browse files Browse the repository at this point in the history
- Add missing global var declaration
- Coding guidelines
- Comment usage of @ operator
- Update changelog
  • Loading branch information
dregad committed Jun 10, 2023
1 parent b819440 commit 348d263
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions drivers/adodb-postgres8.inc.php
Expand Up @@ -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;
}
Expand Down

1 comment on commit 348d263

@dregad
Copy link
Member Author

@dregad dregad commented on 348d263 Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in commit message - PR reference should have been #979

Please sign in to comment.