diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-26 12:07:23 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-26 14:56:07 +0100 |
commit | a0e8a9de612abb0fd5f147d33e69c774d54e5f29 (patch) | |
tree | 3b8d380804fe4d226d307cae11413c0c77e0db59 /lib/private/db | |
parent | 751469539916a3b81f4d6a0bf29c848e951e70d8 (diff) | |
download | nextcloud-server-a0e8a9de612abb0fd5f147d33e69c774d54e5f29.tar.gz nextcloud-server-a0e8a9de612abb0fd5f147d33e69c774d54e5f29.zip |
Introduce helper method
Diffstat (limited to 'lib/private/db')
-rw-r--r-- | lib/private/db/querybuilder/ociexpressionbuilder.php | 133 |
1 files changed, 34 insertions, 99 deletions
diff --git a/lib/private/db/querybuilder/ociexpressionbuilder.php b/lib/private/db/querybuilder/ociexpressionbuilder.php index 59ac90e2b13..4c127bd752d 100644 --- a/lib/private/db/querybuilder/ociexpressionbuilder.php +++ b/lib/private/db/querybuilder/ociexpressionbuilder.php @@ -21,6 +21,7 @@ namespace OC\DB\QueryBuilder; + use OCP\DB\QueryBuilder\ILiteral; use OCP\DB\QueryBuilder\IParameter; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -28,20 +29,26 @@ use OCP\DB\QueryBuilder\IQueryBuilder; class OCIExpressionBuilder extends ExpressionBuilder { /** - * @inheritdoc + * @param mixed $column + * @param mixed|null $type + * @return array|QueryFunction|string */ - 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 . ')'); + 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 { - $y = $this->helper->quoteColumnName($y); + $column = $this->helper->quoteColumnNames($column); } + return $column; + } + + /** + * @inheritdoc + */ + public function comparison($x, $operator, $y, $type = null) { + $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); } |