From 95340a9e671991ecca93deaab60f3923a78b9586 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 23 Nov 2012 00:23:27 +0100 Subject: [PATCH] use lastval() to get the insert id in postgesql --- lib/db.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/db.php b/lib/db.php index de42626563..23fd9acfc5 100644 --- a/lib/db.php +++ b/lib/db.php @@ -355,12 +355,19 @@ class OC_DB { */ public static function insertid($table=null) { self::connect(); - if($table !== null) { - $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); - $suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" ); - $table = str_replace( '*PREFIX*', $prefix, $table ).$suffix; + $type = OC_Config::getValue( "dbtype", "sqlite" ); + if( $type == 'pgsql' ) { + $query = self::prepare('SELECT lastval() AS id'); + $row = $query->execute()->fetchRow(); + return $row['id']; + }else{ + if($table !== null) { + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + $suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" ); + $table = str_replace( '*PREFIX*', $prefix, $table ).$suffix; + } + return self::$connection->lastInsertId($table); } - return self::$connection->lastInsertId($table); } /**