1
votes

It's about Doctrine and the TIMESTAMPDIFF function from the Oro Doctrine Extensions library.

Some code:

    $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

Error:

    [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

What's wrong? Thanks.

1
can you give us full DQL? - Roman Kliuchko
Run this die($qb->getDql()); so we can see the full DQL or look in your profiler to get the full DQL. What the select function contains is not the same as what the resulting DQL may be - sjagr
The DQL for the query, not the full dql parameters from your config.yml - sjagr
I have an error about to much code in post. What params you need? - Alex

1 Answers

1
votes

Your timestampdiff configuration declaration is incorrect. You must use this parameter instead, as per the README:

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

The reason the error message expects a closing ) bracket is because the SimpleFunction is a one-parameter function and doesn't accept multiple arguments, so a , (comma) is never expected.