Bug #24244 DBD driver has not implemented the AutoCommit attribute
Submitted: 13 Nov 2006 9:47 Modified: 21 Feb 2013 21:57
Reporter: Craig Manley Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connectors: DBD::mysql ( Perl ) Severity:S2 (Serious)
Version:3.0008 OS:FreeBSD (FreeBSD/Windows)
Assigned to: CPU Architecture:Any
Tags: local AutoCommit implemented innodb

[13 Nov 2006 9:47] Craig Manley
Description:
Normally when using transactions, I set a 'local' copy of the AutoCommit attribute so that when my transaction block exits, the original value of the AutoCommit attribute is automatically restored.

Unfortunately, when using the DBD::mysql driver, Perl dies with the message "DBD driver has not implemented the AutoCommit attribute" as soon as this line is executed:
local $dbh->{'AutoCommit'} = 0;
Executing the same line, but without the 'local' part, works fine, but of course this is not so safe (especially in persistant code) because if the block die's, the value of $dbh->{'AutoCommit'} isn't restored to what it was.

I've included a test script. My MySQL client+server versions are 5.0.27.

How to repeat:
#!/usr/local/bin/perl -w
use strict;
use DBI;

my $dbh = DBI->connect('dbi:mysql:database=test:localhost', 'test', '', {'RaiseError' => 1, 'PrintError' => 0, 'AutoCommit' => 1});
unless(defined($dbh)) {
	die($DBI::errstr);
}
$dbh->do('DROP TABLE IF EXISTS tinnodb');
$dbh->do('CREATE TABLE tinnodb (id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, data VARCHAR(25)) TYPE InnoDB');
print 'AutoCommit: ' . $dbh->{'AutoCommit'} . "\n";
$dbh->{'AutoCommit'} = 1;
do_stuff();
print 'AutoCommit: ' . $dbh->{'AutoCommit'} . "\n";

sub do_stuff {
	print 'AutoCommit: ' . $dbh->{'AutoCommit'} . "\n";
	local $dbh->{'AutoCommit'} = 0; # removing 'local' works
	print 'AutoCommit: ' . $dbh->{'AutoCommit'} . "\n";
	my $sth = $dbh->prepare('INSERT INTO tinnodb (data) VALUES (?)');
	$sth->execute('bla');
	$sth->execute('foo');
	$sth->finish();
	$dbh->commit();
	$dbh->disconnect();
}
[14 Nov 2006 9:28] MySQL Verification Team
Thank you for the bug report.

C:\codesmaple>perl bug24244.pl
AutoCommit: 1
AutoCommit: 1
AutoCommit:
DBD driver has not implemented the AutoCommit attribute at bug24244.pl line 15.
[13 Jan 2007 19:20] Peter Jordan
I am seeing this on a Debian Sid platform.
Using Sebian packages:

ii  mysql-server                         5.0.32-2
ii  libdbi-perl                          1.53-1

FATAL PLUGIN ERROR:  DBD driver has not implemented the AutoCommit attribute at /usr/lib/perl5/DBI.pm line 672.

I am pretty sure that the error is coming out of this code snippet:

  $self->{_dbh_pc} = DBI->connect_cached($self->{_dsn}, $self->{_config}->{login},                                   $self->{_config}->{password},
{private_foo_key => 'pre_connect', RaiseError => 1, AutoCommit => 1});

  $self->log(LOGWARN, "pre-connect: connect_cached returned undef") unless defined $self->{_dbh_pc};
  $self->log(LOGWARN, "pre-connect: connect_cached ERRSTR: ", $DBI::errstr) if defined $DBI::errstr;

  my $sql = "INSERT INTO maillog.connection ( connect_time, remote_host, remote_ip ) VALUES ( NOW(), ?, ?);";
  my $rc;
  eval {
    $rc = $self->{_dbh_pc}->do($sql, undef, $remote_host, $remote_ip);
  };
  if ($@) { 
    $self->log(LOGWARN, "pre_connect: code: $rc, ip: $remote_ip, insert_id: " . $self->{_dbh_pc}->{'mysql_insertid'} . " : " . $self->{_dbh_pc}->errstr);
    return DENYSOFT, "Database has gone away, try again.";
  }

At least I'm pretty sure this is where it is happening, since I get
no db entries for the connection that is logged immediately following
this error.

That code snippet is run in a pre_connect hook from a qpsmtpd plugin.
[21 Feb 2013 21:57] Sveta Smirnova
Thank you for the report.

We don't work on DBD::mysql bugs anymore. All its bugs should go to CPAN: https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql

I re-submitted your report to https://rt.cpan.org/Public/Bug/Display.html?id=83518
Please subscribe to the new report on CPAN and work with DBD::mysql developers in case if they need additional details.