Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine Query Builder mysql Functions

im atempting to create one of my old mysql queries in Doctrine Query Builder however im getting back an error Error: Expected known function, got 'SEC_TO_TIME'

So im guessing that doctrine doesnt like the mysql function SEC_TO_TIME however it does seem to like AVG, COUNT and such. Is there any way apart form using the Doctrine_RawSQL class of getting the query builder to run the query?

Thanks

like image 887
Lee Avatar asked May 18 '11 14:05

Lee


1 Answers

i know this question is very old, but i am answering this question for others who having same error.
you just need to add below code in form of file Named "SecToTime.php" as below path.

YourProjectName\libraries\Doctrine\DoctrineExtensions\Query\MySql\SecToTime.php

And put below code in above file Named "SecToTime.php".

<?php

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode,
    Doctrine\ORM\Query\Lexer;

class SecToTime extends FunctionNode {

    public $time;

    /**
     * @override
     */
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
        return 'SEC_TO_TIME(' . $sqlWalker->walkArithmeticPrimary($this->time) . ')';
    }

    /**
     * @override
     */
    public function parse(\Doctrine\ORM\Query\Parser $parser) {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->time = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }

}

you need to add above file name in your doctrine.php file for using it further. i hope you know how to add it.

If you having any query, feel free to ask.

like image 189
Amit Joshi Avatar answered Sep 28 '22 19:09

Amit Joshi