Groups | Search | Server Info | Login | Register
Groups > perl.dbi.users > #3366
| Newsgroups | perl.dbi.users |
|---|---|
| Date | 2018-01-28 13:43 +0000 |
| Subject | Re: Need help with an unexpected behaviour |
| Message-ID | <20180128134339.ijbimjf7w2fs2sca@timac> (permalink) |
| References | <00f001d396bc$fd0270d0$f7075270$@web.de> |
| From | Tim.Bunce@pobox.com (Tim Bunce) |
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.
Back to perl.dbi.users | Previous | Next — Previous in thread | Next in thread | Find similar
Need help with an unexpected behaviour andreas.mock@web.de ("Andreas Mock") - 2018-01-26 16:47 +0100
Re: Need help with an unexpected behaviour Tim.Bunce@pobox.com (Tim Bunce) - 2018-01-28 13:43 +0000
AW: Need help with an unexpected behaviour andreas.mock@web.de ("Andreas Mock") - 2018-01-28 15:12 +0100
csiph-web