Add sequence name in insertid to be more portable

remotes/origin/stable
Brice Maron 14 years ago
parent 5ffec92701
commit e533e82bc9
  1. 8
      apps/bookmarks/ajax/addBookmark.php
  2. 4
      apps/calendar/lib/calendar.php
  3. 4
      apps/calendar/lib/object.php
  4. 4
      apps/contacts/lib/addressbook.php
  5. 4
      apps/contacts/lib/vcard.php
  6. 2
      apps/media/lib_collection.php
  7. 10
      lib/db.php

@ -54,13 +54,7 @@ $params=array(
); );
$query->execute($params); $query->execute($params);
if($CONFIG_DBTYPE == 'pgsql') $b_id = OC_DB::insertid('*PREFIX*bookmarks');
{
$query = OC_DB::prepare("SELECT currval('*PREFIX*bookmarks_id_seq')");
$b_id = $query->execute()->fetchOne();
} else {
$b_id = OC_DB::insertid();
}
if($b_id !== false) { 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(?,?,?,?,?,?,?,?)' ); $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)); $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(?,?,?,?,?,?,?,?)' ); $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)); $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); 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); 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(?,?,?,?,?)' ); $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,$description,1)); $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(?,?,?,?,?)' ); $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,$description,1)); $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); 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); 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=self::$queries['addsong'];
} }
$query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size)); $query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size));
$songId=OC_DB::insertid(); $songId=OC_DB::insertid('*PREFIX*media_songs');
// self::setLastUpdated(); // self::setLastUpdated();
return self::getSongId($name,$artist,$album); return self::getSongId($name,$artist,$album);
} }

@ -224,6 +224,7 @@ class OC_DB {
/** /**
* @brief gets last value of autoincrement * @brief gets last value of autoincrement
* @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
* @returns id * @returns id
* *
* MDB2 lastInsertID() * MDB2 lastInsertID()
@ -231,9 +232,14 @@ class OC_DB {
* Call this method right after the insert command or other functions may * Call this method right after the insert command or other functions may
* cause trouble! * cause trouble!
*/ */
public static function insertid(){ public static function insertid($table=null){
self::connect(); 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…
Cancel
Save