Easily produced: DBD::mysql outputs to stderr and no DBI->errstr



The 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

.



Relevant Pages

  • DBD:Excel on unix machine
    ... after installation of all packges i ran the most ... use DBI; ... DBI connectfailed: (no error string) at ...
    (perl.dbi.users)
  • DBD:Excel on unix machine
    ... after installation of all packges i ran the most ... use DBI; ... DBI connectfailed: (no error string) at ...
    (comp.lang.perl.modules)
  • Re: sql sERVER sYBASE
    ... (inner DBI::db=HASH(0x81f2db4) ... has ref cnt 1) ... DBI connect ... (no error string) at test.pl line 11 ...
    (perl.beginners)
  • Newbie Question: (no error string)
    ... $ perl testing.pl ... DBI connectfailed: (no error string) at ... use warnings; ...
    (perl.dbi.users)