2016-02-05 14:32:34 +00:00
|
|
|
<?php
|
2024-05-23 07:26:56 +00:00
|
|
|
|
2016-02-05 14:32:34 +00:00
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-05 14:32:34 +00:00
|
|
|
*/
|
|
|
|
namespace OC\DB\QueryBuilder\ExpressionBuilder;
|
|
|
|
|
|
|
|
use OC\DB\QueryBuilder\QueryFunction;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2021-02-15 15:36:20 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryFunction;
|
2016-02-05 14:32:34 +00:00
|
|
|
|
|
|
|
class PgSqlExpressionBuilder extends ExpressionBuilder {
|
|
|
|
/**
|
|
|
|
* Returns a IQueryFunction that casts the column to the given type
|
|
|
|
*
|
2021-07-07 12:20:24 +00:00
|
|
|
* @param string|IQueryFunction $column
|
2016-02-05 14:32:34 +00:00
|
|
|
* @param mixed $type One of IQueryBuilder::PARAM_*
|
2022-01-03 11:06:05 +00:00
|
|
|
* @psalm-param IQueryBuilder::PARAM_* $type
|
2021-02-15 15:36:20 +00:00
|
|
|
* @return IQueryFunction
|
2016-02-05 14:32:34 +00:00
|
|
|
*/
|
2021-02-15 15:36:20 +00:00
|
|
|
public function castColumn($column, $type): IQueryFunction {
|
2019-03-14 13:19:10 +00:00
|
|
|
switch ($type) {
|
|
|
|
case IQueryBuilder::PARAM_INT:
|
2024-07-19 16:03:54 +00:00
|
|
|
return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS BIGINT)');
|
2019-03-14 13:19:10 +00:00
|
|
|
case IQueryBuilder::PARAM_STR:
|
|
|
|
return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
|
|
|
|
default:
|
|
|
|
return parent::castColumn($column, $type);
|
2016-02-05 14:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-22 18:46:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function iLike($x, $y, $type = null): string {
|
2016-02-22 18:46:37 +00:00
|
|
|
$x = $this->helper->quoteColumnName($x);
|
|
|
|
$y = $this->helper->quoteColumnName($y);
|
2022-06-20 15:53:20 +00:00
|
|
|
return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
|
2016-02-22 18:46:37 +00:00
|
|
|
}
|
2016-02-05 14:32:34 +00:00
|
|
|
}
|