aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2021-12-21 12:18:15 -0300
committerVitor Mattos <vitor@php.rio>2022-01-03 07:48:11 -0300
commit79b3df00f82f3d0eee397f5389d23c8af1727afd (patch)
tree69bd942fd443b7f560ae6d0dbd72f2b1be873e00 /lib/private/DB
parent29dffd7e7fc84faa6a4317c691c6cac9eaf42f42 (diff)
downloadnextcloud-server-79b3df00f82f3d0eee397f5389d23c8af1727afd.tar.gz
nextcloud-server-79b3df00f82f3d0eee397f5389d23c8af1727afd.zip
Add group_concat aggregator function
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib/private/DB')
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php4
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php7
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php7
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
index dfc0d0a6d61..88290237a90 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
@@ -49,6 +49,10 @@ class FunctionBuilder implements IFunctionBuilder {
return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
}
+ public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
+ return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ')');
+ }
+
public function substring($input, $start, $length = null): IQueryFunction {
if ($length) {
return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
index 5581207a166..af72d85d511 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
@@ -72,4 +72,11 @@ class OCIFunctionBuilder extends FunctionBuilder {
return parent::least($x, $y);
}
+
+ public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
+ if (is_null($separator)) {
+ return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr));
+ }
+ return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . ", '$separator')");
+ }
}
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
index 853c65ac32a..a3a25b7e293 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
@@ -30,4 +30,11 @@ class PgSqlFunctionBuilder extends FunctionBuilder {
public function concat($x, $y): IQueryFunction {
return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')');
}
+
+ public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
+ if (is_null($separator)) {
+ return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr));
+ }
+ return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr) . ", '$separator')");
+ }
}