jsor / doctrine-postgis

Spatial and Geographic Data with PostGIS and Doctrine.
MIT License
209 stars 50 forks source link

[SOLVED] Error with String Functions #28

Closed ianrodrigues closed 7 years ago

ianrodrigues commented 7 years ago

Hi guys,

I'm trying to execute the following code:

public function nearestStations($geom = null, $srid = null)
{
    $builder = $this->createQueryBuilder('s');
    $builder->select('s')
        ->where(
            $builder->expr()->andX('ST_Intersects(ST_GeomFromText(:geom, :srid), s.geom)'),
            $builder->expr()->isNotNull('s.origin')
        )
        ->setParameter('geom', $geom)
        ->setParameter('srid', $srid);

    $query = $builder->getQuery();
    // var_dump($query->getDQL()); die;
    return $query->execute();
}

This is the result when I dump the DQL:

SELECT s FROM Funceme\PCD\Station\Station s WHERE ST_Intersects(ST_GeomFromText(:geom, :srid), s.geom) AND s.origin IS NOT NULL

But I'm getting this error:

[Syntax Error] line 0, col 103: Error: Expected =, <, <=, <>, >, >=, !=, got 'AND'

When I execute the SQL in pgAdmin, it works. Someone knows how to resolve this? Thx!

ianrodrigues commented 7 years ago

The SQL code that I run in pgAmin looks like this:

SELECT * FROM pcd.station WHERE ST_Intersects(ST_GeomFromText('MY_POLYGON_CODE', 'MY_SRID'), geom) AND origin IS NOT NULL

The same as the DQL, I think.

ianrodrigues commented 7 years ago

Hey guys,

I solved the problem, changing this:

$builder->expr()->andX('ST_Intersects(ST_GeomFromText(:geom, :srid), s.geom)')

by this:

$builder->expr()->eq('ST_Intersects(ST_GeomFromText(:geom, :srid), s.geom)', $builder->expr()->literal(true))
jsor commented 7 years ago

Was about to comment but glad you solved it yourself. 👍

ianrodrigues commented 7 years ago

Thx!