Symfony Creof功能mydbname.distance不存在

时间:2017-11-28 16:00:09

标签: php symfony doctrine-orm doctrine-query doctrine-extensions

我正在尝试使用Creof包及其Distance函数。当我执行以下代码时,我得到以下异常:

public function getMapDecorator(array $requestInformation, $type) : MapDecorator {
        $queryBuilder = $this->entityManager->getRepository('AppBundle:Provider')->createQueryBuilder('provider');

    $point = new Point(0,0);
    $point->setLongitude($requestInformation["currentLongitude"]);
    $point->setLatitude($requestInformation["currentLatitude"]);

    // build the query
    $queryBuilder
        ->select('provider, DISTANCE(:point, provider.coordinates) AS HIDDEN distance')
        ->having('distance <= :radius')
        ->where("provider.type = :type")
        ->setParameter('type', $type)
        ->setParameter('radius', 10)
        ->setParameter('point', $point)
        ->orderBy('distance')
    ;

    $providers = $queryBuilder->getQuery()->getResult();

    return null;
}

执行此操作时,这是我得到的错误

  

“执行'SELECT a0_.id AS id_0时发生异常,   a0_.type AS type_1,AsBinary(a0_.coordinates)AS coordinates_2,   距离(?,a0_.coordinates)AS sclr_3,a0_.path_id AS path_id_4,   a0_.coordinate_id AS coordinate_id_5 FROM provider a0_ WHERE a0_.type   =?有sclr_3&lt; =? ORDER BY sclr_3 ASC'with params [{},\“professional \”,10]:\ n \ n \ nSQLSTATE [42000]:语法错误或访问   违规:1305功能mydbname.Distance不存在“

我想知道为什么我收到此错误,我可以看到调用此文件的调试:CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Distance

我的配置中也有以下内容:

orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    dql:
        numeric_functions:
            # for mysql
            area:                   CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
            asbinary:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsBinary
            astext:                 CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsText
            buffer:                 CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Buffer
            centroid:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Centroid
            contains:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
            crosses:                CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Crosses
            dimension:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Dimension
            distance:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Distance
            disjoint:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Disjoint
            distancefrommultyLine:  CrEOF\Spatial\ORM\Query\AST\Functions\MySql\DistanceFromMultyLine
            endpoint:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\EndPoint
            envelope:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Envelope
            equals:                 CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Equals
            exteriorring:           CrEOF\Spatial\ORM\Query\AST\Functions\MySql\ExteriorRing
            geodistpt:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeodistPt
            geometrytype:           CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeometryType
            geomfromtext:           CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
            glength:                CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GLength
            interiorringn:          CrEOF\Spatial\ORM\Query\AST\Functions\MySql\InteriorRingN
            intersects:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Intersects
            isclosed:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsClosed
            isempty:                CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsEmpty
            issimple:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\IsSimple
            linestringfromwkb:      CrEOF\Spatial\ORM\Query\AST\Functions\MySql\LineStringFromWKB
            linestring:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\LineString
            mbrcontains:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRContains
            mbrdisjoint:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRDisjoint
            mbrequal:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBREqual
            mbrintersects:          CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRIntersects
            mbroverlaps:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBROverlaps
            mbrtouches:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRTouches
            mbrwithin:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\MBRWithin
            numinteriorrings:       CrEOF\Spatial\ORM\Query\AST\Functions\MySql\NumInteriorRings
            numpoints:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\NumPoints
            overlaps:               CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Overlaps
            pointfromwkb:           CrEOF\Spatial\ORM\Query\AST\Functions\MySql\PointFromWKB
            pointn:                 CrEOF\Spatial\ORM\Query\AST\Functions\MySql\PointN
            point:                  CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point
            srid:                   CrEOF\Spatial\ORM\Query\AST\Functions\MySql\SRID
            startpoint:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\StartPoint
            st_buffer:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
            st_contains:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
            st_crosses:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STCrosses
            st_disjoint:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STDisjoint
            st_equals:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STEquals
            st_intersects:          CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
            st_overlaps:            CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STOverlaps
            st_touches:             CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STTouches
            st_within:              CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STWithin
            touches:                CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Touches
            within:                 CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Within
            x:                      CrEOF\Spatial\ORM\Query\AST\Functions\MySql\X
            y:                      CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Y

1 个答案:

答案 0 :(得分:0)

好的发现了这个问题。 Mysql不赞成使用Distance函数来支持ST_Distance。这个包应该更新,但目前我在我的包中创建了以下类:

namespace AppBundle\ORM;

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

/**
 * Distance DQL function
 *
 * @author  luca capra <luca.capra@create-net.org>
 * @license http://dlambert.mit-license.org MIT
 */
class STDistance extends AbstractSpatialDQLFunction {

    protected $platforms = array('mysql');
    protected $functionName = 'ST_Distance';
    protected $minGeomExpr = 2;
    protected $maxGeomExpr = 2;

}

我在配置中添加了

st_distance:            AppBundle\ORM\STDistance

我现在使用ST_Distance代替Distance