Remove OC_DB::insertid
This commit is contained in:
parent
0a41cfefe3
commit
fddece9552
5 changed files with 5 additions and 20 deletions
|
@ -157,21 +157,6 @@ class OC_DB {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets last value of autoincrement
|
||||
* @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
|
||||
* @return string id
|
||||
* @throws \OC\DatabaseException
|
||||
*
|
||||
* \Doctrine\DBAL\Connection lastInsertId
|
||||
*
|
||||
* Call this method right after the insert command or other functions may
|
||||
* cause trouble!
|
||||
*/
|
||||
public static function insertid($table=null) {
|
||||
return \OC::$server->getDatabaseConnection()->lastInsertId($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* saves database schema to xml file
|
||||
* @param string $file name of file
|
||||
|
|
2
lib/private/files/cache/storage.php
vendored
2
lib/private/files/cache/storage.php
vendored
|
@ -61,7 +61,7 @@ class Storage {
|
|||
$connection = \OC_DB::getConnection();
|
||||
$available = $isAvailable ? 1 : 0;
|
||||
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
|
||||
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
|
||||
$this->numericId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages');
|
||||
} else {
|
||||
if ($row = self::getStorageById($this->storageId)) {
|
||||
$this->numericId = $row['numeric_id'];
|
||||
|
|
|
@ -2191,7 +2191,7 @@ class Share extends Constants {
|
|||
if ($isGroupShare) {
|
||||
$id = self::insertShare($queriesToExecute['groupShare']);
|
||||
// Save this id, any extra rows for this group share will need to reference it
|
||||
$parent = \OC_DB::insertid('*PREFIX*share');
|
||||
$parent = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share');
|
||||
unset($queriesToExecute['groupShare']);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,11 +111,11 @@ class Test_DB extends \Test\TestCase {
|
|||
public function testLastInsertId() {
|
||||
$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
|
||||
$result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1'));
|
||||
$id1 = OC_DB::insertid('*PREFIX*'.$this->table2);
|
||||
$id1 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2);
|
||||
|
||||
// we don't know the id we should expect, so insert another row
|
||||
$result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2'));
|
||||
$id2 = OC_DB::insertid('*PREFIX*'.$this->table2);
|
||||
$id2 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2);
|
||||
// now we can check if the two ids are in correct order
|
||||
$this->assertGreaterThan($id1, $id2);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class RepairLegacyStorages extends TestCase {
|
|||
$numRows = $this->connection->executeUpdate($sql, array($storageId));
|
||||
$this->assertEquals(1, $numRows);
|
||||
|
||||
return \OC_DB::insertid('*PREFIX*storages');
|
||||
return \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue