2016-01-18 15:03:41 +00:00
|
|
|
<?php
|
2024-05-23 07:26:56 +00:00
|
|
|
|
2016-01-18 15:03:41 +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-01-18 15:03:41 +00:00
|
|
|
*/
|
2016-02-05 14:32:34 +00:00
|
|
|
namespace OC\DB\QueryBuilder\ExpressionBuilder;
|
2016-01-18 15:03:41 +00:00
|
|
|
|
2016-02-05 14:32:34 +00:00
|
|
|
use OC\DB\QueryBuilder\QueryFunction;
|
2016-01-26 10:27:35 +00:00
|
|
|
use OCP\DB\QueryBuilder\ILiteral;
|
|
|
|
use OCP\DB\QueryBuilder\IParameter;
|
2016-01-26 09:45:29 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2016-02-05 14:32:34 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryFunction;
|
2016-01-26 09:45:29 +00:00
|
|
|
|
2016-01-18 15:03:41 +00:00
|
|
|
class OCIExpressionBuilder extends ExpressionBuilder {
|
2016-01-26 10:27:35 +00:00
|
|
|
/**
|
2016-01-26 11:07:23 +00:00
|
|
|
* @param mixed $column
|
|
|
|
* @param mixed|null $type
|
2016-02-05 14:32:34 +00:00
|
|
|
* @return array|IQueryFunction|string
|
2016-01-26 10:27:35 +00:00
|
|
|
*/
|
2016-01-26 11:07:23 +00:00
|
|
|
protected function prepareColumn($column, $type) {
|
|
|
|
if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
|
2016-02-05 14:32:34 +00:00
|
|
|
$column = $this->castColumn($column, $type);
|
2016-01-26 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 14:57:48 +00:00
|
|
|
return parent::prepareColumn($column, $type);
|
2016-01-26 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function in($x, $y, $type = null): string {
|
2016-01-26 11:07:23 +00:00
|
|
|
$x = $this->prepareColumn($x, $type);
|
|
|
|
$y = $this->prepareColumn($y, $type);
|
2016-01-26 10:27:35 +00:00
|
|
|
|
2022-06-20 15:53:20 +00:00
|
|
|
return $this->expressionBuilder->in($x, $y);
|
2016-01-26 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function notIn($x, $y, $type = null): string {
|
2016-01-26 11:07:23 +00:00
|
|
|
$x = $this->prepareColumn($x, $type);
|
|
|
|
$y = $this->prepareColumn($y, $type);
|
2016-01-26 10:27:35 +00:00
|
|
|
|
2022-06-20 15:53:20 +00:00
|
|
|
return $this->expressionBuilder->notIn($x, $y);
|
2016-01-26 10:27:35 +00:00
|
|
|
}
|
2016-02-05 14:32:34 +00:00
|
|
|
|
2017-07-25 13:34:59 +00:00
|
|
|
/**
|
|
|
|
* Creates a $x = '' statement, because Oracle needs a different check
|
|
|
|
*
|
2021-02-15 15:36:20 +00:00
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
|
2022-06-20 15:53:20 +00:00
|
|
|
* @return string
|
2017-07-25 13:34:59 +00:00
|
|
|
* @since 13.0.0
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function emptyString($x): string {
|
2017-07-25 13:34:59 +00:00
|
|
|
return $this->isNull($x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a `$x <> ''` statement, because Oracle needs a different check
|
|
|
|
*
|
2021-02-15 15:36:20 +00:00
|
|
|
* @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
|
2022-06-20 15:53:20 +00:00
|
|
|
* @return string
|
2017-07-25 13:34:59 +00:00
|
|
|
* @since 13.0.0
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function nonEmptyString($x): string {
|
2017-07-25 13:34:59 +00:00
|
|
|
return $this->isNotNull($x);
|
|
|
|
}
|
|
|
|
|
2016-02-05 14:32:34 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2016-02-05 14:32:34 +00:00
|
|
|
* @return IQueryFunction
|
|
|
|
*/
|
2021-07-07 12:20:24 +00:00
|
|
|
public function castColumn($column, $type): IQueryFunction {
|
2016-02-05 14:32:34 +00:00
|
|
|
if ($type === IQueryBuilder::PARAM_STR) {
|
|
|
|
$column = $this->helper->quoteColumnName($column);
|
|
|
|
return new QueryFunction('to_char(' . $column . ')');
|
|
|
|
}
|
2020-11-05 09:50:21 +00:00
|
|
|
if ($type === IQueryBuilder::PARAM_INT) {
|
|
|
|
$column = $this->helper->quoteColumnName($column);
|
|
|
|
return new QueryFunction('to_number(to_char(' . $column . '))');
|
|
|
|
}
|
2016-02-05 14:32:34 +00:00
|
|
|
|
|
|
|
return parent::castColumn($column, $type);
|
|
|
|
}
|
2016-02-22 18:46:37 +00:00
|
|
|
|
2017-01-16 14:12:30 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-06-20 15:53:20 +00:00
|
|
|
public function like($x, $y, $type = null): string {
|
|
|
|
return parent::like($x, $y, $type) . " ESCAPE '\\'";
|
2017-01-16 14:12:30 +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 {
|
2020-11-06 14:31:28 +00:00
|
|
|
return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));
|
2016-02-22 18:46:37 +00:00
|
|
|
}
|
2016-01-18 15:03:41 +00:00
|
|
|
}
|