Skip to content

Commit

Permalink
Fixed AutoCommit so that it doesn't cache
Browse files Browse the repository at this point in the history
  • Loading branch information
robkinyon committed Jul 29, 2006
1 parent b109575 commit 81ef9dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension DBD::Mock.

1.34
- Fixed how AutoCommit is handled to avoid $dbh caching (RobK)

1.33
- Thanks to Chas Owens for patch and test
for the mock_can_prepare, mock_can_execute,
Expand Down
33 changes: 21 additions & 12 deletions lib/DBD/Mock.pm
@@ -1,4 +1,3 @@

package DBD::Mock;

sub import {
Expand All @@ -19,7 +18,7 @@ use warnings;

require DBI;

our $VERSION = '1.33';
our $VERSION = '1.34';

our $drh = undef; # will hold driver handle
our $err = 0; # will hold any error codes
Expand Down Expand Up @@ -109,6 +108,10 @@ sub connect {
$attributes->{mock_attribute_aliases} = DBD::Mock::_get_mock_attribute_aliases($dbname);
$attributes->{mock_database_name} = $dbname;
}

# Need to protect AutoCommit from $dbh caching - RobK.
my $autocommit = delete $attributes->{ 'AutoCommit' };

my $dbh = DBI::_new_dbh($drh, {
Name => $dbname,
# holds statement parsing coderefs/objects
Expand All @@ -124,6 +127,9 @@ sub connect {
# rest of attributes
%{ $attributes },
}) || return;

$dbh->STORE( 'AutoCommit' => $autocommit || 1 );

return $dbh;
}

Expand Down Expand Up @@ -392,11 +398,14 @@ sub selectcol_arrayref {
return [ map { $_->[0] } @{$a_ref} ]
}

{
my %autocommit;
sub FETCH {
my ( $dbh, $attrib ) = @_;
$dbh->trace_msg( "Fetching DB attrib '$attrib'\n" );
if ($attrib eq 'AutoCommit') {
return $dbh->{AutoCommit};
$dbh->trace_msg( "Fetching AutoCommit\n" );
return $autocommit{$dbh};
}
elsif ($attrib eq 'Active') {
return $dbh->{mock_can_connect};
Expand Down Expand Up @@ -435,7 +444,7 @@ sub STORE {
my ( $dbh, $attrib, $value ) = @_;
$dbh->trace_msg( "Storing DB attribute '$attrib' with '" . (defined($value) ? $value : 'undef') . "'\n" );
if ($attrib eq 'AutoCommit') {
$dbh->{AutoCommit} = $value;
$autocommit{$dbh} = $value;
return $value;
}
elsif ( $attrib eq 'mock_clear_history' ) {
Expand Down Expand Up @@ -527,6 +536,7 @@ sub STORE {
return $dbh->{$attrib} = $value;
}
}
}

sub DESTROY {
undef
Expand Down Expand Up @@ -1933,15 +1943,14 @@ I would also like to add the ability to bind a subroutine (or possibly an object
=head1 CODE COVERAGE
I use L<Devel::Cover> to test the code coverage of my tests, below is the L<Devel::Cover> report on this module test suite.
We use L<Devel::Cover> to test the code coverage of my tests, below is the L<Devel::Cover> report on this module test suite.
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
DBD/Mock.pm 90.9 85.5 76.0 94.1 0.0 100.0 88.4
---------------------------- ------ ------ ------ ------ ------ ------ ------
Total 90.9 85.5 76.0 94.1 0.0 100.0 88.4
---------------------------- ------ ------ ------ ------ ------ ------ ------
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
blib/lib/DBD/Mock.pm 92.0 86.6 77.9 95.3 0.0 100.0 89.5
Total 92.0 86.6 77.9 95.3 0.0 100.0 89.5
---------------------------- ------ ------ ------ ------ ------ ------ ------
=head1 SEE ALSO
Expand Down

0 comments on commit 81ef9dc

Please sign in to comment.