mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
Add sequence name in insertid to be more portable
This commit is contained in:
parent
5ffec92701
commit
e533e82bc9
7 changed files with 18 additions and 18 deletions
|
|
@ -54,13 +54,7 @@ $params=array(
|
|||
);
|
||||
$query->execute($params);
|
||||
|
||||
if($CONFIG_DBTYPE == 'pgsql')
|
||||
{
|
||||
$query = OC_DB::prepare("SELECT currval('*PREFIX*bookmarks_id_seq')");
|
||||
$b_id = $query->execute()->fetchOne();
|
||||
} else {
|
||||
$b_id = OC_DB::insertid();
|
||||
}
|
||||
$b_id = OC_DB::insertid('*PREFIX*bookmarks');
|
||||
|
||||
|
||||
if($b_id !== false) {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class OC_Calendar_Calendar{
|
|||
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
|
||||
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*calendar_calendar');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,7 +131,7 @@ class OC_Calendar_Calendar{
|
|||
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' );
|
||||
$result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components));
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*calendar_calendars');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class OC_Calendar_Object{
|
|||
|
||||
OC_Calendar_Calendar::touchCalendar($id);
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*calendar_objects');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,7 +97,7 @@ class OC_Calendar_Object{
|
|||
|
||||
OC_Calendar_Calendar::touchCalendar($id);
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*calendar_objects');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class OC_Contacts_Addressbook{
|
|||
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
|
||||
$result = $stmt->execute(array($userid,$name,$uri,$description,1));
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*contacts_addressbooks');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,7 +113,7 @@ class OC_Contacts_Addressbook{
|
|||
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
|
||||
$result = $stmt->execute(array($userid,$name,$uri,$description,1));
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*contacts_addressbooks');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class OC_Contacts_VCard{
|
|||
|
||||
OC_Contacts_Addressbook::touch($id);
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*contacts_cards');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,7 +147,7 @@ class OC_Contacts_VCard{
|
|||
|
||||
OC_Contacts_Addressbook::touch($id);
|
||||
|
||||
return OC_DB::insertid();
|
||||
return OC_DB::insertid('*PREFIX*contacts_cards');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class OC_MEDIA_COLLECTION{
|
|||
$query=self::$queries['addsong'];
|
||||
}
|
||||
$query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size));
|
||||
$songId=OC_DB::insertid();
|
||||
$songId=OC_DB::insertid('*PREFIX*media_songs');
|
||||
// self::setLastUpdated();
|
||||
return self::getSongId($name,$artist,$album);
|
||||
}
|
||||
|
|
|
|||
10
lib/db.php
10
lib/db.php
|
|
@ -224,6 +224,7 @@ class OC_DB {
|
|||
|
||||
/**
|
||||
* @brief gets last value of autoincrement
|
||||
* @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
|
||||
* @returns id
|
||||
*
|
||||
* MDB2 lastInsertID()
|
||||
|
|
@ -231,9 +232,14 @@ class OC_DB {
|
|||
* Call this method right after the insert command or other functions may
|
||||
* cause trouble!
|
||||
*/
|
||||
public static function insertid(){
|
||||
public static function insertid($table=null){
|
||||
self::connect();
|
||||
return self::$connection->lastInsertId();
|
||||
if($table !== null){
|
||||
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
|
||||
$suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" );
|
||||
$table = str_replace( '*PREFIX*', $prefix, $table );
|
||||
}
|
||||
return self::$connection->lastInsertId($table.$suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue