diff options
author | Vitor Mattos <vitor@php.rio> | 2022-01-03 11:04:05 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2022-01-03 21:41:38 -0300 |
commit | fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f (patch) | |
tree | 15fe65abdae05c775dd4c484319c2f7319a88ac0 /lib | |
parent | 7b9fea85b6e893aca874b7a0a07866443822005a (diff) | |
download | nextcloud-server-fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f.tar.gz nextcloud-server-fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f.zip |
Add unit test
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib')
5 files changed, 12 insertions, 25 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php index 3384ad8b42f..6b5fb751fbd 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php @@ -54,14 +54,9 @@ class FunctionBuilder implements IFunctionBuilder { return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); } - public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction { - if (is_null($orderBy)) { - $orderByClause = ''; - } else { - $orderByClause = ' ORDER BY ' . $orderBy; - } + public function groupConcat($expr, ?string $separator = ','): IQueryFunction { $separator = $this->connection->quote($separator); - return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . $orderByClause . ' SEPARATOR ' . $separator . ')'); + return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')'); } public function substring($input, $start, $length = null): IQueryFunction { diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php index d3553565b7e..efc42e66112 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php @@ -73,11 +73,8 @@ class OCIFunctionBuilder extends FunctionBuilder { return parent::least($x, $y); } - public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction { - if (is_null($orderBy)) { - $orderBy = 'NULL'; - } - $orderByClause = ' WITHIN GROUP(ORDER BY ' . $orderBy . ')'; + public function groupConcat($expr, ?string $separator = ','): IQueryFunction { + $orderByClause = ' WITHIN GROUP(ORDER BY NULL)'; if (is_null($separator)) { return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . $orderByClause . ')'); } diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php index 702b71e12b8..f4c1364fab1 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php @@ -31,15 +31,11 @@ class PgSqlFunctionBuilder extends FunctionBuilder { return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')'); } - public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction { - if (is_null($orderBy)) { - $orderByClause = ''; - } else { - $orderByClause = ' ORDER BY ' . $orderBy; - } + public function groupConcat($expr, ?string $separator = ','): IQueryFunction { if (is_null($separator)) { - return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr) . $orderByClause . ')'); + return new QueryFunction('string_agg(cast(' . $this->helper->quoteColumnName($expr) . ' AS varchar)'); } - return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr) . ", '$separator'$orderByClause)"); + $separator = $this->connection->quote($separator); + return new QueryFunction('string_agg(cast(' . $this->helper->quoteColumnName($expr) . " AS varchar), $separator)"); } } diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php index 796495dfd89..74e4e30e7ff 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php @@ -31,9 +31,9 @@ class SqliteFunctionBuilder extends FunctionBuilder { return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')'); } - public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction { - $separator = $this->helper->quoteColumnName($separator); - return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . "$separator)"); + public function groupConcat($expr, ?string $separator = ','): IQueryFunction { + $separator = $this->connection->quote($separator); + return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ", $separator)"); } public function greatest($x, $y): IQueryFunction { diff --git a/lib/public/DB/QueryBuilder/IFunctionBuilder.php b/lib/public/DB/QueryBuilder/IFunctionBuilder.php index 466a1c4ddf4..e04a4cbfdba 100644 --- a/lib/public/DB/QueryBuilder/IFunctionBuilder.php +++ b/lib/public/DB/QueryBuilder/IFunctionBuilder.php @@ -62,11 +62,10 @@ interface IFunctionBuilder { * * @param string|ILiteral|IParameter|IQueryFunction $expr The expression to group * @param string|null $separator The separator - * @param string|null $orderBy Optional SQL expression (and direction) to order the grouped rows by. * @return IQueryFunction * @since 24.0.0 */ - public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction; + public function groupConcat($expr, ?string $separator = ','): IQueryFunction; /** * Takes a substring from the input string |