if ($self->{_can_do_transactions}) { local $dbh->{AutoCommit} = 0; eval { code_that_touches_db(); $dbh->commit; }; if ($@) { my $msg = $@; eval { $dbh->rollback }; die $msg; } } else { code_that_touches_db(); } #### if ($self->{_can_do_transactions}) { # If RaiseError is true, begin_work() will: # return true if a new transaction was started # croak if already in a transaction # croak if transactions not supported # local $dbh->{RaiseError} = 1; my $started_a_new_transaction = 0; eval { $started_a_new_transaction = $dbh->begin_work }; eval { $code->(@_); $dbh->commit if $started_a_new_transaction; }; if ($@) { my $msg = $@; eval { $dbh->rollback } if $started_a_new_transaction; die $msg; } } else { code_that_touches_db(); } #### eval { local $dbh->{AutoCommit} = 0; }; $self->{_can_do_transactions} = $@ ? 0 : 1; #### # If RaiseError is false, begin_work() will: # return true if a new transaction was started # return false if already in a transaction # croak if transactions not supported # my $started_a_new_transaction = 0; eval { local $dbh->{RaiseError} = 0; $started_a_new_transaction = $dbh->begin_work; }; $self->{_can_do_transactions} = $@ ? 0 : 1; eval { $dbh->rollback } if $started_a_new_transaction; #### closing dbh with active statement handles during global destruction #### eval { my $val = $dbh->{AutoCommit}; # makes error go away? local $dbh->{AutoCommit} = 0; }; $self->{_can_do_transactions} = $@ ? 0 : 1;