Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 48242
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: stro [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 4.011
  • 4.012
Fixed in: (no value)



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.';
This problem also happens with '+', '.', 'e' values, the bug is in "parse_number" in dbdimp.c -- Serguei Trouchelle
#!/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', '+'], }, {'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', 'e'], }, {'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.';
This is a patch that solves the bug. -- Serguei Trouchelle
4663a4664 > int seen_digit; 4666c4667 < seen_neg= seen_dec= seen_e= seen_plus= 0; --- > seen_neg= seen_dec= seen_e= seen_plus= seen_digit= 0; 4719a4721 > seen_digit= 1; 4727c4729 < if (len == 0 || cp - string < (int) len) { --- > if (len == 0 || cp - string < (int) len || seen_digit == 0) {
Applied patch - thank you!