Merge pull request #556 from owncloud/postgres_insert_id
use lastval() to get the insert id in postgesql
This commit is contained in:
commit
f81321af3d
17
lib/db.php
17
lib/db.php
|
@ -353,12 +353,19 @@ class OC_DB {
|
||||||
*/
|
*/
|
||||||
public static function insertid($table=null) {
|
public static function insertid($table=null) {
|
||||||
self::connect();
|
self::connect();
|
||||||
if($table !== null) {
|
$type = OC_Config::getValue( "dbtype", "sqlite" );
|
||||||
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
|
if( $type == 'pgsql' ) {
|
||||||
$suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" );
|
$query = self::prepare('SELECT lastval() AS id');
|
||||||
$table = str_replace( '*PREFIX*', $prefix, $table ).$suffix;
|
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue