Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Doctrine2 Symfony2自定义函数解析器_Mysql_Sql_Function_Symfony_Doctrine Orm - Fatal编程技术网

Mysql Doctrine2 Symfony2自定义函数解析器

Mysql Doctrine2 Symfony2自定义函数解析器,mysql,sql,function,symfony,doctrine-orm,Mysql,Sql,Function,Symfony,Doctrine Orm,我尝试添加我的自定义sql函数 我的功能是这样的: DISTANCE( 15.154454, 5.121444, -15.321111, 15.12111) 我添加了这个解析器来解析它: use Doctrine\ORM\Query\Lexer; class Distance extends \Doctrine\ORM\Query\AST\Functions\FunctionNode { public $lat_a = null; public $lat_b = null;

我尝试添加我的自定义sql函数

我的功能是这样的:

DISTANCE( 15.154454, 5.121444, -15.321111, 15.12111)
我添加了这个解析器来解析它:

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) .
        ')';
    }
}
没关系,这工作很好,但当我使用负变量,如“-15.321111”,我得到一个错误500。。。 有了正var,一切都没问题

有人能帮我解析负变量吗?

试试这个:

public function parse(\Doctrine\ORM\Query\Parser $parser)
{
    $parser->match(Lexer::T_IDENTIFIER);
    $parser->match(Lexer::T_OPEN_PARENTHESIS);
    $this->lat_a = $parser->ArithmeticExpression();
    $parser->match(Lexer::T_COMMA);
    $this->lon_a = $parser->ArithmeticExpression();
    $parser->match(Lexer::T_COMMA);
    $this->lat_b = $parser->ArithmeticExpression();
    $parser->match(Lexer::T_COMMA);
    $this->lon_b = $parser->ArithmeticExpression();
    $parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
    return 'DISTANCE(' .
    $sqlWalker->walkArithmeticExpression($this->lat_a) . ', ' .
    $sqlWalker->walkArithmeticExpression($this->lon_a) . ', ' .
    $sqlWalker->walkArithmeticExpression($this->lat_b) . ', ' .
    $sqlWalker->walkArithmeticExpression($this->lon_b) .
    ')';
}

谢谢你的帮助。我只是在解析中使用算术表达式,一切正常。