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