diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-23 13:29:08 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-23 13:29:08 +0100 |
commit | df906f475bbf22788620ef05a58231639b5423ad (patch) | |
tree | 5993395b1bf1c1aea9bd926263a93665e39a1dc7 | |
parent | 240cc1c4ead5f89e3c296bfb8f0b34b7c3748316 (diff) | |
parent | aa660ec232a236a9c62e4bf2b1535127bb8521be (diff) | |
download | nextcloud-server-df906f475bbf22788620ef05a58231639b5423ad.tar.gz nextcloud-server-df906f475bbf22788620ef05a58231639b5423ad.zip |
Merge pull request #20617 from owncloud/fix-usage-of-lastInsertId
lastInsertId() is properly working with Oracle if the table name is p…
-rw-r--r-- | lib/private/db/adapteroci8.php | 3 | ||||
-rw-r--r-- | lib/private/db/connection.php | 3 | ||||
-rw-r--r-- | lib/private/share/share.php | 17 | ||||
-rw-r--r-- | tests/lib/repair/cleantags.php | 16 | ||||
-rw-r--r-- | tests/lib/repair/oldgroupmembershipsharestest.php | 21 | ||||
-rw-r--r-- | tests/lib/repair/repairinvalidsharestest.php | 14 |
6 files changed, 12 insertions, 62 deletions
diff --git a/lib/private/db/adapteroci8.php b/lib/private/db/adapteroci8.php index 6e7857e6620..76c265bc178 100644 --- a/lib/private/db/adapteroci8.php +++ b/lib/private/db/adapteroci8.php @@ -26,6 +26,9 @@ namespace OC\DB; class AdapterOCI8 extends Adapter { public function lastInsertId($table) { + if (is_null($table)) { + throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); + } if ($table !== null) { $suffix = '_SEQ'; $table = '"' . $table . $suffix . '"'; diff --git a/lib/private/db/connection.php b/lib/private/db/connection.php index 1b86d3d383a..85b1b7cd5ea 100644 --- a/lib/private/db/connection.php +++ b/lib/private/db/connection.php @@ -214,8 +214,7 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection { * @param string $seqName Name of the sequence object from which the ID should be returned. * @return string A string representation of the last inserted ID. */ - public function lastInsertId($seqName = null) - { + public function lastInsertId($seqName = null) { if ($seqName) { $seqName = $this->replaceTablePrefix($seqName); } diff --git a/lib/private/share/share.php b/lib/private/share/share.php index d377708a268..6aac0d6264d 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -2332,22 +2332,7 @@ class Share extends Constants { $id = false; if ($result) { - $id = \OC::$server->getDatabaseConnection()->lastInsertId(); - // 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']; - } - } - + $id = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share'); } return $id; diff --git a/tests/lib/repair/cleantags.php b/tests/lib/repair/cleantags.php index a511daa03d6..896dd333cc2 100644 --- a/tests/lib/repair/cleantags.php +++ b/tests/lib/repair/cleantags.php @@ -165,20 +165,6 @@ class CleanTags extends \Test\TestCase { * @return int */ protected function getLastInsertID($tableName, $idName) { - $id = $this->connection->lastInsertId(); - 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(); + return $this->connection->lastInsertId("*PREFIX*$tableName"); } } diff --git a/tests/lib/repair/oldgroupmembershipsharestest.php b/tests/lib/repair/oldgroupmembershipsharestest.php index 74f68bd7899..272e1ef09c4 100644 --- a/tests/lib/repair/oldgroupmembershipsharestest.php +++ b/tests/lib/repair/oldgroupmembershipsharestest.php @@ -72,7 +72,7 @@ class OldGroupMembershipSharesTest extends \Test\TestCase { ->orderBy('id', 'ASC') ->execute(); $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(); $repair->run(); @@ -83,7 +83,7 @@ class OldGroupMembershipSharesTest extends \Test\TestCase { ->orderBy('id', 'ASC') ->execute(); $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(); } @@ -118,21 +118,6 @@ class OldGroupMembershipSharesTest extends \Test\TestCase { ->values($shareValues) ->execute(); - return $this->getLastShareId(); - } - - /** - * @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']; + return $this->connection->lastInsertId('*PREFIX*share'); } } diff --git a/tests/lib/repair/repairinvalidsharestest.php b/tests/lib/repair/repairinvalidsharestest.php index 005a2db2344..e8dcaa4da97 100644 --- a/tests/lib/repair/repairinvalidsharestest.php +++ b/tests/lib/repair/repairinvalidsharestest.php @@ -162,7 +162,7 @@ class RepairInvalidSharesTest extends TestCase { ->orderBy('id', 'ASC') ->execute(); $rows = $result->fetchAll(); - $this->assertSame([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows); + $this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows); $result->closeCursor(); $this->repair->run(); @@ -173,7 +173,7 @@ class RepairInvalidSharesTest extends TestCase { ->orderBy('id', 'ASC') ->execute(); $rows = $result->fetchAll(); - $this->assertSame([['id' => $parent], ['id' => $validChild]], $rows); + $this->assertEquals([['id' => $parent], ['id' => $validChild]], $rows); $result->closeCursor(); } @@ -181,15 +181,7 @@ class RepairInvalidSharesTest extends TestCase { * @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']; + return $this->connection->lastInsertId('*PREFIX*share'); } } |