Subject: | bug in prepare? |
Date: | Tue, 27 Feb 2007 17:48:10 -0500 |
To: | bug-DBD-SQLite [...] rt.cpan.org. |
From: | "JJ Knitis" <jj [...] dangercreative.com> |
distribution: M/MS/MSERGEANT/DBD-SQLite-1.12.tar.gz
perl: This is perl, v5.8.8 built for i586-linux-thread-multi
os: Linux d530 2.6.18.2-34-default #1 SMP Mon Nov 27 11:46:27 UTC 2006 i686 i686 i386 GNU/Linux
Code and output below. In a where clause, comparing an absolute value of anything on the left to a place holder on the right evaluates to true.
----
#!/usr/bin/perl
use strict;
use DBI;
use Data::Dumper;
my $dbh = DBI->connect( "dbi:SQLite:dbname=", '', '' );
{
my $SQL = "SELECT 'b' where abs('a') < -1";
my $getSTH = $dbh->prepare( $SQL );
$getSTH->execute();
print Dumper( [$SQL, undef, $getSTH->fetchall_arrayref()] );
$getSTH->finish;
print "\n\n";
}
{
my $value = 'a';
my $SQL = "SELECT 'b' where abs('a') < ?";
my $getSTH = $dbh->prepare( $SQL );
$getSTH->execute( $value );
print Dumper( [$SQL, $value, $getSTH->fetchall_arrayref()] );
$getSTH->finish;
print "\n\n";
}
my $value = -1;
my @SQL = (
"SELECT 'b' where abs('a') < ?",
"SELECT 'b' where ? < abs('a')",
"SELECT 'b' where CAST( abs('a') as 'real' ) < ?",
"SELECT 'b' where abs('a') < CAST(? as 'real')",
);
foreach my $thisSQL ( @SQL ) {
my $getSTH = $dbh->prepare( $thisSQL );
$getSTH->execute( $value );
print Dumper( [$thisSQL, $value, $getSTH->fetchall_arrayref()] ), "\n";
$getSTH->finish;
}
------
Show quoted text
> perl check_dbi.pl
$VAR1 = [
'SELECT \'b\' where abs(\'a\') < -1',
undef,
[]
];
$VAR1 = [
'SELECT \'b\' where abs(\'a\') < ?',
'a',
[
[
'b'
]
]
];
$VAR1 = [
'SELECT \'b\' where abs(\'a\') < ?',
-1,
[
[
'b'
]
]
];
$VAR1 = [
'SELECT \'b\' where ? < abs(\'a\')',
-1,
[]
];
$VAR1 = [
'SELECT \'b\' where CAST( abs(\'a\') as \'real\' ) < ?',
-1,
[]
];
$VAR1 = [
'SELECT \'b\' where abs(\'a\') < CAST(? as \'real\')',
-1,
[]
];
--
JJ Knitis