diff --git a/src/Query/Mysql/Format.php b/src/Query/Mysql/Format.php index a861c97c..da17c065 100644 --- a/src/Query/Mysql/Format.php +++ b/src/Query/Mysql/Format.php @@ -4,9 +4,10 @@ use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\QueryException; /** - * @author Wally Noveno + * @author Marek Karmelski */ class Format extends FunctionNode { @@ -14,6 +15,8 @@ class Format extends FunctionNode public $patternExpression = null; + public $optionalLocaleExpression = null; + public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); @@ -21,6 +24,13 @@ public function parse(\Doctrine\ORM\Query\Parser $parser) $this->numberExpression = $parser->SimpleArithmeticExpression(); $parser->match(Lexer::T_COMMA); $this->patternExpression = $parser->SimpleArithmeticExpression(); + + $lexer = $parser->getLexer(); + if ($lexer->isNextToken(Lexer::T_COMMA)) { + $parser->match(Lexer::T_COMMA); + $this->optionalLocaleExpression = $parser->StringExpression(); + } + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } @@ -29,6 +39,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) return 'FORMAT(' . $this->numberExpression->dispatch($sqlWalker) . ', ' . $this->patternExpression->dispatch($sqlWalker) . - ')'; + (($this->optionalLocaleExpression) ? ', ' . $this->optionalLocaleExpression->dispatch($sqlWalker) : '') . + ')'; } -} +} \ No newline at end of file