Subject: | Quote marks in comments can break bind parameters |
The following program produces the error:
DBD::mysql::db selectrow_arrayref failed: called with 1 bind variables
when 0 are needed at mysqlbug.pl line 15.
DBD::mysql::db selectrow_arrayref failed: called with 1 bind variables
when 0 are needed at mysqlbug.pl line 15
The SQL is legal in MySQL (tested on both 5.0.38 and 4.0.18), but fails
in DBD::mysql 3.008 and 4.005. Removing the single quote mark in the
SQL comment or having an even number of quote marks fixes the problem.
Cheers,
Ovid
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dsn = "DBI:mysql:database=mydatabase;host=localhost";
my $dbh = DBI->connect( $dsn, qw/user pass/, { RaiseError => 1 } )
or die $DBI::errstr;
$dbh->do('DROP TABLE IF EXISTS buggy');
$dbh->do('CREATE TABLE buggy ( id int(3) )');
$dbh->do('INSERT INTO buggy (id) VALUES (1)');
$dbh->selectrow_arrayref(<<'END', {}, 1);
SELECT id
FROM buggy
-- it's a bug!
WHERE id = ?
END