Add count to function builder

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/9881/head
Robin Appelman 7 years ago
parent cd87a40eb3
commit 3047ef31bd
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
  1. 4
      lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
  2. 8
      lib/public/DB/QueryBuilder/IFunctionBuilder.php
  3. 10
      tests/lib/DB/QueryBuilder/FunctionBuilderTest.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) . ')');
}
}

@ -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);
}

@ -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());
}
}

Loading…
Cancel
Save