From 20f8d1094ab9958dc50104a79a2ad0f0a9e0ce1a Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Sat, 22 Jul 2017 12:21:00 +0200
Subject: [PATCH] Can not insert auto increment on oracle

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 lib/private/Comments/Manager.php              |  2 +-
 .../Repair/NC12/UpdateLanguageCodes.php       |  3 +-
 lib/private/User/Manager.php                  |  3 +-
 tests/lib/Comments/ManagerTest.php            | 50 +++++++++----------
 .../lib/Files/Cache/QuerySearchHelperTest.php | 41 ++++++++-------
 5 files changed, 53 insertions(+), 46 deletions(-)

diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index 0c2a5efe601..078e1eef4d3 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -411,7 +411,7 @@ class Manager implements ICommentsManager {
 	 */
 	public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) {
 		$qb = $this->dbConn->getQueryBuilder();
-		$query = $qb->select('fileid')
+		$query = $qb->select('f.fileid')
 			->selectAlias(
 				$qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'),
 				'num_ids'
diff --git a/lib/private/Repair/NC12/UpdateLanguageCodes.php b/lib/private/Repair/NC12/UpdateLanguageCodes.php
index 891473f51a7..f4a1204543b 100644
--- a/lib/private/Repair/NC12/UpdateLanguageCodes.php
+++ b/lib/private/Repair/NC12/UpdateLanguageCodes.php
@@ -23,6 +23,7 @@
 
 namespace OC\Repair\NC12;
 
+use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IConfig;
 use OCP\IDBConnection;
 use OCP\Migration\IOutput;
@@ -80,7 +81,7 @@ class UpdateLanguageCodes implements IRepairStep {
 				->set('configvalue', $qb->createNamedParameter($newCode))
 				->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
 				->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
-				->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode)))
+				->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR))
 				->execute();
 
 			$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index ded807a223b..8f3c98d4b5e 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -34,6 +34,7 @@
 namespace OC\User;
 
 use OC\Hooks\PublicEmitter;
+use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IUser;
 use OCP\IUserBackend;
 use OCP\IUserManager;
@@ -436,7 +437,7 @@ class Manager extends PublicEmitter implements IUserManager {
 			->from('preferences')
 			->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
 			->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
-			->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false')));
+			->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR));
 
 		$query = $queryBuilder->execute();
 
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 24c634be137..b04f3bd567e 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -307,29 +307,9 @@ class ManagerTest extends TestCase {
 	}
 
 	public function testGetNumberOfUnreadCommentsForFolder() {
-		// 2 comment for 1111 with 1 before read marker
-		// 2 comments for 1112 with no read marker
-		// 1 comment for 1113 before read marker
-		// 1 comment for 1114 with no read marker
-		$this->addDatabaseEntry(0, 0, null, null, '1112');
-		for ($i = 1; $i < 5; $i++) {
-			$this->addDatabaseEntry(0, 0, null, null, '111' . $i);
-		}
-		$this->addDatabaseEntry(0, 0, (new \DateTime())->modify('-2 days'), null, '1111');
-		$user = $this->createMock(IUser::class);
-		$user->expects($this->any())
-			->method('getUID')
-			->will($this->returnValue('comment_test'));
-
-		$manager = $this->getManager();
-
-		$manager->setReadMark('files', '1111', (new \DateTime())->modify('-1 days'), $user);
-		$manager->setReadMark('files', '1113', (new \DateTime()), $user);
-
 		$query = $this->connection->getQueryBuilder();
 		$query->insert('filecache')
 			->values([
-				'fileid' => $query->createParameter('fileid'),
 				'parent' => $query->createNamedParameter(1000),
 				'size' => $query->createNamedParameter(10),
 				'mtime' => $query->createNamedParameter(10),
@@ -338,17 +318,37 @@ class ManagerTest extends TestCase {
 				'path_hash' => $query->createParameter('path'),
 			]);
 
-		for ($i = 1111; $i < 1115; $i++) {
+		$fileIds = [];
+		for ($i = 0; $i < 4; $i++) {
 			$query->setParameter('path', 'path_' . $i);
-			$query->setParameter('fileid', $i);
 			$query->execute();
+			$fileIds[] = $query->getLastInsertId();
 		}
 
+		// 2 comment for 1111 with 1 before read marker
+		// 2 comments for 1112 with no read marker
+		// 1 comment for 1113 before read marker
+		// 1 comment for 1114 with no read marker
+		$this->addDatabaseEntry(0, 0, null, null, $fileIds[1]);
+		for ($i = 0; $i < 4; $i++) {
+			$this->addDatabaseEntry(0, 0, null, null, $fileIds[$i]);
+		}
+		$this->addDatabaseEntry(0, 0, (new \DateTime())->modify('-2 days'), null, $fileIds[0]);
+		$user = $this->createMock(IUser::class);
+		$user->expects($this->any())
+			->method('getUID')
+			->will($this->returnValue('comment_test'));
+
+		$manager = $this->getManager();
+
+		$manager->setReadMark('files', (string) $fileIds[0], (new \DateTime())->modify('-1 days'), $user);
+		$manager->setReadMark('files', (string) $fileIds[2], (new \DateTime()), $user);
+
 		$amount = $manager->getNumberOfUnreadCommentsForFolder(1000, $user);
 		$this->assertEquals([
-			'1111' => 1,
-			'1112' => 2,
-			'1114' => 1,
+			$fileIds[0] => 1,
+			$fileIds[1] => 2,
+			$fileIds[3] => 1,
 		], $amount);
 	}
 
diff --git a/tests/lib/Files/Cache/QuerySearchHelperTest.php b/tests/lib/Files/Cache/QuerySearchHelperTest.php
index f458ef039e1..850cee066a1 100644
--- a/tests/lib/Files/Cache/QuerySearchHelperTest.php
+++ b/tests/lib/Files/Cache/QuerySearchHelperTest.php
@@ -129,6 +129,8 @@ class QuerySearchHelperTest extends TestCase {
 		$builder->insert('filecache')
 			->values($values)
 			->execute();
+
+		return $builder->getLastInsertId();
 	}
 
 	private function search(ISearchOperator $operator) {
@@ -139,34 +141,34 @@ class QuerySearchHelperTest extends TestCase {
 
 	public function comparisonProvider() {
 		return [
-			[new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1002]],
-			[new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [1001]],
+			[new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1]],
+			[new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [0]],
 			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 125), []],
-			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50), [1001, 1002]],
-			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), [1001]],
-			[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%'), [1001, 1002]],
-			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'image/jpg'), [1001]],
-			[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'image/%'), [1001, 1002]],
+			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50), [0, 1]],
+			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), [0]],
+			[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%'), [0, 1]],
+			[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'image/jpg'), [0]],
+			[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'image/%'), [0, 1]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
 				new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50),
-				new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [1001]
-			]), [1001]],
+				new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [0]
+			]), [0]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [
 				new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 100),
 				new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 150),
-			]), [1001, 1002]],
+			]), [0, 1]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [
 				new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 150),
-			]), [1001]],
+			]), [0]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [
 				new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125),
-			]), [1001]],
+			]), [0]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [
 				new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125),
-			]), [1002]],
+			]), [1]],
 			[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [
 				new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%bar'),
-			]), [1002]],
+			]), [1]],
 
 		];
 	}
@@ -178,22 +180,25 @@ class QuerySearchHelperTest extends TestCase {
 	 * @param array $fileIds
 	 */
 	public function testComparison(ISearchOperator $operator, array $fileIds) {
-		$this->addCacheEntry([
+		$fileId = [];
+		$fileId[] = $this->addCacheEntry([
 			'path' => 'foobar',
-			'fileid' => 1001,
 			'mtime' => 100,
 			'size' => 50,
 			'mimetype' => 'image/jpg'
 		]);
 
-		$this->addCacheEntry([
+		$fileId[] = $this->addCacheEntry([
 			'path' => 'fooasd',
-			'fileid' => 1002,
 			'mtime' => 150,
 			'size' => 50,
 			'mimetype' => 'image/png'
 		]);
 
+		$fileIds = array_map(function($i) use ($fileId) {
+			return $fileId[$i];
+		}, $fileIds);
+
 		$results = $this->search($operator);
 
 		sort($fileIds);
-- 
GitLab