diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-26 11:27:35 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-26 14:56:07 +0100 |
commit | 751469539916a3b81f4d6a0bf29c848e951e70d8 (patch) | |
tree | d177e580aa96c0df9aee833d06966c311f9e1f94 /lib | |
parent | bd444ae3c3d65c7c758d478d99a2e079d3330023 (diff) | |
download | nextcloud-server-751469539916a3b81f4d6a0bf29c848e951e70d8.tar.gz nextcloud-server-751469539916a3b81f4d6a0bf29c848e951e70d8.zip |
Fix Oracle comparisons
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/db/querybuilder/expressionbuilder.php | 46 | ||||
-rw-r--r-- | lib/private/db/querybuilder/ociexpressionbuilder.php | 167 | ||||
-rw-r--r-- | lib/public/db/querybuilder/iexpressionbuilder.php | 98 |
3 files changed, 272 insertions, 39 deletions
diff --git a/lib/private/db/querybuilder/expressionbuilder.php b/lib/private/db/querybuilder/expressionbuilder.php index a4621da1a4e..b688ebfabbe 100644 --- a/lib/private/db/querybuilder/expressionbuilder.php +++ b/lib/private/db/querybuilder/expressionbuilder.php @@ -86,12 +86,14 @@ class ExpressionBuilder implements IExpressionBuilder { * Creates a comparison expression. * * @param mixed $x The left expression. - * @param string $operator One of the ExpressionBuilder::* constants. + * @param string $operator One of the IExpressionBuilder::* constants. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function comparison($x, $operator, $y) { + public function comparison($x, $operator, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->comparison($x, $operator, $y); @@ -109,7 +111,7 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. - * @param int|null $type one of the IQueryBuilder::PARAM_* constants + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * * @return string @@ -131,10 +133,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function neq($x, $y) { + public function neq($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->neq($x, $y); @@ -151,10 +155,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function lt($x, $y) { + public function lt($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->lt($x, $y); @@ -171,10 +177,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function lte($x, $y) { + public function lte($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->lte($x, $y); @@ -191,10 +199,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function gt($x, $y) { + public function gt($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->gt($x, $y); @@ -211,10 +221,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function gte($x, $y) { + public function gte($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->gte($x, $y); @@ -249,10 +261,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string $x Field in string format to be inspected by LIKE() comparison. * @param mixed $y Argument to be used in LIKE() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function like($x, $y) { + public function like($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->like($x, $y); @@ -263,10 +277,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string $x Field in string format to be inspected by NOT LIKE() comparison. * @param mixed $y Argument to be used in NOT LIKE() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function notLike($x, $y) { + public function notLike($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->notLike($x, $y); @@ -277,10 +293,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string $x The field in string format to be inspected by IN() comparison. * @param string|array $y The placeholder or the array of values to be used by IN() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function in($x, $y) { + public function in($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnNames($y); return $this->expressionBuilder->in($x, $y); @@ -291,10 +309,12 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string $x The field in string format to be inspected by NOT IN() comparison. * @param string|array $y The placeholder or the array of values to be used by NOT IN() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string */ - public function notIn($x, $y) { + public function notIn($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnNames($y); return $this->expressionBuilder->notIn($x, $y); @@ -304,7 +324,7 @@ class ExpressionBuilder implements IExpressionBuilder { * Quotes a given input parameter. * * @param mixed $input The parameter to be quoted. - * @param string|null $type The type of the parameter. + * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants * * @return Literal */ diff --git a/lib/private/db/querybuilder/ociexpressionbuilder.php b/lib/private/db/querybuilder/ociexpressionbuilder.php index 62cb5aa62ad..59ac90e2b13 100644 --- a/lib/private/db/querybuilder/ociexpressionbuilder.php +++ b/lib/private/db/querybuilder/ociexpressionbuilder.php @@ -21,15 +21,180 @@ namespace OC\DB\QueryBuilder; +use OCP\DB\QueryBuilder\ILiteral; +use OCP\DB\QueryBuilder\IParameter; use OCP\DB\QueryBuilder\IQueryBuilder; class OCIExpressionBuilder extends ExpressionBuilder { + + /** + * @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); + } + + return $this->expressionBuilder->comparison($x, $operator, $y); + } + + /** + * @inheritdoc + */ public function eq($x, $y, $type = null) { $x = $this->helper->quoteColumnName($x); - $y = $this->helper->quoteColumnName($y); 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); + } + return $this->expressionBuilder->eq($x, $y); } + + /** + * @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); + } + + return $this->expressionBuilder->neq($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->lt($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->lte($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->gt($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->gte($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->in($x, $y); + } + + /** + * @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); + } + + return $this->expressionBuilder->notIn($x, $y); + } } diff --git a/lib/public/db/querybuilder/iexpressionbuilder.php b/lib/public/db/querybuilder/iexpressionbuilder.php index 6163680c126..a53ae3846c2 100644 --- a/lib/public/db/querybuilder/iexpressionbuilder.php +++ b/lib/public/db/querybuilder/iexpressionbuilder.php @@ -21,12 +21,40 @@ namespace OCP\DB\QueryBuilder; + +use Doctrine\DBAL\Query\Expression\ExpressionBuilder; + /** * This class provides a wrapper around Doctrine's ExpressionBuilder * @since 8.2.0 */ interface IExpressionBuilder { /** + * @since 9.0.0 + */ + const EQ = ExpressionBuilder::EQ; + /** + * @since 9.0.0 + */ + const NEQ = ExpressionBuilder::NEQ; + /** + * @since 9.0.0 + */ + const LT = ExpressionBuilder::LT; + /** + * @since 9.0.0 + */ + const LTE = ExpressionBuilder::LTE; + /** + * @since 9.0.0 + */ + const GT = ExpressionBuilder::GT; + /** + * @since 9.0.0 + */ + const GTE = ExpressionBuilder::GTE; + + /** * Creates a conjunction of the given boolean expressions. * * Example: @@ -64,13 +92,15 @@ interface IExpressionBuilder { * Creates a comparison expression. * * @param mixed $x The left expression. - * @param string $operator One of the ExpressionBuilder::* constants. + * @param string $operator One of the IExpressionBuilder::* constants. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function comparison($x, $operator, $y); + public function comparison($x, $operator, $y, $type = null); /** * Creates an equality comparison expression with the given arguments. @@ -84,11 +114,11 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. - * @param int|null $type @since 9.0.0 one of the IQueryBuilder::PARAM_* constants - * required when comparing text fields for oci compatibility. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ public function eq($x, $y, $type = null); @@ -103,11 +133,13 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function neq($x, $y); + public function neq($x, $y, $type = null); /** * Creates a lower-than comparison expression with the given arguments. @@ -120,11 +152,13 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function lt($x, $y); + public function lt($x, $y, $type = null); /** * Creates a lower-than-equal comparison expression with the given arguments. @@ -137,11 +171,13 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function lte($x, $y); + public function lte($x, $y, $type = null); /** * Creates a greater-than comparison expression with the given arguments. @@ -154,11 +190,13 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function gt($x, $y); + public function gt($x, $y, $type = null); /** * Creates a greater-than-equal comparison expression with the given arguments. @@ -171,11 +209,13 @@ interface IExpressionBuilder { * * @param mixed $x The left expression. * @param mixed $y The right expression. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function gte($x, $y); + public function gte($x, $y, $type = null); /** * Creates an IS NULL expression with the given arguments. @@ -202,50 +242,58 @@ interface IExpressionBuilder { * * @param string $x Field in string format to be inspected by LIKE() comparison. * @param mixed $y Argument to be used in LIKE() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function like($x, $y); + public function like($x, $y, $type = null); /** * Creates a NOT LIKE() comparison expression with the given arguments. * * @param string $x Field in string format to be inspected by NOT LIKE() comparison. * @param mixed $y Argument to be used in NOT LIKE() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function notLike($x, $y); + public function notLike($x, $y, $type = null); /** * Creates a IN () comparison expression with the given arguments. * * @param string $x The field in string format to be inspected by IN() comparison. * @param string|array $y The placeholder or the array of values to be used by IN() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function in($x, $y); + public function in($x, $y, $type = null); /** * Creates a NOT IN () comparison expression with the given arguments. * * @param string $x The field in string format to be inspected by NOT IN() comparison. * @param string|array $y The placeholder or the array of values to be used by NOT IN() comparison. + * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants + * required when comparing text fields for oci compatibility * * @return string - * @since 8.2.0 + * @since 8.2.0 - Parameter $type was added in 9.0.0 */ - public function notIn($x, $y); + public function notIn($x, $y, $type = null); /** * Quotes a given input parameter. * * @param mixed $input The parameter to be quoted. - * @param string|null $type The type of the parameter. + * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants * * @return string * @since 8.2.0 |