Introduce helper method
This commit is contained in:
parent
7514695399
commit
a0e8a9de61
1 changed files with 34 additions and 99 deletions
|
@ -21,27 +21,34 @@
|
|||
|
||||
namespace OC\DB\QueryBuilder;
|
||||
|
||||
|
||||
use OCP\DB\QueryBuilder\ILiteral;
|
||||
use OCP\DB\QueryBuilder\IParameter;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class OCIExpressionBuilder extends ExpressionBuilder {
|
||||
|
||||
/**
|
||||
* @param mixed $column
|
||||
* @param mixed|null $type
|
||||
* @return array|QueryFunction|string
|
||||
*/
|
||||
protected function prepareColumn($column, $type) {
|
||||
if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
|
||||
$column = $this->helper->quoteColumnName($column);
|
||||
$column = new QueryFunction('to_char(' . $column . ')');
|
||||
} else {
|
||||
$column = $this->helper->quoteColumnNames($column);
|
||||
}
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function comparison($x, $operator, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->comparison($x, $operator, $y);
|
||||
}
|
||||
|
@ -50,17 +57,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function eq($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->eq($x, $y);
|
||||
}
|
||||
|
@ -69,17 +67,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function neq($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->neq($x, $y);
|
||||
}
|
||||
|
@ -88,17 +77,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function lt($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->lt($x, $y);
|
||||
}
|
||||
|
@ -107,17 +87,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function lte($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->lte($x, $y);
|
||||
}
|
||||
|
@ -126,17 +97,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function gt($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->gt($x, $y);
|
||||
}
|
||||
|
@ -145,17 +107,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function gte($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->gte($x, $y);
|
||||
}
|
||||
|
@ -164,17 +117,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function in($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !is_array($y) && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnNames($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->in($x, $y);
|
||||
}
|
||||
|
@ -183,17 +127,8 @@ class OCIExpressionBuilder extends ExpressionBuilder {
|
|||
* @inheritdoc
|
||||
*/
|
||||
public function notIn($x, $y, $type = null) {
|
||||
$x = $this->helper->quoteColumnName($x);
|
||||
if ($type === IQueryBuilder::PARAM_STR) {
|
||||
$x = new QueryFunction('to_char(' . $x . ')');
|
||||
}
|
||||
|
||||
if ($type === IQueryBuilder::PARAM_STR && !is_array($y) && !($y instanceof IParameter) && !($y instanceof ILiteral)) {
|
||||
$y = $this->helper->quoteColumnName($y);
|
||||
$y = new QueryFunction('to_char(' . $y . ')');
|
||||
} else {
|
||||
$y = $this->helper->quoteColumnNames($y);
|
||||
}
|
||||
$x = $this->prepareColumn($x, $type);
|
||||
$y = $this->prepareColumn($y, $type);
|
||||
|
||||
return $this->expressionBuilder->notIn($x, $y);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue