Le mardi 24 janvier 2017 11:21:24 UTC+1, Marco Pivetta a écrit : > > INTERVAL 1 WEEK doesn't parse in DQL. See > https://github.com/doctrine/doctrine2/blob/b181228d69a78372693ee0f3dd2285e0e3771bca/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php#L28 > > Also, please note that you just select `a`, not `a.*`. >
Ok, Actually I tried by 'DAY' => `WEEK_NUMBER(DATE_SUB(a.createdAt , 7, DAY)` sorry for the typo error :/ > > > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > On Tue, Jan 24, 2017 at 10:49 AM, Abir BRAHEM <[email protected] > <javascript:>> wrote: > >> Thank you for your reply @Marco, please find all details below: >> >> My expected SQL: >> >> SELECT a.* >> FROM my_table a >> WHERE WEEK(DATE_SUB(a.createdAt, INTERVAL 1 WEEK)) = >> WEEK(DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK)) >> >> My Current DQL: >> >> SELECT a.* >> FROM MyBundle:MyEntity a >> WHERE WEEK_NUMBER(DATE_SUB(a.createdAt, INTERVAL 1 WEEK)) = >> WEEK(DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK)) >> >> >> My custom DQL function `WEEK_NUMBER`: >> >> ``` >> class WeekNumber extends FunctionNode >> { >> /** >> * @var AggregateExpression| >> FunctionNode|InputParameter|string >> */ >> public $dateTimeExpression = null; >> >> /** >> * {@inheritdoc} >> */ >> public function parse(Parser $parser) >> { >> $parser->match(Lexer::T_IDENTIFIER); >> $parser->match(Lexer::T_OPEN_PARENTHESIS); >> >> $this->dateTimeExpression = $parser->ArithmeticPrimary(); >> >> >> $parser->match(Lexer::T_CLOSE_PARENTHESIS); >> } >> >> /** >> * {@inheritdoc} >> */ >> public function getSql(SqlWalker $sqlWalker) >> { >> return 'WEEK(' . >> $this->dateTimeExpression->dispatch($sqlWalker) >> . ')'; >> } >> >> >> Error Message: >> Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Syntax Error] >> line 0, col 134: Error: Expected '.' or '(', got 'DAY'" .. >> I am nout sure, may be the `ArithmeticPrimary()` does not support `DATE_SUB` >> expression as argument to `WEEK_NUMBER`. >> >> Thank you, >> >> Le mardi 24 janvier 2017 00:34:12 UTC+1, Marco Pivetta a écrit : >>> >>> ` "[Syntax Error] line 0, col 134` >>> >>> Please provide: >>> >>> * your DQL >>> * your expected SQL >>> >>> Also, I would strongly suggest to write an integration test relying on >>> the DQL parser ;-) >>> >>> Marco Pivetta >>> >>> http://twitter.com/Ocramius >>> >>> http://ocramius.github.com/ >>> >>> On Mon, Jan 23, 2017 at 12:17 PM, Abir BRAHEM <[email protected]> >>> wrote: >>> >>>> Hello, >>>> >>>> I need to translate `WEEK(DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK))` >>>> to DQL: >>>> >>>> It looks like this for the moment: `WEEK_NUMBER(DATE_SUB(my_var , 7, >>>> DAY) ` >>>> >>>> ``` >>>> class WeekNumber extends FunctionNode >>>> { >>>> /** >>>> * @var AggregateExpression|FunctionNode|InputParameter|string >>>> */ >>>> public $dateTimeExpression = null; >>>> >>>> /** >>>> * {@inheritdoc} >>>> */ >>>> public function parse(Parser $parser) >>>> { >>>> $parser->match(Lexer::T_IDENTIFIER); >>>> $parser->match(Lexer::T_OPEN_PARENTHESIS); >>>> >>>> $this->dateTimeExpression = $parser->ArithmeticPrimary(); >>>> >>>> >>>> $parser->match(Lexer::T_CLOSE_PARENTHESIS); >>>> } >>>> >>>> /** >>>> * {@inheritdoc} >>>> */ >>>> public function getSql(SqlWalker $sqlWalker) >>>> { >>>> return 'WEEK(' . >>>> $this->dateTimeExpression->dispatch($sqlWalker) >>>> . ')'; >>>> } >>>> >>>> >>>> => It generates me an error: Uncaught PHP Exception >>>> Doctrine\ORM\Query\QueryException: "[Syntax Error] line 0, col 134: Error: >>>> Expected '.' or '(', got 'DAY'" .. >>>> Seems like `ArithmeticPrimary()` does'nt support `DATE_SUB` expression >>>> :S >>>> >>>> Any help please! >>>> >>>> Thanks, >>>> >>>> >>>> >>>> -- >>>> 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 https://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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://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 https://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
