教义querybuilder语法错误预期=,<,<=,<>,>,> =,!=

时间:2018-11-24 09:24:26

标签: php symfony4 doctrine-query mysql-spatial

出现以下错误:

“ [语法错误]第0行,列-1:错误:预期=,<,<=,<>,>,> =,!=,出现了字符串结尾。” < / p>

使用学说querybuiler构建此查询:

SELECT * 
FROM area 
WHERE ST_Contains(polygon, ST_GeomFromText('POINT(13.405584 52.510621)', 1));

(Sf4和教义2.6)

Orm配置:

orm:
    dql:
      numeric_functions:
        ST_Contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
        ST_GeomFromText: App\Infrastructure\Persistence\Doctrine\STGeomFromText
        POINT: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point

STGeoFromText类:

use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction;

class STGeomFromText extends AbstractSpatialDQLFunction
{
    protected $platforms = array('mysql');

    protected $functionName = 'ST_GeomFromText';

    protected $minGeomExpr = 1;

    protected $maxGeomExpr = 2;
}

查询的构造:

use CrEOF\Spatial\PHP\Types\Geometry\Point;

    $lon = 13.405584;
    $lat = 52.510621;
    $qb = $this->getEntityManager()->createQueryBuilder();
    $qb->select('a.name')
        ->from(Area::class, 'a')
        ->where("ST_Contains(a.polygon, ST_GeomFromText(':point', 1))")
        ->setParameter('point', new Point($lon, $lat), 'point');
    $result = $query->getResult();

相同错误:

->where("ST_Contains(a.polygon, ST_GeomFromText(:point, 1))")

请注意,没有符号'包裹了:point参数。

1 个答案:

答案 0 :(得分:0)

错误来自Doctrine/ORM/Query/Parser.php,该错误试图解析和验证查询版本。

此问题是由于该解析器未“理解” ST_Contains 返回布尔值并需要比较器运算符,例如“ =,<,<=,<>,>,> =,!= ”。

要解决此问题,请将= true添加到您的条件中:

->where("ST_Contains(a.polygon, ST_GeomFromText(:point, 1)) = true")