summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-12 12:55:09 -0500
committerGitHub <noreply@github.com>2017-04-12 12:55:09 -0500
commit124fdf8062139d5f1877e5fa9d0ce1969aa51e93 (patch)
tree2f937827859fbeb2869e358f173fb9c6e3242e72 /lib
parent31024b7700e025c78c1da94ab77564adeca54dee (diff)
parentac45af68cd7d30bb202e6b39ecf5bfcfd4b00225 (diff)
downloadnextcloud-server-124fdf8062139d5f1877e5fa9d0ce1969aa51e93.tar.gz
nextcloud-server-124fdf8062139d5f1877e5fa9d0ce1969aa51e93.zip
Merge pull request #4331 from nextcloud/query-builder-sum
Add sum() to the query function builder
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php4
-rw-r--r--lib/public/DB/QueryBuilder/IFunctionBuilder.php10
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
index 6bd98e4ce50..9ec8a9fd3c4 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
@@ -53,4 +53,8 @@ class FunctionBuilder implements IFunctionBuilder {
return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
}
}
+
+ public function sum($field) {
+ return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
+ }
}
diff --git a/lib/public/DB/QueryBuilder/IFunctionBuilder.php b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
index 6c1f596966d..38d3a67da9b 100644
--- a/lib/public/DB/QueryBuilder/IFunctionBuilder.php
+++ b/lib/public/DB/QueryBuilder/IFunctionBuilder.php
@@ -59,4 +59,14 @@ interface IFunctionBuilder {
* @since 12.0.0
*/
public function substring($input, $start, $length = null);
+
+ /**
+ * Takes the sum of all rows in a column
+ *
+ * @param mixed $field the column to sum
+ *
+ * @return IQueryFunction
+ * @since 12.0.0
+ */
+ public function sum($field);
}