1
0

PgSqlExpressionBuilder.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\DB\QueryBuilder\ExpressionBuilder;
  26. use OC\DB\QueryBuilder\QueryFunction;
  27. use OCP\DB\QueryBuilder\IQueryBuilder;
  28. use OCP\DB\QueryBuilder\IQueryFunction;
  29. class PgSqlExpressionBuilder extends ExpressionBuilder {
  30. /**
  31. * Returns a IQueryFunction that casts the column to the given type
  32. *
  33. * @param string|IQueryFunction $column
  34. * @param mixed $type One of IQueryBuilder::PARAM_*
  35. * @psalm-param IQueryBuilder::PARAM_* $type
  36. * @return IQueryFunction
  37. */
  38. public function castColumn($column, $type): IQueryFunction {
  39. switch ($type) {
  40. case IQueryBuilder::PARAM_INT:
  41. return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)');
  42. case IQueryBuilder::PARAM_STR:
  43. return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
  44. default:
  45. return parent::castColumn($column, $type);
  46. }
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function iLike($x, $y, $type = null): string {
  52. $x = $this->helper->quoteColumnName($x);
  53. $y = $this->helper->quoteColumnName($y);
  54. return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
  55. }
  56. }