phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.db.inc.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] phpgwapi/inc class.db.inc.php
Date: Sun, 11 Mar 2007 14:39:32 +0000

CVSROOT:        /sources/phpgwapi
Module name:    phpgwapi
Changes by:     Sigurd Nes <sigurdne>   07/03/11 14:39:32

Modified files:
        inc            : class.db.inc.php 

Log message:
        according to 
http://phplens.com/adodb/reference.functions.insert_id.html Insert_ID( ) 
returns the oid for postgres - which is no good.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.db.inc.php?cvsroot=phpgwapi&r1=1.31&r2=1.32

Patches:
Index: class.db.inc.php
===================================================================
RCS file: /sources/phpgwapi/phpgwapi/inc/class.db.inc.php,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- class.db.inc.php    22 Sep 2006 03:00:33 -0000      1.31
+++ class.db.inc.php    11 Mar 2007 14:39:32 -0000      1.32
@@ -9,7 +9,7 @@
        * @link http://www.sanisoft.com/phplib/manual/DB_sql.php
        * @package phpgwapi
        * @subpackage database
-       * @version $Id: class.db.inc.php,v 1.31 2006/09/22 03:00:33 skwashd Exp 
$
+       * @version $Id: class.db.inc.php,v 1.32 2007/03/11 14:39:32 sigurdne 
Exp $
        */
 
        if (empty($GLOBALS['phpgw_info']['server']['db_type']))
@@ -377,8 +377,44 @@
                */
                function get_last_insert_id($table, $field)
                {
+                       
if($GLOBALS['phpgw_info']['server']['db_type']=='postgres')
+                       {
+                               $params = explode('.',$this->adodb->pgVersion);
+
+                               if ($params[0] < 8 || ($params[0] == 8 && 
$params[1] ==0))
+                               {
+                                       $oid = 
pg_getlastoid($this->resultSet->_queryID);
+                                       if ($oid == -1)
+                                       {
+                                               return -1;
+                                       }
+
+                                       $result = 
@pg_Exec($this->adodb->_connectionID, "select $field from $table where 
oid=$oid");
+                               }
+                               else
+                               {
+                                       $result = 
@pg_Exec($this->adodb->_connectionID, "select lastval()");
+                               }
+
+                               if (!$result)
+                               {
+                                       return -1;
+                               }
+
+                               $Record = @pg_fetch_array($result, 0);
+
+                               @pg_freeresult($result);
+                               if (!is_array($Record)) /* OID not found? */
+                               {
+                                       return -1;
+                               }
+                               return $Record[0];
+                       }
+                       else
+                       {
                        return $this->adodb->Insert_ID($table, $field);
                }
+               }
 
                /**
                * Lock a table




reply via email to

[Prev in Thread] Current Thread [Next in Thread]