mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
CaseExpression as first parameter of LikeExpression not working as intended #6656
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MassimoDeFacciZucchettiSWGiuridico on GitHub (Mar 22, 2021).
Bug report
Short Explanation:
Inside a WhereClause, having a LikeExpression which the first term of is a CaseExpression invokes the error "Expected =, <, <=, <>, >, >=, !=, got 'LIKE'"
Long Explanation
I want to start using doctrine in a big program I'm working on, as it would make development time faster. To test it I tried converting a complex query I'm using to its doctrine orm implementation. This query is build based on a lot of parameters, but in this specific part it invokes an error.
What I need to do is, when some conditions are met, do a series of leftjoins and then apply a where clause, which like compares different parameters based on a value. To do that in the original sql query I used a WHERE clause, inside of which I used an IF condition, that would form the first parameter of the like comparison, like this simplified example:
I converted that sql code into this doctrine one:
When I do that tho, I get the error "Expected =, <, <=, <>, >, >=, !=, got 'LIKE'", which disappears if instead of using a like comparison I just use an equal operator. This doesnt make sense if we follow what's written in this page: here
in fact, following that same page definition, we know that there is a WhereClause, which only contains a ConditionalExpression. The ConditionalExpression its just a LikeExpression, the second term of which is just a string, while the first one is a StringExpression, a StringPrimary which is a CaseExpression.
I tried modifying the form of the code in various ways, like having the CaseExpression hold the LikeExpression inside of it's results, but to no success.
Summary
Let a WhereClause have a LikeExpression in which the first term is defined by a CaseExpression, as intended by documentation in this page: here
How to reproduce
this is a simplified version of the incriminated code
@MassimoDeFacciZucchettiSWGiuridico commented on GitHub (Mar 23, 2021):
Small update:
I was able to avoid this problem by writing a query that gives the same results, but is less optimized. I still think this bug should be fixed, since it goes against the expected behaviour defined in the reference page.
If anyone is curious about the query I used, this is a simplified version of it: