Hey Diogo,

I'd suggest you to check:

 - merged configuration (via `$sm->get('Config')`)
 - if those classes can be autoloaded

I don't see any particular mistakes. Does the ACOS function work? Are you
using DoctrineORMModule 0.8.x?

Cheers,

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 16 March 2014 13:03, Diogo Domanski <[email protected]> wrote:

> Hi all,
>
> I need to use some MySQL functions (MONTH, YEAR, SIN, ACOS, etc) in
> Doctrine2 through DQL. What I've done until now was the following (but it
> didn't work):
>
> 1. I've created a class for the MySQL function I want to use (for
> instance, ACOS):
>
> namespace MOBBase\Doctrine\ORM\Query\AST\Functions;
>
> use Doctrine\ORM\Query\AST\Functions\FunctionNode,
>     Doctrine\ORM\Query\Lexer;
>
> class Acos extends FunctionNode {
>
>     public $arithmeticExpression;
>
>     public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
>
>         return 'ACOS(' . $sqlWalker->walkSimpleArithmeticExpression(
>                         $this->arithmeticExpression
>                 ) . ')';
>     }
>
>     public function parse(\Doctrine\ORM\Query\Parser $parser) {
>
>         $lexer = $parser->getLexer();
>
>         $parser->match(Lexer::T_IDENTIFIER);
>         $parser->match(Lexer::T_OPEN_PARENTHESIS);
>
>         $this->arithmeticExpression =
> $parser->SimpleArithmeticExpression();
>
>         $parser->match(Lexer::T_CLOSE_PARENTHESIS);
>     }
> }
>
> 2. I've referenced this class in config/autoload/doctrine_orm.local.php:
>
> return array(
>     'doctrine' => array(
>         'configuration' => array(
>             'orm_default' => array(
>                 'datetime_functions' => array(
>                     'Month' =>
> 'MOBBase\Doctrine\ORM\Query\AST\Functions\Month'
>                 ),
>                 'numeric_functions' => array(
>                     'ACOS' =>
> 'MOBBase\Doctrine\ORM\Query\AST\Functions\Acos'
>                 )
>             )
>         ),
>     ...
>
> 3. I've created a DQL query that uses the custom function. However, when
> it is executed, Doctrine triggers the following error:
>
> [Syntax Error] line 0, col 150: Error: Expected known function, got 'MONTH'
>
>
> Does anyone know how to correctly setup a custom MySQL function in
> Doctrine2 + ZF2?
>
> Thanks in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to