Subject: | DBD driver has not implemented the AutoCommit attribute |
Originally reported by Craig Manley at
http://bugs.mysql.com/bug.php?id=24244
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();
}