mirror of
https://github.com/nextcloud/server.git
synced 2024-07-30 20:16:04 +02:00
lastInsertId() is properly working with Oracle if the table name is properly passed in
This commit is contained in:
parent
79bbda994b
commit
9f69021691
@ -2332,22 +2332,7 @@ class Share extends Constants {
|
|||||||
|
|
||||||
$id = false;
|
$id = false;
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$id = \OC::$server->getDatabaseConnection()->lastInsertId();
|
$id = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share');
|
||||||
// Fallback, if lastInterId() doesn't work we need to perform a select
|
|
||||||
// to get the ID (seems to happen sometimes on Oracle)
|
|
||||||
if (!$id) {
|
|
||||||
$getId = \OC_DB::prepare('
|
|
||||||
SELECT `id`
|
|
||||||
FROM`*PREFIX*share`
|
|
||||||
WHERE `uid_owner` = ? AND `item_target` = ? AND `item_source` = ? AND `stime` = ?
|
|
||||||
');
|
|
||||||
$r = $getId->execute(array($shareData['uidOwner'], $shareData['itemTarget'], $shareData['itemSource'], $shareData['shareTime']));
|
|
||||||
if ($r) {
|
|
||||||
$row = $r->fetchRow();
|
|
||||||
$id = $row['id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
|
@ -165,20 +165,6 @@ class CleanTags extends \Test\TestCase {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function getLastInsertID($tableName, $idName) {
|
protected function getLastInsertID($tableName, $idName) {
|
||||||
$id = $this->connection->lastInsertId();
|
return $this->connection->lastInsertId("*PREFIX*$tableName");
|
||||||
if ($id) {
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME !!!! ORACLE WORKAROUND DO NOT COPY
|
|
||||||
// FIXME INSTEAD HELP FIXING DOCTRINE
|
|
||||||
// FIXME https://github.com/owncloud/core/issues/13303
|
|
||||||
// FIXME ALSO FIX https://github.com/owncloud/core/commit/2dd85ec984c12d3be401518f22c90d2327bec07a
|
|
||||||
$qb = $this->connection->getQueryBuilder();
|
|
||||||
$result = $qb->select($qb->createFunction('MAX(`' . $idName . '`)'))
|
|
||||||
->from($tableName)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
return (int) $result->fetchColumn();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class OldGroupMembershipSharesTest extends \Test\TestCase {
|
|||||||
->orderBy('id', 'ASC')
|
->orderBy('id', 'ASC')
|
||||||
->execute();
|
->execute();
|
||||||
$rows = $result->fetchAll();
|
$rows = $result->fetchAll();
|
||||||
$this->assertSame([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows);
|
$this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows);
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
|
|
||||||
$repair->run();
|
$repair->run();
|
||||||
@ -83,7 +83,7 @@ class OldGroupMembershipSharesTest extends \Test\TestCase {
|
|||||||
->orderBy('id', 'ASC')
|
->orderBy('id', 'ASC')
|
||||||
->execute();
|
->execute();
|
||||||
$rows = $result->fetchAll();
|
$rows = $result->fetchAll();
|
||||||
$this->assertSame([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member]], $rows);
|
$this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member]], $rows);
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,21 +118,6 @@ class OldGroupMembershipSharesTest extends \Test\TestCase {
|
|||||||
->values($shareValues)
|
->values($shareValues)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
return $this->getLastShareId();
|
return $this->connection->lastInsertId('*PREFIX*share');
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
protected function getLastShareId() {
|
|
||||||
// select because lastInsertId does not work with OCI
|
|
||||||
$query = $this->connection->getQueryBuilder();
|
|
||||||
$result = $query->select('id')
|
|
||||||
->from('share')
|
|
||||||
->orderBy('id', 'DESC')
|
|
||||||
->execute();
|
|
||||||
$row = $result->fetch();
|
|
||||||
$result->closeCursor();
|
|
||||||
return $row['id'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ class RepairInvalidSharesTest extends TestCase {
|
|||||||
->orderBy('id', 'ASC')
|
->orderBy('id', 'ASC')
|
||||||
->execute();
|
->execute();
|
||||||
$rows = $result->fetchAll();
|
$rows = $result->fetchAll();
|
||||||
$this->assertSame([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows);
|
$this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows);
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
|
|
||||||
$this->repair->run();
|
$this->repair->run();
|
||||||
@ -173,7 +173,7 @@ class RepairInvalidSharesTest extends TestCase {
|
|||||||
->orderBy('id', 'ASC')
|
->orderBy('id', 'ASC')
|
||||||
->execute();
|
->execute();
|
||||||
$rows = $result->fetchAll();
|
$rows = $result->fetchAll();
|
||||||
$this->assertSame([['id' => $parent], ['id' => $validChild]], $rows);
|
$this->assertEquals([['id' => $parent], ['id' => $validChild]], $rows);
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,15 +181,7 @@ class RepairInvalidSharesTest extends TestCase {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function getLastShareId() {
|
protected function getLastShareId() {
|
||||||
// select because lastInsertId does not work with OCI
|
return $this->connection->lastInsertId('*PREFIX*share');
|
||||||
$query = $this->connection->getQueryBuilder();
|
|
||||||
$result = $query->select('id')
|
|
||||||
->from('share')
|
|
||||||
->orderBy('id', 'DESC')
|
|
||||||
->execute();
|
|
||||||
$row = $result->fetch();
|
|
||||||
$result->closeCursor();
|
|
||||||
return $row['id'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user