Browse Source

Add bitwise AND and OR to the expression builder

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v12.0.0beta1
Joas Schilling 7 years ago
parent
commit
4128a08333
No account linked to committer's email address

+ 37
- 1
lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php View File

@@ -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);
}
@@ -344,13 +350,43 @@ class ExpressionBuilder implements IExpressionBuilder {
return $this->expressionBuilder->notIn($x, $y);
}

/**
* 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));

+ 21
- 0
lib/public/DB/QueryBuilder/IExpressionBuilder.php View File

@@ -305,6 +305,27 @@ interface IExpressionBuilder {
*/
public function notIn($x, $y, $type = null);


/**
* Creates a bitwise AND comparison
*
* @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);

/**
* Creates a bitwise OR comparison
*
* @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);

/**
* Quotes a given input parameter.
*

Loading…
Cancel
Save