From 1c8ecb3992e1b15314d7804511e7d8d293597127 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 19 Nov 2005 20:13:06 +0000 Subject: [PATCH] enhanced _insertID function to deal with tables without oid's (default from 8.1+) --- .../inc/adodb/drivers/adodb-postgres64.inc.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php index 82c3799762..affc34ebb4 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php @@ -156,6 +156,21 @@ a different OID if a database must be reloaded. */ { if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; $oid = pg_getlastoid($this->_resultid); + + if ($oid === false && $table && $column) // table might not use oid's, default for 8.1+ + { + // try the standard sequence name first, due to table renames etc. this might not be the correct one + if (!($ret = $this->GetOne($sql='SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { + // now we read the sequence name from the database itself, that is a lot slower! + $cols = $this->MetaColumns($table); + $fld = $cols[strtoupper($column)]; + if ($fld->primary_key && $fld->has_default && + preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) { + $ret = $this->GetOne($sql='SELECT currval('.$this->qstr($matches[1]).')'); + } + } + return $ret; + } // to really return the id, we need the table and column-name, else we can only return the oid != id return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid); }