2017-01-16 09:31:04 -05:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2017-01-16 09:31:04 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-01-16 09:31:04 -05:00
|
|
|
*/
|
|
|
|
|
namespace OC\DB\QueryBuilder\FunctionBuilder;
|
|
|
|
|
|
|
|
|
|
use OC\DB\QueryBuilder\QueryFunction;
|
2020-11-07 08:06:03 -05:00
|
|
|
use OCP\DB\QueryBuilder\IQueryFunction;
|
2017-01-16 09:31:04 -05:00
|
|
|
|
|
|
|
|
class SqliteFunctionBuilder extends FunctionBuilder {
|
2021-12-17 15:21:35 -05:00
|
|
|
public function concat($x, ...$expr): IQueryFunction {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
$list = [];
|
|
|
|
|
foreach ($args as $item) {
|
|
|
|
|
$list[] = $this->helper->quoteColumnName($item);
|
|
|
|
|
}
|
|
|
|
|
return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
|
2017-01-16 09:31:04 -05:00
|
|
|
}
|
2019-11-06 05:38:47 -05:00
|
|
|
|
2022-01-03 09:04:05 -05:00
|
|
|
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
|
|
|
|
$separator = $this->connection->quote($separator);
|
2022-01-04 02:50:10 -05:00
|
|
|
return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
|
2022-01-03 09:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
2020-11-16 13:17:21 -05:00
|
|
|
public function greatest($x, $y): IQueryFunction {
|
2019-11-06 05:38:47 -05:00
|
|
|
return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 13:17:21 -05:00
|
|
|
public function least($x, $y): IQueryFunction {
|
2019-11-06 05:38:47 -05:00
|
|
|
return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
|
|
|
|
|
}
|
2022-03-24 11:17:37 -04:00
|
|
|
|
|
|
|
|
public function octetLength($field, $alias = ''): IQueryFunction {
|
|
|
|
|
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
|
|
|
|
|
$quotedName = $this->helper->quoteColumnName($field);
|
|
|
|
|
return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
|
|
|
|
|
}
|
2022-03-27 18:01:17 -04:00
|
|
|
|
|
|
|
|
public function charLength($field, $alias = ''): IQueryFunction {
|
|
|
|
|
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
|
|
|
|
|
$quotedName = $this->helper->quoteColumnName($field);
|
|
|
|
|
return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
|
|
|
|
|
}
|
2017-01-16 09:31:04 -05:00
|
|
|
}
|