Subject: | when a txn fails, should clear sth cache |
Date: | Fri, 5 Mar 2010 03:34:34 +0000 |
To: | bug-DBD-InterBase [...] rt.cpan.org |
From: | Sam Watkins <sam [...] nipl.net> |
We are using DBIx::Class with DBD::InterBase and Firebird. DBIx::Class uses
$dbh->prepare_cached(...) to cache statement handles for efficiency.
The problem is that if a transaction fails and is rolled back, Firebird
discards all active statements, but the cached statement handles remain.
So after a failed transaction, other things fail too, they are trying to use
cached handles that are no longer valid. This does not seem to occur with
normal database errors, or after a successful transaction.
I was able to hack around this by clearing the statement handle cache, which is
described in the DBI perldoc. If a transaction fails, I call a function which
includes this code:
my $CachedKids = $dbh->{CachedKids};
# warn "clearing statement cache: $_\n" for keys %$CachedKids;
%$CachedKids = () if $CachedKids;
Since this appears to be a Firebird-specific quirk, I think it's reasonable to
ask DBD::InterBase to clear the statement handle cache automatically when
rollback is called. I haven't checked whether the active statements are lost
when a exception occurs in a transaction, or when ROLLBACK is called; but I
think it's probably a side-effect of ROLLBACK.
I hope I explained this clearly, it's a bit complicated I guess!
thanks,
Sam Watkins