in reply to Placeholders and Negative Numbers..

It seems to work for me on MySQL 4.1 using $dbh instead of $sp->dbh:
use strict; use warnings; use DBI; my $dbh = DBI->connect( 'DBI:mysql:test', 'foo', 'bar' ) or die; my $lon = -0.232323127347249; my $sql = qq| SELECT lon,lat,location_id FROM lat_long WHERE lon>= $lo +n|; my $sth = $dbh->prepare($sql); $sth->execute(); print STDERR "Rows not using placeholders ".$sth->rows."\n"; $sql = qq| SELECT lon,lat,location_id FROM lat_long WHERE lon >= ?|; $sth = $dbh->prepare($sql); $sth->execute($lon); print STDERR "Rows using placeholders ".$sth->rows."\n"; __END__
create table lat_long(lon double not null, lat double not null, locati +on_id integer); insert into lat_long (location_id, lat, lon) values(44977, 48.3547, 11 +.7875); insert into lat_long (location_id, lat, lon) values(53280, 48.1369, 11 +.5456); insert into lat_long (location_id, lat, lon) values(53281, 48.1394, 11 +.5454); insert into lat_long (location_id, lat, lon) values(53282, 47.6869, 11 +.7609); insert into lat_long (location_id, lat, lon) values(53283, 48.3547, 11 +.7875); insert into lat_long (location_id, lat, lon) values(60105, 48.3547, 11 +.7875); insert into lat_long (location_id, lat, lon) values(80766, 48.3507, 11 +.7328); insert into lat_long (location_id, lat, lon) values(71776, 48.1435, 11 +.5574); insert into lat_long (location_id, lat, lon) values(65883, 48.1269, 11 +.6363); insert into lat_long (location_id, lat, lon) values(65884, 48.1515, 11 +.6178);
$ perl 656378.pl Rows not using placeholders 10 Rows using placeholders 10
Update Tue Dec 11 14:48:09 CET 2007: Re-ran using data supplied by ropey, still the same results.
--
Andreas

Replies are listed 'Best First'.
Re^2: Placeholders and Negative Numbers..
by ropey (Hermit) on Dec 11, 2007 at 13:26 UTC
    Afraid not - think you do not have the same sample data - see my updated node
Re^2: Placeholders and Negative Numbers..
by Anonymous Monk on May 26, 2015 at 23:28 UTC
    Your negative values are being typecast to strings. Putting CAST(XXX as signed integer) around your placeholder and column would solve it.