mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3364: QueryBuilder fails when using alias in having with like expr #3883
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 @doctrinebot on GitHub (May 21, 2014).
Jira issue originally created by user webdevilopers:
In my select I create an alias. I use a like expr on this alias in the having clause.
Trying several variations I still get the following error:
Expected '.' or '(', got 'long_name'
My example including variations inside comments:
I use a Doctrine Extension for the MySQL GROUP_CONCAT functionality:
https://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/GroupConcat.php
This should have no effect on the result since I tried a simple alias - see comment - instead of it.
The problem seems to be using an alias inside the having clause when adding the like expr.
The following clause would work:
I also tried this workaround using the GROUP_CONCAT method inside the where part:
Allthough I used the groupBy part I got this error:
General error: 1111 Invalid use of group function
@doctrinebot commented on GitHub (Jun 26, 2014):
Comment created by @ocramius:
What is the actual failure/exception type? What about the generated SQL?
@doctrinebot commented on GitHub (Oct 26, 2014):
Comment created by @deeky666:
Moved to ORM, the error and use case is ORM related.
@doctrinebot commented on GitHub (Aug 4, 2015):
Comment created by kryniol:
Same here. It has nothing in common with usage of GROUP_CONCAT. The simpliest example I can think of:
This produces following error (full stacktrace from Symfony2 app):
{quote}
[1] Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 73: Error: Expected '.' or '(', got 'id'
at n/a
in /var/www/myproject/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 52
[2] Doctrine\ORM\Query\QueryException: SELECT b.id AS id FROM MyProject\MyBundle\Entity\MyEntity b HAVING id LIKE foobar
at n/a
in /var/www/myproject/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 41
{quote}
Note that the following example works like a charm:
Has anyone by any chance found any, even temporary workaround for this issue?
@doctrinebot commented on GitHub (Aug 5, 2015):
Comment created by kryniol:
My temp solution is to use custom function which is being resolved to LIKE expression: https://gist.github.com/Kryniol/901255742078bdb8aa1d
And the possible bug is that Doctrine\ORM\Query\Parser::LikeExpression() matches StringExpression instead of ArithmeticExpression (as for the ComparisonExpression) in the first part of LIKE. When changed to ArithmeticExpression in the Parser class itself, my code started working. But I'm not sure what this change could break...
@doctrinebot commented on GitHub (Aug 27, 2015):
Comment created by Raphi:
I have the same issue.
In DQL, it's possible to get around this bug by writing CONCAT in like condition too.
For example :
{quote}SELECT *, CONCAT('', field1, '')
FROM *
GROUP BY ******
HAVING CONCAT('', field1, '') LIKE ******{quote}
Please replace the stars with the right values.
@qferr commented on GitHub (Apr 1, 2016):
Have you fix this bug ? I have the same error. Thank you.
@kimpixel commented on GitHub (Jul 14, 2016):
Hi
This Bug is still present!
The custom like extension from "kryniol" is also not working or i unable to setup it right.
And the workaround from "Raphi" is no option for me (have some auto generated code)
can someone help to get this working?
I am in the Flow 3.0 Framework:
$this->getEntityManager()->getConfiguration()->addCustomStringFunction('like', 'XXX\YYYYY\Doctrine\Functions\Like');@Ocramius commented on GitHub (Jul 15, 2016):
Write a failing test case, then the fix becomes easier to find.
@kimpixel commented on GitHub (Jul 15, 2016):
hi the bug is very simple to reproduce as "kryniol" wrote above
@Ocramius commented on GitHub (Jul 15, 2016):
Yes, which means that it is simple to send a pull request with a failing test case ;-)
@romaricdrigon commented on GitHub (Oct 1, 2019):
I just tried as I was investing #7846, I could not reproduce.