summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-08 09:49:21 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-12-08 09:49:21 +0100
commita3391248e46bbc389dc1880f7ae50aa5dade8731 (patch)
treeeb3451415520fa2557a141a5145f28b2fb6023fb /tests
parentf2c7acb3c065c35a1e75d512d0ce193f1989296f (diff)
downloadnextcloud-server-a3391248e46bbc389dc1880f7ae50aa5dade8731.tar.gz
nextcloud-server-a3391248e46bbc389dc1880f7ae50aa5dade8731.zip
Add select distinct to the query builder
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/db/querybuilder/querybuildertest.php36
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php
index 828a860ee80..b52fbd7c283 100644
--- a/tests/lib/db/querybuilder/querybuildertest.php
+++ b/tests/lib/db/querybuilder/querybuildertest.php
@@ -48,12 +48,12 @@ class QueryBuilderTest extends \Test\TestCase {
$this->queryBuilder = new QueryBuilder($this->connection);
}
- protected function createTestingRows() {
+ protected function createTestingRows($appId = 'testFirstResult') {
$qB = $this->connection->getQueryBuilder();
for ($i = 1; $i < 10; $i++) {
$qB->insert('*PREFIX*appconfig')
->values([
- 'appid' => $qB->expr()->literal('testFirstResult'),
+ 'appid' => $qB->expr()->literal($appId),
'configkey' => $qB->expr()->literal('testing' . $i),
'configvalue' => $qB->expr()->literal(100 - $i),
])
@@ -80,11 +80,11 @@ class QueryBuilderTest extends \Test\TestCase {
return $rows;
}
- protected function deleteTestingRows() {
+ protected function deleteTestingRows($appId = 'testFirstResult') {
$qB = $this->connection->getQueryBuilder();
$qB->delete('*PREFIX*appconfig')
- ->where($qB->expr()->eq('appid', $qB->expr()->literal('testFirstResult')))
+ ->where($qB->expr()->eq('appid', $qB->expr()->literal($appId)))
->execute();
}
@@ -272,6 +272,34 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows();
}
+ public function testSelectDistinct() {
+ $this->deleteTestingRows('testFirstResult1');
+ $this->deleteTestingRows('testFirstResult2');
+ $this->createTestingRows('testFirstResult1');
+ $this->createTestingRows('testFirstResult2');
+
+ $this->queryBuilder->selectDistinct('appid');
+
+ $this->queryBuilder->from('*PREFIX*appconfig')
+ ->where($this->queryBuilder->expr()->in(
+ 'appid',
+ [$this->queryBuilder->expr()->literal('testFirstResult1'), $this->queryBuilder->expr()->literal('testFirstResult2')]
+ ))
+ ->orderBy('appid', 'DESC');
+
+ $query = $this->queryBuilder->execute();
+ $rows = $query->fetchAll();
+ $query->closeCursor();
+
+ $this->assertEquals(
+ [['appid' => 'testFirstResult2'], ['appid' => 'testFirstResult1']],
+ $rows
+ );
+
+ $this->deleteTestingRows('testFirstResult1');
+ $this->deleteTestingRows('testFirstResult2');
+ }
+
public function dataAddSelect() {
$queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection());
return [