Problems with database handle attributes in error handle

Problems with database handle attributes in error handle

am 27.03.2006 15:04:30 von Martin.Evans

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.

This is a warning (I always use - use warnings).

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? I found:

/* finally check the actual hash just in case */
if (valuesv == Nullsv) {
valuesv = &sv_undef;
cacheit = 0;
svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
if (svp)
valuesv = newSVsv(*svp); /* take copy to mortalize */
else if (!( (*key=='H' && strEQ(key, "HandleError"))
|| (*key=='H' && strEQ(key, "HandleSetErr"))
|| (*key=='S' && strEQ(key, "Statement"))
|| (*key=='P' && strEQ(key, "ParamValues"))
|| (*key=='P' && strEQ(key, "Profile"))
|| (*key=='C' && strEQ(key, "CursorName"))
|| (*key=='C' && strEQ(key, "Callbacks"))
|| !isUPPER(*key) /* dbd_*, private_* etc */
))
warn("Can't get %s->{%s}: unrecognised attribute name",neatsvpv(h,0)
,key);
}

in DBI.xs and the pureperl DBI (which I'm not using) seems to be substantially
different in this area. I noticed Changes file for 1.37 says:

Fixed "Can't get dbh->{Statement}: unrecognised attribute" error in test
caused by change to perl internals in 5.8.0

and a diff of 1.36/1.37 seems to have added the strEQ test for "Statement"
(above). Is this a similar case perhaps?

Thanks.

Martin
--
Martin J. Evans
Easysoft Ltd, UK
http://www.easysoft.com

Re: Problems with database handle attributes in error handle

am 27.03.2006 17:20:28 von Tim.Bunce

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.

Re: Problems with database handle attributes in error handle

am 27.03.2006 17:40:15 von Martin.Evans

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.

PLEASE HELP ME TO REMOVE MYSELF FROM MAILING LIST

am 28.03.2006 12:42:24 von cooi0260

HI,

I BEEN RECEIVING EMAIL FROM THIS dbi-users@perl.org FOR ALMOST 1 YEAR AND I
DIDN'T SUBCRIBE FOR THIS SERVICE. ANY COULD ASSIST ME TO REMOVE THIS EMAILL
ADDRESS COOI0260@MAIL.USYD.EDU.AU FROM THE MAILING LIST. I RECEIVE HUNDRED
AND HUNDRED OF EMAIL FROM THIS SERVER THAT DOESN'T INTEREST ME AT ALL.

COULD ANYONE TELL ME WHAT IS THE LINK OR STEP THAT I COULD REMOVE MYSELF
FROM THIS MAILING LIST, MY EMAIL HAVE EXPLODE MANY TIME DUE TO THE AMOUNT
OF EMAIL THAT I BEEN RECEIVING THROUGH THIS dbi-users@perl.org.

THANK YOU.





Quoting Tim Bunce :

> 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.
>




------------------------------------------------------------ ----
This message was sent using IMP, the Internet Messaging Program.

Re: PLEASE HELP ME TO REMOVE MYSELF FROM MAILING LIST

am 28.03.2006 15:21:40 von david

Steve Hay wrote:
> Send an email to dbi-users-unsubscribe@perl.org, as is shown in the mail
> headers of the mails that you've been receiving.

AND TO THINK THAT IT ONLY TOOK THE PERSON ABOUT ONE YEAR TO REALISE THAT
THEY HAD BEEN SUBSCRIBED TO A MAILING LIST TO WHICH THEY WERE NOT
SUBSCRIBED? ISN'T TECHNOLOGY WONDERFUL?

DAVID

>
> cooi0260@mail.usyd.edu.au wrote:
>> HI,
>>
>> I BEEN RECEIVING EMAIL FROM THIS dbi-users@perl.org FOR ALMOST 1 YEAR
>> AND I
>> DIDN'T SUBCRIBE FOR THIS SERVICE. ANY COULD ASSIST ME TO REMOVE THIS
>> EMAILL
>> ADDRESS COOI0260@MAIL.USYD.EDU.AU FROM THE MAILING LIST. I RECEIVE
>> HUNDRED
>> AND HUNDRED OF EMAIL FROM THIS SERVER THAT DOESN'T INTEREST ME AT ALL.
>>
>> COULD ANYONE TELL ME WHAT IS THE LINK OR STEP THAT I COULD REMOVE MYSELF
>> FROM THIS MAILING LIST, MY EMAIL HAVE EXPLODE MANY TIME DUE TO THE AMOUNT
>> OF EMAIL THAT I BEEN RECEIVING THROUGH THIS dbi-users@perl.org.
>>
>> THANK YOU.
>
>
> ------------------------------------------------
> Radan Computational Ltd.
>
> The information contained in this message and any files transmitted with
> it are confidential and intended for the addressee(s) only. If you have
> received this message in error or there are any problems, please notify
> the sender immediately. The unauthorized use, disclosure, copying or
> alteration of this message is strictly forbidden. Note that any views or
> opinions presented in this email are solely those of the author and do
> not necessarily represent those of Radan Computational Ltd. The
> recipient(s) of this message should check it and any attached files for
> viruses: Radan Computational will accept no liability for any damage
> caused by any virus transmitted by this email.


--
"It's overkill of course, but you can never have too much overkill."