Subject: | AutoCommit => 0 on connect does not work |
AutoCommit cannot be set to a false value when passed into connect. The
following code does not work:
my $dbh = DBI->connect( 'DBI:Mock:', '', '', { AutoCommit => 0 } );
# $dbh->{AutoCommit} == 1
The reason for this bug is in this line 134 Mock.pm in the connect method:
$dbh->STORE( 'AutoCommit' => $autocommit || 1 );
The attached patch provides a fix and test cases for this issue. A
workaround until the patch is applied is to set the AutoCommit attribute
to zero after connect:
my $dbh = DBI->connect( 'DBI:Mock:', '', '');
$dbh->{AutoCommit} = 0
Subject: | AutoCommit_off_on_connect.patch |
diff -ur DBD-Mock-1.34.orig/lib/DBD/Mock.pm DBD-Mock-1.34/lib/DBD/Mock.pm
--- DBD-Mock-1.34.orig/lib/DBD/Mock.pm 2006-07-29 13:09:29.000000000 -0500
+++ DBD-Mock-1.34/lib/DBD/Mock.pm 2007-04-18 08:54:29.000000000 -0500
@@ -110,7 +110,10 @@
}
# Need to protect AutoCommit from $dbh caching - RobK.
- my $autocommit = delete $attributes->{ 'AutoCommit' };
+ my $autocommit = 1;
+ if( exists $attributes->{ 'AutoCommit' } ) {
+ $autocommit = delete $attributes->{ 'AutoCommit' };
+ }
my $dbh = DBI::_new_dbh($drh, {
Name => $dbname,
@@ -128,7 +131,7 @@
%{ $attributes },
}) || return;
- $dbh->STORE( 'AutoCommit' => $autocommit || 1 );
+ $dbh->STORE( 'AutoCommit' => $autocommit );
return $dbh;
}
Only in DBD-Mock-1.34/lib/DBD: .Mock.pm.swp
diff -ur DBD-Mock-1.34.orig/t/001_db_handle.t DBD-Mock-1.34/t/001_db_handle.t
--- DBD-Mock-1.34.orig/t/001_db_handle.t 2006-07-29 13:09:29.000000000 -0500
+++ DBD-Mock-1.34/t/001_db_handle.t 2007-04-18 10:36:24.000000000 -0500
@@ -1,6 +1,6 @@
use strict;
-use Test::More tests => 16;
+use Test::More tests => 20;
BEGIN {
use_ok('DBD::Mock');
@@ -14,6 +14,8 @@
isa_ok($dbh, 'DBI::db');
is($dbh->{Name}, '', '... if no db-name is given');
+ cmp_ok( $dbh->{AutoCommit}, '==', 1,
+ '... AutoCommit DB attribute defaults to set' );
# DBI will handle attributes with 'private_', 'dbi_' or ,
# 'dbd_' prefixes but all others, we need to handle.
@@ -71,6 +73,22 @@
$dbh->disconnect();
}
+# test setting attributes with negative values during connect
+
+{
+ my $dbh = DBI->connect( 'DBI:Mock:', '', '',
+ { RaiseError => 0,
+ PrintError => 0,
+ AutoCommit => 0 } );
+ cmp_ok( $dbh->{RaiseError}, '==', 0,
+ 'RaiseError DB attribute unset in connect()' );
+ cmp_ok( $dbh->{PrintError}, '==', 0,
+ 'PrintError DB attribute unset in connect()' );
+ cmp_ok( $dbh->{AutoCommit}, '==', 0,
+ 'AutoCommit DB attribute unset in connect()' );
+
+ $dbh->disconnect();
+}
{
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
Only in DBD-Mock-1.34/t: .001_db_handle.t.swp