预期的Doctrine \ ORM \ Query \ Lexer :: T_CLOSE_PARENTHESIS,得到','

时间:2014-12-03 14:05:26

标签: symfony doctrine-orm dql

关于Doctrine和来自Oro Doctrine Extensions库的TIMESTAMPDIFF函数。

一些代码:

    $qb = $em->createQueryBuilder();
    $totalLogedTime  = $qb
                ->select('SUM(TIMESTAMPDIFF(MINUTE, ulr.logedIn, ulr.logedOut)) as sum')
                ->from('SDUserBundle:UserLoginRecord', 'ulr')
                ->where ...

config.yml

            dql:
                string_functions:
                    array_to_string: ITDoors\CommonBundle\DQL\ArrayToStringDQL
                    array: ITDoors\CommonBundle\DQL\ArrayDQL
                    select_next_handling_message_date: SD\CommonBundle\DQL\SelectNextHandlingMessageDateDQL
                    cast: Oro\ORM\Query\AST\Functions\Cast
                datetime_functions:
                    date:  Oro\ORM\Query\AST\Functions\SimpleFunction
                numeric_functions:
                    dayofyear: Oro\ORM\Query\AST\Functions\SimpleFunction
                    year: Oro\ORM\Query\AST\Functions\SimpleFunction
                    month: Oro\ORM\Query\AST\Functions\SimpleFunction
                    day: Oro\ORM\Query\AST\Functions\SimpleFunction
                    timestampdiff: Oro\ORM\Query\AST\Functions\SimpleFunction
                    date: Oro\ORM\Query\AST\Functions\SimpleFunction

错误:

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

DQL:

SELECT SUM(TIMESTAMPDIFF(MINUTE, ulr.logedIn, ulr.logedOut)) FROM SDUserBundle:UserLoginRecord ulr WHERE ulr.user_id = 353 AND ulr.logedIn > :start AND ulr.logedOut < :end
                               ^ - col 31

出了什么问题?感谢。

1 个答案:

答案 0 :(得分:1)

您的timestampdiff配置声明不正确。您必须改为使用此参数,as per the README

doctrine:
    orm:
        dql:
            numeric_functions:
                timestampdiff:  Oro\ORM\Query\AST\Functions\Numeric\TimestampDiff

错误消息期望结束)括号的原因是因为SimpleFunction是单参数函数并且不接受多个参数,所以,(逗号)是没想到。