[postgis-users] Using DBI Placeholders for GeomFromText

Stephen Woodbridge woodbri at swoodbridge.com
Fri Jun 11 21:48:04 PDT 2010


Stuart Gralton wrote:
> Hello Everybody,
> 
> Is it possible to use Perl DBI placeholders to insert a geometry into a 
> table using GeomFromText.
> 
> When I try the following;
> 
>      $sth = $dbh->prepare("INSERT INTO table (gid, the_geom) VALUES (?,?)");
>      $sth->execute(1, GeomFromText('POINT(1 1)', 4326));

You might try something like this.

       $sth = $dbh->prepare("INSERT INTO table (gid, the_geom)
                             VALUES (?, GeomFromText(?, 4326))");
       $sth->execute(1, 'POINT(1 1)');

I'm not sure it is valid to pass arbitrary SQL via a place holder. 
GeomFromText() is a function and not a variable.

-Steve

> 
> an error is produced:
> 
>      ERROR:  parse error - invalid geometry
>      HINT:  You must specify a valid OGC WKT geometry type such as 
> POINT, LINESTRING or POLYGON
> 
> The following statement works fine:
> 
>      INSERT INTO table (gid, the_geom) VALUES (1, GeomFromText('POINT(1 
> 1)', 4326));
> 
> 
> I am not entirely sure if this is more of a DBI question or a POSTGIS 
> question, but maybe someone can help?
> 
> Thanks,
> 
> Stuart
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list