mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Fix groupConcat and ordering on Oracle
Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
parent
f7cd995612
commit
f071b4dfbb
6 changed files with 12 additions and 10 deletions
|
|
@ -1210,20 +1210,21 @@ class Manager implements ICommentsManager {
|
|||
$totalQuery->expr()->literal('":'),
|
||||
$totalQuery->func()->count('id')
|
||||
),
|
||||
'total'
|
||||
'colonseparatedvalue'
|
||||
)
|
||||
->selectAlias($totalQuery->func()->count('id'), 'total')
|
||||
->from('reactions', 'r')
|
||||
->where($totalQuery->expr()->eq('r.parent_id', $qb->createNamedParameter($parentId)))
|
||||
->groupBy('r.reaction')
|
||||
->orderBy($totalQuery->func()->count('id'), 'DESC')
|
||||
->orderBy('total', 'DESC')
|
||||
->setMaxResults(200);
|
||||
|
||||
$jsonQuery = $this->dbConn->getQueryBuilder();
|
||||
$jsonQuery
|
||||
->selectAlias(
|
||||
$totalQuery->func()->concat(
|
||||
$jsonQuery->func()->concat(
|
||||
$jsonQuery->expr()->literal('{'),
|
||||
$jsonQuery->func()->groupConcat('total'),
|
||||
$jsonQuery->func()->groupConcat('colonseparatedvalue', ',', $jsonQuery->getColumnName('total') . ' DESC'),
|
||||
$jsonQuery->expr()->literal('}')
|
||||
),
|
||||
'json'
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class FunctionBuilder implements IFunctionBuilder {
|
|||
return new QueryFunction(sprintf('CONCAT(%s)', implode(', ', $list)));
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction {
|
||||
$separator = $this->connection->quote($separator);
|
||||
return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ class OCIFunctionBuilder extends FunctionBuilder {
|
|||
return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
$orderByClause = ' WITHIN GROUP(ORDER BY NULL)';
|
||||
public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = 'NULL'): IQueryFunction {
|
||||
$orderByClause = ' WITHIN GROUP(ORDER BY ' . $orderBy . ')';
|
||||
if (is_null($separator)) {
|
||||
return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . ')' . $orderByClause);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class PgSqlFunctionBuilder extends FunctionBuilder {
|
|||
return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction {
|
||||
$castedExpression = $this->queryBuilder->expr()->castColumn($expr, IQueryBuilder::PARAM_STR);
|
||||
|
||||
if (is_null($separator)) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class SqliteFunctionBuilder extends FunctionBuilder {
|
|||
return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction {
|
||||
$separator = $this->connection->quote($separator);
|
||||
return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,11 @@ interface IFunctionBuilder {
|
|||
*
|
||||
* @param string|IQueryFunction $expr The expression to group
|
||||
* @param string|null $separator The separator
|
||||
* @param string|null $orderBy Option only used to make compatible with Oracle database if is necessary use order. The default value is null and the Oracle don't will respect the order by of query
|
||||
* @return IQueryFunction
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
|
||||
public function groupConcat($expr, ?string $separator = ',', ?string $orderBy = null): IQueryFunction;
|
||||
|
||||
/**
|
||||
* Takes a substring from the input string
|
||||
|
|
|
|||
Loading…
Reference in a new issue