i try to add my custom sql function.
my function is like this :
DISTANCE( 15.154454, 5.121444, -15.321111, 15.12111)
I add this parser for parse it :
use Doctrine\ORM\Query\Lexer;
class Distance extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
{
public $lat_a = null;
public $lat_b = null;
public $lon_a = null;
public $lon_b = null;
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->lat_a = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->lon_a = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->lat_b = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->lon_b = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'DISTANCE(' .
$this->lat_a->dispatch($sqlWalker) . ', ' .
$this->lon_a->dispatch($sqlWalker) . ', ' .
$this->lat_b->dispatch($sqlWalker) . ', ' .
$this->lon_b->dispatch($sqlWalker) .
')';
}
}
It's ok, this work fine but when i use negative var like "-15.321111", i get an error 500... With positive var, all it's ok.
Anyone can help me for parse negative var ?