Subject: | 'mysql_bind_type_guessing' doesn't work correctly with minus sign |
Hi guys,
I've tried to use 'mysql_bind_type_guessing' parameter but found a
problem, when a binding value equals to '-' (minus). Seems that
DBD::mysql thinks that minus is a number, and doesn't quote it.
I'm attaching a script that shows this problem. I'm using DBD::mysql
4.011 an 4.012 with ActivePerl 5.10.1005 on MS Windows Vista 32 bit and
MySQL 5.1.36 if it does matter.
--
Serguei Trouchelle
Subject: | ___test1.pl |
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::mysql 4.012;
my $dbh = DBI->connect('dbi:mysql:test', 'test', '');
undef $dbh->{'RaiseError'};
$dbh->{'PrintError'}++;
my @queries = (
{'stmt' => 'CREATE TABLE test_dbd_mysql1 (first_name VARCHAR(255), last_name VARCHAR(255))',
'bind' => [],
},
{'stmt' => 'INSERT INTO test_dbd_mysql1 (first_name, last_name) VALUES (?, ?)',
'bind' => ['testtest', '-'],
},
{'stmt' => 'INSERT INTO test_dbd_mysql1 (first_name, last_name) VALUES (?, ?)',
'bind' => ['testtest', 0],
},
{'stmt' => 'INSERT INTO test_dbd_mysql1 (first_name, last_name) VALUES (?, ?)',
'bind' => ['testtest', ''],
},
{'stmt' => 'DROP TABLE test_dbd_mysql1',
'bind' => [],
},
);
foreach my $guess (0, 1) {
$dbh->{'mysql_bind_type_guessing'} = $guess;
print '>>>>Guessing set to ' . $guess . "\n";
foreach (@queries) {
print '-'x64, "\n", $_->{'stmt'}, "\n", join('/', @{ $_->{'bind'} }), "\n";
my $sth = $dbh->prepare($_->{'stmt'}) or next;
$sth->execute(@{ $_->{'bind'} }) or next;
}
}
print 'Done.';