From c99b3d3b694c96de5534abe4de2a00086db36884 Mon Sep 17 00:00:00 2001 From: Marek Karmelski Date: Thu, 9 Jun 2022 18:23:39 +0200 Subject: [PATCH] Add optional parameter locale to mysql FORMAT function --- src/Query/Mysql/Format.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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