1
0

SqliteFunctionBuilder.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\DB\QueryBuilder\FunctionBuilder;
  7. use OC\DB\QueryBuilder\QueryFunction;
  8. use OCP\DB\QueryBuilder\IQueryFunction;
  9. class SqliteFunctionBuilder extends FunctionBuilder {
  10. public function concat($x, ...$expr): IQueryFunction {
  11. $args = func_get_args();
  12. $list = [];
  13. foreach ($args as $item) {
  14. $list[] = $this->helper->quoteColumnName($item);
  15. }
  16. return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
  17. }
  18. public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
  19. $separator = $this->connection->quote($separator);
  20. return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
  21. }
  22. public function greatest($x, $y): IQueryFunction {
  23. return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
  24. }
  25. public function least($x, $y): IQueryFunction {
  26. return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
  27. }
  28. public function octetLength($field, $alias = ''): IQueryFunction {
  29. $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
  30. $quotedName = $this->helper->quoteColumnName($field);
  31. return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
  32. }
  33. public function charLength($field, $alias = ''): IQueryFunction {
  34. $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
  35. $quotedName = $this->helper->quoteColumnName($field);
  36. return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
  37. }
  38. }