in reply to DBI placeholders for spatial data

Have you tried passing a whole point-string for each placeholder?

So something like:

$arg =' POINT ( -4.67682813534559 58.3335955352018 ) ' -- then using execute($arg) for a statement with ST_GeomFromText( ? ) -- -- (maybe casting the argument to WKT, if such casting is supported)

(just curious, it probably won't work either...)

Replies are listed 'Best First'.
Re^2: DBI placeholders for spatial data
by LanX (Sage) on Jun 26, 2021 at 11:57 UTC

      You think it will work? That'd be nice, I didn't gather that from your reply (but I didn't TL/DR any links of course). Let's see if it helps Bod.

        To test this I have used this code:

        my $test = 'POINT( 20 10 )'; $dbh->do("INSERT INTO Test SET start = ST_GeomFromText(?, 4326), end = + ST_GeomFromText(?, 4326)", undef, $test, $test); if ($dbh->err) { print "ERROR: " . $dbh->errstr; } else { print "SUCCESS!"; } print "\n";
        And from the test it I get this result:
        SELECT ST_AsText(start) FROM Test ------------ POINT(20 10)
        I think we can conclude that feeding POINT($lng $lat) to the placeholder works :)

        A quick note for anyone finding this in future...
        POINT takes longitude first then latitude. Several sources online say that it doesn't matter which way around they are. However, if you want ST_Distance_Sphere to give a correct result, they need to be longitude followed by latitude. This is the reason I created a module to handles points, so I don't need to worry about the order except within the module.

        Edited to remove rogue comma pointed out by LanX

        > I didn't gather that from your reply

        as documented: ST_GeomFromText(wkt[,srid])

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        Let's see if it helps Bod

        I am out visiting my sister currently with no access to a computer to try it. When I get back home later, I shall try and report back.

        Thanks for all the useful suggestions and information.