Hi All,
I'm using DBI HandleError to handle DBI errors in my own subroutine. In that
subroutine I currently do some error logging; give user messages and exit.
I note from the docs that the when working in a transactional environment
the action of the $dbh->disconnect method is undefined i.e. some drivers
will 'rollback' and others will 'commit' the current transaction before
disconnecting.
To cut to the chase, what I want to be able to do in my 'HandleError'
routine is to add code to
1 rollback the current transaction
and
2 disconnect from the database handle.
My prooblem is that the Handleerror method is passed three parameters by
DBI, namely: an error string, a database or statement handle, and the return
value of the function that caused the error.
Now, in order to call $dbh-rollback and $dhh->disconnect I need a database
handle.
Is there a way of finding out in the DBI HandleError routine whether the
handle passed is a statement of a database handle AND, if it is a statement
handle, is there any way of getting the value of the corresponding database
handle from a statement handle.
I tried the following but it will fail if DBI passes a statement handle:
sub _dbierrorlog {
my ($errormessage, $handle, $functionreturnvalue) = @_;
# log the message and trigger an email
# for TESTING ONLY just print
print "Testing message: $errormessage\n$handle\n$functionreturnvalue\n";
print Carp::longmess;
# rollback any active transactions. Can't be sure if we were in a
transaction
# so do the rollback in an eval
eval{ $handle->rollback };
if ($@){ print "rollback failed" }
# disconnect the database
eval( $handle->disconnect() );
if ($@){ print "disconnect failed" }
# exit the program
exit;
}; # end _dbierrorlog
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs