Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

in_txn always returns true? #11

Closed
rledousa opened this Issue · 4 comments

2 participants

@rledousa

Hi

Loving DBIx::Connector so far. One question - in_txn() returns true even before I do $conn->txn(..). Here's an example:

#class var
my $conn = DBIx::Connector->new($dsn,$dbUser,$dbPwd, {AutoCommit => 0, RaiseError => 1, PrintError => 0});

sub do_something {
:
# for testing
print $conn->in_txn() . "\n";
$conn->txn(fixup => sub {
print $conn->in_txn() . "\n";
:
:
} );
}

If I set AutoCommit => 1 (enabled), then in_txn() works as expected ( returns false outside of txn, '1' inside).

If AutoCommit => 0, both print statements shows true. I'm using mysql 5.1. Am I doing something wrong or misunderstanding in_txn()?

thx

@theory
Owner
@rledousa

thx for the reply

sorry for not adding the code that calls do_something(). I was just trying to provide a bare-bones example. To add more flesh, here's what I did: I created a simple class which has the class var ($conn) and a constructor which does nothing more than bless and return. I instantiate the class in my test script, then call do_something($sql) and pass in some sql for testing, eg

sub new {
        my ($this, $args) = @_;

        my $class = ref($this) || $this;

        my $self = {
                dbh => 'handle'
        };

        bless $self, $class;

        return $self;
}

sub do_something {
  my ($self, $sql) = @_;
  print $conn->in_txn();   # this always prints '1' if AutoCommit is false
  $conn->txn(fixup => sub { $_->do($sql)} );
}

again, I'm using mysql. Dunno if that makes a difference for you.

@theory
Owner
@theory theory closed this in b4111d0
@rledousa

thanks David. I'd read that, but wasn't clear if that is the same behavior for your module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.