Re: Problems with database handle attributes in error handle
- From: Tim.Bunce@xxxxxxxxx (Tim Bunce)
- Date: Mon, 27 Mar 2006 16:20:28 +0100
On Mon, Mar 27, 2006 at 02:04:30PM +0100, Martin J. Evans wrote:
Hi,
I have my own error handler in which I'd like to log as much detail about the
error as possible. In this handler I do something like:
sub _error_handler {
my ($msg, $h, $method_ret) = @_;
my $dbh = $h;
$dbh = $h->{Database} if ($h->{Type} eq "st");
print "DB: ". $dbh->{Name}.
", Username: ". $dbh->{Username};
print "Error: (handle type: ". $h->{Type}. ")" .
"(SQL:" . $h->{Statement} . ") (msg:".
$h->errstr . ")");
print Carp::longmess("DBI error trap")};
}
(vastly simplified).
This works fine when $h is type "st" and is mostly fine when $h is type "dr"
with one notable exception - when DBI->connect fails as I get:
Can't get DBI::dr=HASH(0x83cbbc4)->{Username}: unrecognised attribute name at
/usr/local/lib/perl5/site_perl/5.8.7/i686-linux/DBI.pm line 1329.
Funnily enough I just fixed that yesterday.
I cannot protect the $dbh->{Username} references by checking for existance
first e.g.
print "Username: " . $dbh->{Username} if (exists($dbh->{Username}));
as I get the same warning message. Is this correct behavior?
Yes. It's a tied hash and the DBI doesn't provide a useful EXISTS method.
I found:
Yeap. That's the right spot. Just add in a case for Username.
Tim.
.
- Follow-Ups:
- Re: Problems with database handle attributes in error handle
- From: Martin J. Evans
- Re: Problems with database handle attributes in error handle
- References:
- Problems with database handle attributes in error handle
- From: Martin J. Evans
- Problems with database handle attributes in error handle
- Prev by Date: Problems with database handle attributes in error handle
- Next by Date: Re: Problems with database handle attributes in error handle
- Previous by thread: Problems with database handle attributes in error handle
- Next by thread: Re: Problems with database handle attributes in error handle
- Index(es):
Relevant Pages
|