Saturday 15 February 2014

oracle - doctrine 2 where condition without comparison -



oracle - doctrine 2 where condition without comparison -

i have written custom function dql:

<?php namespace bundle\dql\functions; utilize doctrine\orm\query\ast\functions\functionnode; utilize doctrine\orm\query\lexer; utilize doctrine\orm\query\sqlwalker; utilize doctrine\orm\query\parser; /** * "date_compare" "(" arithmeticprimary "," comparisonoperator "," arithmeticprimary ")" */ class datecomparefunction extends functionnode { public $date1; public $date2; public $operator; /** * @override * @param sqlwalker $sqlwalker * @return string * @throws \doctrine\dbal\dbalexception */ public function getsql(sqlwalker $sqlwalker) { homecoming sprintf( 'trunc(%s) %s trunc(%s)', $this->date1->dispatch($sqlwalker), $this->operator, $this->date2->dispatch($sqlwalker) ); } /** * @override * @param parser $parser */ public function parse(parser $parser) { $parser->match(lexer::t_identifier); $parser->match(lexer::t_open_parenthesis); $this->date1 = $parser->arithmeticprimary(); $parser->match(lexer::t_comma); $this->operator = $parser->comparisonoperator(); $parser->match(lexer::t_comma); $this->date2 = $parser->arithmeticprimary(); $parser->match(lexer::t_close_parenthesis); } }

and stmt looks this:

$query = $em->createquerybuilder() ->select('evt') ->from('application\model\event', 'evt') ->where('evt.usr_id in (:uid)') ->setparameter('uid', $usersid); if (null !== $from) { $query->andwhere('date_compare(evt.day, >, to_date(:from, \'yyyy-mm-dd\'))') ->setparameter('from', $from);

the problem doctrine raise exception having where statement without comparing symbol:

object(doctrine\orm\query\queryexception)[347] protected 'message' => string '[syntax error] line 0, col 130: error: expected =, <, <=, <>, >, >=, !=, got ')'' (length=80) private 'string' (exception) => string '' (length=0) protected 'code' => int 0 protected 'file' => string 'c:\workspace\app\hcalendar\vendor\doctrine\orm\lib\doctrine\orm\query\queryexception.php' (length=88) protected 'line' => int 52 private 'trace' (exception) =>

i have tried adding stmt = true, generated statement isn't understood oracle, hwo can statement without comparing symbol ? (just true/false function return)

why need function? can status without custom function, write:

$query->andwhere('evt.day > :from')->setparameter('from', $from);

where variable $from should datetime object, , if want oracle trunc function can implement self in here https://github.com/zeineddin/zedoctrineextensions/blob/master/lib/zedoctrineextensions/query/oracle/truncdate.php , utilize this:

$query->andwhere('trunc(evt.day) > :from')->setparameter('from', $from);

if want can install this module zf2 project , have truncdate function ready used in project

oracle doctrine2 dql

No comments:

Post a Comment