0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-01-31 14:53:18 +00:00
nextcloud_server/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php
Julius Härtl 86dc766276 Cast datetime columns in sqlite before comparing
Move the logic to prepare a column to the parent ExpressionBuilder so
that it can be reused for OCI and sqlite

Signed-off-by: Julius Härtl <jus@bitgrid.net>
2023-12-29 10:36:59 +01:00

72 lines
2.3 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
*
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\DB\QueryBuilder\ExpressionBuilder;
use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\ILiteral;
use OCP\DB\QueryBuilder\IParameter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
class SqliteExpressionBuilder extends ExpressionBuilder {
/**
* @inheritdoc
*/
public function like($x, $y, $type = null): string {
return parent::like($x, $y, $type) . " ESCAPE '\\'";
}
public function iLike($x, $y, $type = null): string {
return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type);
}
/**
* @param mixed $column
* @param mixed|null $type
* @return array|IQueryFunction|string
*/
protected function prepareColumn($column, $type) {
if ($type === IQueryBuilder::PARAM_DATE && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
return $this->castColumn($column, $type);
}
return parent::prepareColumn($column, $type);
}
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return IQueryFunction
*/
public function castColumn($column, $type): IQueryFunction {
if ($type === IQueryBuilder::PARAM_DATE) {
$column = $this->helper->quoteColumnName($column);
return new QueryFunction('DATETIME(' . $column . ')');
}
return parent::castColumn($column, $type);
}
}