Query generated using bitwise operations has error in Doctrine
theviniciusmartins opened this issue · 1 comments
I was using this lib and found an error while using it with doctrine. When I do some bitwise spec, the generate query looks like this field & value
, but doctrine doesn't support this format, in fact it should be like BIT_AND(...)
.
My workaround to solve it was to use Spec::fun('BIT_AND', [field, value])
, this error only occurs using Spec with doctrine. A possible solution is to change the operation and format the query that is generated by the Spec. If you want, I can make a pull request.
Thank you for report.
Strange. For some reason, i was sure that the Doctrine supported bitwise operators.
If you want, I can make a pull request.
Yes. If it is not difficult for you.
Need to change the Bitwise class.
XOR (^
) , left shift (<<
) and right shift (>>
) operators not supported in Doctrine and there are no similar functions for them. It is necessary to remove it.
private static $operations = array(
self::B_AND,
self::B_OR,
- self::B_XOR,
- self::B_LS,
- self::B_RS,
);
And do the transformation through the PlatformFunction.
public function transform(QueryBuilder $qb, $dqlAlias)
{
+ $function = $this->operation === self::B_AND ? 'BIT_AND' : 'BIT_OR';
+
+ return (new PlatformFunction($function, $this->field, $this->value))->transform($qb, $dqlAlias);
- $field = ArgumentToOperandConverter::toField($this->field);
- $value = ArgumentToOperandConverter::toValue($this->value);
- $field = $field->transform($qb, $dqlAlias);
- $value = $value->transform($qb, $dqlAlias);
-
- return sprintf('(%s %s %s)', $field, $this->operation, $value);
}
Thanks