Doctrine FIND_IN_SET leads to Error: Expected end of string, got '('

霸气de小男生 提交于 2019-12-12 03:29:45

问题


I've got the following doctrine query in Symfony2:

$query = $em
    ->createQuery("
        SELECT m FROM MyBackendBundle:Merchant m
        WHERE m.active = :active
        ORDER BY FIND_IN_SET(m.range, 'all', 'without_special'), m.tradingAmount DESC
    ")
    ->setParameter('active', true)
;

But this leads to the following error:

[Syntax Error] line 0, col 112: Error: Expected end of string, got '('

and:

QueryException: 
SELECT m FROM My\Bundle\BackendBundle\Entity\Merchant m 
WHERE m.active = :active 
ORDER BY FIND_IN_SET(m.range, 'all', 'without_special') ASC, m.tradingAmount DESC

I use the FIND_IN_SET doctrine extension from beberlei to be able to use it in the query.

Any ideas why this happens?

Update:

Using the FIND_IN_SET in the SELECT as an alias this way:

SELECT m, FIND_IN_SET(m.range, 'all', 'without_special') AS HIDDEN findInSet
FROM MyBackendBundle:Merchant 
WHERE m.active = :active
ORDER BY findInSet, m.productAmount DESC

results in the following error:

[Syntax Error] line 0, col 56: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','

回答1:


Thanks to the comments of @qooplmao this is the working version:

$query = $em
    ->createQuery("
        SELECT m, FIND_IN_SET(m.range, 'all,without_special') AS rangeOrdering
        FROM MyBackendBundle:Merchant m
        WHERE m.active = :active
        ORDER BY rangeOrdering, m.tradingAmount DESC
    ")
    ->setParameter('active', true)
;

FIND_IN_SET has only two parameters and has to be within the SELECT part of the query as functions can't be used in the ORDER BY part of the query.



来源:https://stackoverflow.com/questions/36246126/doctrine-find-in-set-leads-to-error-expected-end-of-string-got

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!