1
0

SqliteExpressionBuilder.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\ExpressionBuilder;
  7. use OC\DB\QueryBuilder\QueryFunction;
  8. use OCP\DB\QueryBuilder\ILiteral;
  9. use OCP\DB\QueryBuilder\IParameter;
  10. use OCP\DB\QueryBuilder\IQueryBuilder;
  11. use OCP\DB\QueryBuilder\IQueryFunction;
  12. class SqliteExpressionBuilder extends ExpressionBuilder {
  13. /**
  14. * @inheritdoc
  15. */
  16. public function like($x, $y, $type = null): string {
  17. return parent::like($x, $y, $type) . " ESCAPE '\\'";
  18. }
  19. public function iLike($x, $y, $type = null): string {
  20. return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type);
  21. }
  22. /**
  23. * @param mixed $column
  24. * @param mixed|null $type
  25. * @return array|IQueryFunction|string
  26. */
  27. protected function prepareColumn($column, $type) {
  28. if ($type === IQueryBuilder::PARAM_DATE && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
  29. return $this->castColumn($column, $type);
  30. }
  31. return parent::prepareColumn($column, $type);
  32. }
  33. /**
  34. * Returns a IQueryFunction that casts the column to the given type
  35. *
  36. * @param string $column
  37. * @param mixed $type One of IQueryBuilder::PARAM_*
  38. * @return IQueryFunction
  39. */
  40. public function castColumn($column, $type): IQueryFunction {
  41. if ($type === IQueryBuilder::PARAM_DATE) {
  42. $column = $this->helper->quoteColumnName($column);
  43. return new QueryFunction('DATETIME(' . $column . ')');
  44. }
  45. return parent::castColumn($column, $type);
  46. }
  47. }