1
0

SqliteExpressionBuilder.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\DB\QueryBuilder\ExpressionBuilder;
  25. use OC\DB\QueryBuilder\QueryFunction;
  26. use OCP\DB\QueryBuilder\ILiteral;
  27. use OCP\DB\QueryBuilder\IParameter;
  28. use OCP\DB\QueryBuilder\IQueryBuilder;
  29. use OCP\DB\QueryBuilder\IQueryFunction;
  30. class SqliteExpressionBuilder extends ExpressionBuilder {
  31. /**
  32. * @inheritdoc
  33. */
  34. public function like($x, $y, $type = null): string {
  35. return parent::like($x, $y, $type) . " ESCAPE '\\'";
  36. }
  37. public function iLike($x, $y, $type = null): string {
  38. return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type);
  39. }
  40. /**
  41. * @param mixed $column
  42. * @param mixed|null $type
  43. * @return array|IQueryFunction|string
  44. */
  45. protected function prepareColumn($column, $type) {
  46. if ($type === IQueryBuilder::PARAM_DATE && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
  47. return $this->castColumn($column, $type);
  48. }
  49. return parent::prepareColumn($column, $type);
  50. }
  51. /**
  52. * Returns a IQueryFunction that casts the column to the given type
  53. *
  54. * @param string $column
  55. * @param mixed $type One of IQueryBuilder::PARAM_*
  56. * @return IQueryFunction
  57. */
  58. public function castColumn($column, $type): IQueryFunction {
  59. if ($type === IQueryBuilder::PARAM_DATE) {
  60. $column = $this->helper->quoteColumnName($column);
  61. return new QueryFunction('DATETIME(' . $column . ')');
  62. }
  63. return parent::castColumn($column, $type);
  64. }
  65. }