0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-28 10:33:43 +00:00
nextcloud_server/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.9 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* 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;
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
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
}
return parent::prepareColumn($column, $type);
2016-01-26 10:27:35 +00:00
}
/**
* @inheritdoc
*/
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
return $this->expressionBuilder->in($x, $y);
2016-01-26 10:27:35 +00:00
}
/**
* @inheritdoc
*/
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
return $this->expressionBuilder->notIn($x, $y);
2016-01-26 10:27:35 +00:00
}
2016-02-05 14:32:34 +00:00
/**
* Creates a $x = '' statement, because Oracle needs a different check
*
* @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function emptyString($x): string {
return $this->isNull($x);
}
/**
* Creates a `$x <> ''` statement, because Oracle needs a different check
*
* @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison.
* @return string
* @since 13.0.0
*/
public function nonEmptyString($x): string {
return $this->isNotNull($x);
}
2016-02-05 14:32:34 +00:00
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string|IQueryFunction $column
2016-02-05 14:32:34 +00:00
* @param mixed $type One of IQueryBuilder::PARAM_*
* @psalm-param IQueryBuilder::PARAM_* $type
2016-02-05 14:32:34 +00:00
* @return IQueryFunction
*/
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 . ')');
}
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
/**
* @inheritdoc
*/
public function like($x, $y, $type = null): string {
return parent::like($x, $y, $type) . " ESCAPE '\\'";
}
2016-02-22 18:46:37 +00:00
/**
* @inheritdoc
*/
public function iLike($x, $y, $type = null): string {
return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));
2016-02-22 18:46:37 +00:00
}
}