diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-05 11:45:10 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-01-05 14:30:25 +0100 |
commit | 4128a08333746638e7a872ca89f1431cae68161d (patch) | |
tree | 0e7fad7d5d30c040a37e39e0fa1126bb5be476fe /lib/private/DB | |
parent | 5d01004368c4b1a3898831955fac58a86184af5a (diff) | |
download | nextcloud-server-4128a08333746638e7a872ca89f1431cae68161d.tar.gz nextcloud-server-4128a08333746638e7a872ca89f1431cae68161d.zip |
Add bitwise AND and OR to the expression builder
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/DB')
-rw-r--r-- | lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php index f9170e97a02..f172260df79 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php @@ -30,6 +30,8 @@ use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\QueryFunction; use OC\DB\QueryBuilder\QuoteHelper; use OCP\DB\QueryBuilder\IExpressionBuilder; +use OCP\DB\QueryBuilder\ILiteral; +use OCP\DB\QueryBuilder\IQueryFunction; use OCP\IDBConnection; class ExpressionBuilder implements IExpressionBuilder { @@ -39,12 +41,16 @@ class ExpressionBuilder implements IExpressionBuilder { /** @var QuoteHelper */ protected $helper; + /** @var IDBConnection */ + protected $connection; + /** * Initializes a new <tt>ExpressionBuilder</tt>. * * @param \OCP\IDBConnection $connection */ public function __construct(IDBConnection $connection) { + $this->connection = $connection; $this->helper = new QuoteHelper(); $this->expressionBuilder = new DoctrineExpressionBuilder($connection); } @@ -345,12 +351,42 @@ class ExpressionBuilder implements IExpressionBuilder { } /** + * Binary AND Operator copies a bit to the result if it exists in both operands. + * + * @param string|ILiteral $x The field or value to check + * @param int $y Bitmap that must be set + * @return IQueryFunction + * @since 12.0.0 + */ + public function bitwiseAnd($x, $y) { + return new QueryFunction($this->connection->getDatabasePlatform()->getBitAndComparisonExpression( + $this->helper->quoteColumnName($x), + $y + )); + } + + /** + * Binary OR Operator copies a bit if it exists in either operand. + * + * @param string|ILiteral $x The field or value to check + * @param int $y Bitmap that must be set + * @return IQueryFunction + * @since 12.0.0 + */ + public function bitwiseOr($x, $y) { + return new QueryFunction($this->connection->getDatabasePlatform()->getBitOrComparisonExpression( + $this->helper->quoteColumnName($x), + $y + )); + } + + /** * Quotes a given input parameter. * * @param mixed $input The parameter to be quoted. * @param mixed|null $type One of the IQueryBuilder::PARAM_* constants * - * @return Literal + * @return ILiteral */ public function literal($input, $type = null) { return new Literal($this->expressionBuilder->literal($input, $type)); |