On Fri, Jan 26, 2018 at 04:47:35PM +0100, Andreas Mock wrote: > Hi all, > > 9 my %attr = ( > 10 'AutoCommit' => 1, > 11 'RaiseError' => 1,
> 35 sub doit { > 36 my $dbh = shift; > 37 > 38 local $dbh->{'AutoCommit'} = 1; > 39 > 40 $dbh->begin_work; > 41 $dbh->do("insert into mca_rb_test values ('short')"); > 42 $dbh->do("insert into mca_rb_test values > ('looooooooooooooooooooooooooooooooooooooooooooooooooong')"); > 43 $dbh->commit; > Whithout line 38 I get what I expect. [...] > BUT: As soon as I have line 38 in there, which shouldn't change > the initially set 'AutoCommit', the first insert is commited > to the database even the exeption is raised in the opened > transaction. That seems like a driver bug at first sight. While "local $dbh->{'AutoCommit'} = 1;" looks like a simple hash assignment there's a lot going on behind the scenes. ($dbh is a ref to a tied hash so a STORE method gets called to handle the assignment.) While it doesn't "change" the AutoCommit setting, since it's already enabled, the "local" does cause Perl to arrange to execute $dbh->{'AutoCommit'} = 1 when the scope exits. Both the initial assignment and the re-setting assignment may have side effects. > Can someone explain what is happening behind the scenes or > give a pointer to some helpful documentation which I have overlooked? The DBI (and most drivers) have extensive tracing built in. The trace output is often very helpful to see what's really happening. See https://metacpan.org/pod/DBI#TRACING It'll show you the effect of the local AutoCommit assignment and re-setting assignment at scope-exit. Tim.