summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-06-14 14:32:22 +0200
committerRobin Appelman <robin@icewind.nl>2018-06-14 14:32:22 +0200
commit3047ef31bd8b667cd6d95e133f5968a6822ff279 (patch)
treed07fbfcaca98477f0b6f68a7d95f5f2e0448dc2e
parentcd87a40eb3a2b7026dfd1822e6e43e131edd3423 (diff)
downloadnextcloud-server-3047ef31bd8b667cd6d95e133f5968a6822ff279.tar.gz
nextcloud-server-3047ef31bd8b667cd6d95e133f5968a6822ff279.zip
Add count to function builder
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php4
-rw-r--r--lib/public/DB/QueryBuilder/IFunctionBuilder.php8
-rw-r--r--tests/lib/DB/QueryBuilder/FunctionBuilderTest.php10
3 files changed, 22 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
index bd367973097..cf6183b0238 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
@@ -71,4 +71,8 @@ class FunctionBuilder implements IFunctionBuilder {
public function subtract($x, $y) {
return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
}
+
+ public function count($input) {
+ return new QueryFunction('COUNT(' . $this->helper->quoteColumnName($input) . ')');
+ }
}
diff --git a/lib/public/DB/QueryBuilder/IFunctionBuilder.php b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
index e0e331c0807..51b639028ce 100644
--- a/lib/public/DB/QueryBuilder/IFunctionBuilder.php
+++ b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
@@ -96,4 +96,12 @@ interface IFunctionBuilder {
* @since 14.0.0
*/
public function subtract($x, $y);
+
+ /**
+ * @param mixed $input The input to be counted
+ *
+ * @return IQueryFunction
+ * @since 14.0.0
+ */
+ public function count($input);
}
diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
index 1b998287c98..136650741f5 100644
--- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
@@ -110,4 +110,14 @@ class FunctionBuilderTest extends TestCase {
$this->assertEquals(1, $query->execute()->fetchColumn());
}
+
+ public function testCount() {
+ $query = $this->connection->getQueryBuilder();
+
+ $query->select($query->func()->count('appid'));
+ $query->from('appconfig')
+ ->setMaxResults(1);
+
+ $this->assertGreaterThan(1, $query->execute()->fetchColumn());
+ }
}