diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2012-11-24 22:55:33 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2012-11-24 22:55:33 -0800 |
commit | f81321af3d82bbf9a78f44f4f5bfe60c24f87a04 (patch) | |
tree | c2f8dbac8232ec80faf19c1ff9baa68041f4dc22 | |
parent | 1857d5f9141332e0b15f151810522afa78ca0186 (diff) | |
parent | 95340a9e671991ecca93deaab60f3923a78b9586 (diff) | |
download | nextcloud-server-f81321af3d82bbf9a78f44f4f5bfe60c24f87a04.tar.gz nextcloud-server-f81321af3d82bbf9a78f44f4f5bfe60c24f87a04.zip |
Merge pull request #556 from owncloud/postgres_insert_id
use lastval() to get the insert id in postgesql
-rw-r--r-- | lib/db.php | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/db.php b/lib/db.php index f79768a6640..e63a7a20c81 100644 --- a/lib/db.php +++ b/lib/db.php @@ -353,12 +353,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); } /** |