Bod has asked for the wisdom of the Perl Monks concerning the following question:
I have a relatively simple DB query that is giving very strange results. Have you seen anything like this before or do you have any ideas about how I might debug the problem?
print "Content-type: text/plain\n\n"; my $point = "POINT( $data{'lng'} $data{'lat'} )"; my ($usrn) = $dbh->selectrow_array("SELECT idUSRN FROM USRN WHERE idUS +RN > 0 ORDER BY ST_Distance_Sphere( ST_GeomFromText( ?, 4326 ), cente +r ) LIMIT 1", undef, $point); #my ($usrn) = $dbh->selectrow_array("SELECT idUSRN FROM USRN LIMIT 1") +; print $dbh->errstr; print "\n$point $usrn\n"; print "SELECT idUSRN FROM USRN ORDER BY ST_Distance_Sphere( ST_GeomFro +mText( '$point', 4326 ), center ) LIMIT 1"; exit;
I am getting a value of $usrn of zero. Despite the query excluding zero in the WHERE clause and there being no zero for idUSRN in the database table!
This placeholder syntax works fine elsewhere for me. However, just in case this was the problem I have tried removing the placeholder and writing ST_Distance_Sphere( ST_GeomFromText( '$point', 4326 ), center ) and this also gives zero.
But...when I copy the select statement which is printed and paste it into MySQL Query Browser connected to the same database schema, I get an eight-digit integer as expected.
DBI is not displaying an error so no clues there!
Swapping commenting out of the queries gives a sensible, non-zero, result.
Any ideas on what I can try to get to the bottom of this would be very much appreciated. It seems weird that the same query works differently from Perl than it does when run directly against the database.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI returns zero!
by kcott (Archbishop) on Mar 12, 2022 at 21:18 UTC | |
|
Solved! (was: Re: DBI returns zero!)
by Bod (Parson) on Mar 12, 2022 at 20:20 UTC |