From 5f8de74a2a871aa682bc25614233b80d0a029071 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 3 Aug 2004 23:03:38 +0000 Subject: [PATCH] added table and colum as parameter to Insert_ID() to correctly retrive the id under postgres and MaxDB --- phpgwapi/inc/adodb/adodb.inc.php | 8 +++++--- phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/phpgwapi/inc/adodb/adodb.inc.php b/phpgwapi/inc/adodb/adodb.inc.php index ccaf97eafc..51796470e3 100644 --- a/phpgwapi/inc/adodb/adodb.inc.php +++ b/phpgwapi/inc/adodb/adodb.inc.php @@ -902,12 +902,14 @@ } /** + * @param $table string name of the table, not needed by all databases (eg. mysql), default '' + * @param $column string name of the column, not needed by all databases (eg. mysql), default '' * @return the last inserted ID. Not all databases support this. */ - function Insert_ID() + function Insert_ID($table='',$column='') { if ($this->_logsql && $this->lastInsID) return $this->lastInsID; - if ($this->hasInsertID) return $this->_insertid(); + if ($this->hasInsertID) return $this->_insertid($table,$column); if ($this->debug) { ADOConnection::outp( '

Insert_ID error

'); adodb_backtrace(); @@ -925,7 +927,7 @@ function PO_Insert_ID($table="", $id="") { if ($this->hasInsertID){ - return $this->Insert_ID(); + return $this->Insert_ID($table,$id); } else { return $this->GetOne("SELECT MAX($id) FROM $table"); } diff --git a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php index 05cf6788f3..24f0b0de99 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php @@ -150,10 +150,12 @@ WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s')) Using a OID as a unique identifier is not generally wise. Unless you are very careful, you might end up with a tuple having a different OID if a database must be reloaded. */ - function _insertid() + function _insertid($table,$column) { if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; - return pg_getlastoid($this->_resultid); + $oid = pg_getlastoid($this->_resultid); + // 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); } // I get this error with PHP before 4.0.6 - jlim