diff options
author | Vitor Mattos <vitor@php.rio> | 2021-12-21 12:18:15 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2022-01-03 07:48:11 -0300 |
commit | 79b3df00f82f3d0eee397f5389d23c8af1727afd (patch) | |
tree | 69bd942fd443b7f560ae6d0dbd72f2b1be873e00 /lib/private | |
parent | 29dffd7e7fc84faa6a4317c691c6cac9eaf42f42 (diff) | |
download | nextcloud-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')
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')"); + } } |