PgSqlExpressionBuilder.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\DB\QueryBuilder\ExpressionBuilder;
  8. use OC\DB\QueryBuilder\QueryFunction;
  9. use OCP\DB\QueryBuilder\IQueryBuilder;
  10. use OCP\DB\QueryBuilder\IQueryFunction;
  11. class PgSqlExpressionBuilder extends ExpressionBuilder {
  12. /**
  13. * Returns a IQueryFunction that casts the column to the given type
  14. *
  15. * @param string|IQueryFunction $column
  16. * @param mixed $type One of IQueryBuilder::PARAM_*
  17. * @psalm-param IQueryBuilder::PARAM_* $type
  18. * @return IQueryFunction
  19. */
  20. public function castColumn($column, $type): IQueryFunction {
  21. switch ($type) {
  22. case IQueryBuilder::PARAM_INT:
  23. return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS BIGINT)');
  24. case IQueryBuilder::PARAM_STR:
  25. return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
  26. default:
  27. return parent::castColumn($column, $type);
  28. }
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function iLike($x, $y, $type = null): string {
  34. $x = $this->helper->quoteColumnName($x);
  35. $y = $this->helper->quoteColumnName($y);
  36. return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
  37. }
  38. }