On Thu, 2006-09-07 at 12:29 -0700, Jay Buffington wrote:
> But, that handle might have expired, so it is possible to get a
> different handle.
It's not likely, but it is possible. You'd need to have some transient
error that caused the connection to die between DBI calls. (Not during
a call, since you have RaiseError on, right?)
> I'm worried that it's not safe to do this:
>
> use Apache::DBI;
> use DBI;
>
> my $dbh = DBI->connect(...);
> $dbh->do("insert values('foo') into bar');
>
> # time passes... and then:
>
> my $new_dbh = DBI->connect(...);
> $new_dbh->commit();
My approach is to keep AutoCommit on, and turn it off for the brief
periods where I want a transaction to span multiple statements.
{
local $dbh->{AutoCommit} = 0;
### do some SQL actions here
} # commit happens automatically here
> Of course, I might just be whining about a corner case that never
> exists in real life. If the handle is active when I do the insert,
> it's probably going to be active when I do the commit moments later.
If it worries you, you could modify Apache::DBI to die rather than
reconnect if the handle has been requested previously in the current
request. This is pretty easy to keep track of with pnotes.
- Perrin