Re: Error handling for auto-reconnect?
am 26.01.2006 03:40:12 von steven.lembark
Is there any way to restart the failed transaction from
within the HandleError sub? I cannot find anything in
the DBI doc's that allows me to tell what the last op
on the dbh was.
thanx
--
Steven Lembark steven.lembark@ip-soft.net
Systems Management Phone: 888.IPSOFT8
IPsoft, Inc. Direct: 212.440.5529
http://www.ip-soft.net Fax: 212.353.2454
Re: Error handling for auto-reconnect?
am 26.01.2006 15:37:45 von henri
Are you talking about $dbh->{Statement} ?
If you want full transactional integrity and you've been sending
multiple statements within the transaction, you could overload execute()
and track every time there's an "open tran" or "commit" in the
statement. Anything in between, you store in an array of statements so
when there's an error you rerun all of them.
Steven Lembark wrote:
>
> Is there any way to restart the failed transaction from
> within the HandleError sub? I cannot find anything in
> the DBI doc's that allows me to tell what the last op
> on the dbh was.
>
> thanx
>
>
Re: Error handling for auto-reconnect?
am 26.01.2006 20:09:10 von lembark
-- Henri Asseily
> Are you talking about $dbh->{Statement} ?
> If you want full transactional integrity and you've been sending multiple
> statements within the transaction, you could overload execute() and track
> every time there's an "open tran" or "commit" in the statement. Anything
> in between, you store in an array of statements so when there's an error
> you rerun all of them.
overloading execute doesn't deal gracefully with selectall_*,
fetchall_*...
Best odds I can find at this point is to add a "reconnect"
feture that uses swap_inner_handle to re-establish the dbh,
sth connections and (hopefully) re-bind the parameters.
That would allow the error handler to effectively do
somthing like the pesudo-dbi below:
my $handle = $_[1];
if( $err =~ /$connection_lost_error/o )
{
$_[0] = 'Connection failure';
if( $handle->isa( 'sth' ) )
{
$_[0] .= ' Reconnected'
if $handle->reconnect_statement;
}
elsif( $handle->isa( 'dbh' ) )
{
$_[0] .= ' Reconnected'
if $handle->reconnect_database;
}
else
{
# give up;
undef
}
}
The point is cataloging how much can be done using
the DBI interface to rebuild what was damaged.
For statement handles the current issue is figuring out
how to re-bind the parameters.
Transactions will proably be lost (for now at least),
but at least a downed database connection will leave
all prepared statements still alive and re-usable.
--
Steven Lembark 85-09 90th Street
Workhorse Computing Woodhaven, NY 11421
lembark@wrkhors.com 1 888 359 3508