Easily produced: DBD::mysql outputs to stderr and no DBI->errstr
am 27.03.2006 18:35:04 von Martin.EvansThe following simple script:
==========
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect(
'DBI:mysql:test', 'xxx', 'yyy',
{PrintError => 0, RaiseError=>0}
) or die "DBI::errstr";
$dbh->do(q/create table mytest (a int, b char(20))/);
$dbh->do(q/delete from mytest where type = ?/, undef, 'three');
print "Error: ", $dbh->errstr, "\n";
==========
produces:
DO: Something wrong while try to prepare query Unknown column 'type' in 'where
clause'
Use of uninitialized value in print at x.pl line 13.
Error:
i.e. it is writing directly to stderr (the bit starting DO:) and not setting the
error string. The problem seems to be in DBD::mysql mysql.xs which contains a
number of fprintf(stderr,) calls without calling DBD::mysql do_error. I think
they need changing to something like this:
--- mysql.xs.orig Mon Mar 27 17:10:18 2006
+++ mysql.xs.mine Mon Mar 27 17:27:44 2006
@@ -510,8 +510,7 @@
}
else
{
- fprintf(stderr,"DO: Something wrong while try to prepare query %s\n",
- mysql_error(&imp_dbh->mysql));
+ do_error(dbh, mysql_errno(&imp_dbh->mysql),
mysql_error(&imp_dbh->mysql));
retval=-2;
mysql_stmt_close(stmt);
Martin
--
Martin J. Evans
Easysoft Ltd, UK
http://www.easysoft.com