Permalink
Browse files

Removed the `_in_txn` flag, since `AutoCommit` already has that info

  • Loading branch information...
1 parent 8cb406f commit 45bb09f374708d090207d63d54f57480102a84a8 @theory committed Sep 29, 2009
Showing with 19 additions and 20 deletions.
  1. +3 −4 lib/DBIx/Connection.pm
  2. +8 −3 t/do.t
  3. +3 −6 t/svp_do.t
  4. +5 −7 t/txn_do.t
View
@@ -132,7 +132,7 @@ sub do {
my @ret;
my $wantarray = wantarray;
- if ($self->{_in_do} || $self->{_in_txn}) {
+ if ($self->{_in_do} || !$dbh->{AutoCommit}) {
@ret = _exec( $dbh, $code, $wantarray, @_);
return wantarray ? @ret : $ret[0];
}
@@ -157,13 +157,12 @@ sub txn_do {
my $wantarray = wantarray;
my @ret;
- if ($self->{_in_txn}) {
+ unless ($dbh->{AutoCommit}) {
@ret = _exec( $dbh, $code, $wantarray, @_);
return $wantarray ? @ret : $ret[0];
}
local $self->{_in_do} = 1;
- local $self->{_in_txn} = 1;
eval {
$dbh->begin_work;
@@ -192,7 +191,7 @@ sub svp_do {
my $dbh = $self->_dbh;
# Gotta have a transaction.
- unless ($self->{_in_txn}) {
+ if ($dbh->{AutoCommit}) {
my @args = @_;
return $self->txn_do( sub { $self->svp_do($code, @args) } );
}
View
11 t/do.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 29;
#use Test::More 'no_plan';
use Test::MockModule;
@@ -18,9 +18,14 @@ ok my $conn = $CLASS->new( 'dbi:ExampleP:dummy', '', '' ),
my $module = Test::MockModule->new($CLASS);
# Test with no cached dbh.
-$module->mock( _connect => '_connect');
+$module->mock( _connect => sub {
+ pass '_connect should be called';
+ $module->original('_connect')->(@_);
+});
+
ok $conn->do(sub {
- is shift, '_connect', '_connect should have been called';
+ ok shift->{AutoCommit}, 'Inside, we should not be in a transaction';
+ ok $conn->{_in_do}, '_in_do should be true';
}), 'Do something with no cached handle';
# Test with cached dbh.
View
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 31;
#use Test::More 'no_plan';
use Test::MockModule;
@@ -28,19 +28,16 @@ $module->mock( _connect => sub {
});
ok my $dbh = $conn->dbh, 'Fetch the database handle';
-ok !$conn->{_in_txn}, 'We should not be in a txn';
ok !$conn->{_in_do}, '_in_do should be false';
ok $dbh->{AutoCommit}, 'AutoCommit should be true';
is $conn->{_svp_depth}, 0, 'Depth should be 0';
ok $conn->svp_do(sub {
ok !shift->{AutoCommit}, 'Inside, we should be in a transaction';
- ok $conn->{_in_txn}, 'We should be in a transaction';
ok $conn->{_in_do}, '_in_do should be true';
is $conn->{_svp_depth}, 1, 'Depth should be 1';
}), 'Do something with no cached handle';
$module->unmock( '_connect');
-ok !$conn->{_in_txn}, 'Transaction should be over';
ok !$conn->{_in_do}, '_in_do should be false again';
ok $dbh->{AutoCommit}, 'Transaction should be committed';
is $conn->{_svp_depth}, 0, 'Depth should be 0 again';
@@ -81,12 +78,12 @@ $conn->txn_do(sub {
# Make sure nested calls work.
$conn->svp_do(sub {
my $dbh = shift;
- ok $conn->{_in_txn}, 'We should be in a txn';
+ ok !$dbh->{AutoCommit}, 'Inside, we should be in a transaction';
is $conn->{_svp_depth}, 1, 'Depth should be 1';
local $dbh->{Active} = 0;
$conn->svp_do(sub {
is shift, $dbh, 'Nested svp_do should get same dbh, even though inactive';
- ok $conn->{_in_txn}, 'Nested txn_do should be in the txn';
+ ok !$dbh->{AutoCommit}, 'Nested txn_do should be in the txn';
is $conn->{_svp_depth}, 2, 'Depth should be 2';
});
is $conn->{_svp_depth}, 1, 'Depth should be 1 again';
View
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 33;
+use Test::More tests => 31;
#use Test::More 'no_plan';
use Test::MockModule;
@@ -24,17 +24,15 @@ $module->mock( _connect => sub {
});
ok my $dbh = $conn->dbh, 'Fetch the database handle';
-ok !$conn->{_in_txn}, 'We should not be in a txn';
+ok $dbh->{AutoCommit}, 'We should not be in a txn';
ok !$conn->{_in_do}, '_in_do should be false';
-ok $dbh->{AutoCommit}, 'AutoCommit should be true';
ok $conn->txn_do(sub {
ok !shift->{AutoCommit}, 'Inside, we should be in a transaction';
- ok $conn->{_in_txn}, 'We should be in a transaction';
+ ok !$conn->{AutoCommit}, 'We should be in a txn';
ok $conn->{_in_do}, '_in_do should be true';
}), 'Do something with no cached handle';
$module->unmock( '_connect');
-ok !$conn->{_in_txn}, 'Transaction should be over';
ok !$conn->{_in_do}, '_in_do should be false again';
ok $dbh->{AutoCommit}, 'Transaction should be committed';
@@ -90,10 +88,10 @@ $conn->txn_do(sub {
# Make sure nested calls work.
$conn->txn_do(sub {
my $dbh = shift;
- ok $conn->{_in_txn}, 'We should be in a txn';
+ ok !$conn->{AutoCommit}, 'We should be in a txn';
local $dbh->{Active} = 0;
$conn->txn_do(sub {
is shift, $dbh, 'Nested txn_do should get same dbh, even though inactive';
- ok $conn->{_in_txn}, 'Nested txn_do should be in the txn';
+ ok !$conn->{AutoCommit}, 'Nested txn_do should be in the txn';
});
});

0 comments on commit 45bb09f

Please sign in to comment.