[postgis-users] Using DBI Placeholders for GeomFromText

P Kishor punk.kish at gmail.com
Fri Jun 11 22:03:48 PDT 2010


On Fri, Jun 11, 2010 at 11:48 PM, Stephen Woodbridge
<woodbri at swoodbridge.com> wrote:
> 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 is correct. I just tested his suggested syntax, and it works.


> -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
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>



-- 
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================



More information about the postgis-users mailing list