Re: Problems with database handle attributes in error handle
- From: martin.evans@xxxxxxxxxxxx (Martin J. Evans)
- Date: Mon, 27 Mar 2006 16:40:15 +0100 (BST)
Tim,
Thanks for the confirmation.
I added:
|| (*key=='U' && strEQ(key, "Username"))
and my problem has gone away.
Martin
--
Martin J. Evans
Easysoft Ltd, UK
http://www.easysoft.com
On 27-Mar-2006 Tim Bunce wrote:
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.
- References:
- Re: Problems with database handle attributes in error handle
- From: Tim Bunce
- Re: Problems with database handle attributes in error handle
- Prev by Date: Re: Problems with database handle attributes in error handle
- Next by Date: Easily produced: DBD::mysql outputs to stderr and no DBI->errstr
- Previous by thread: Re: Problems with database handle attributes in error handle
- Next by thread: Re: PLEASE HELP ME TO REMOVE MYSELF FROM MAILING LIST
- Index(es):