Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: DBI fails to return an error code

by mje (Deacon)
on Oct 05, 2011 at 16:56 UTC ( #929840=note: print w/ replies, xml ) Need Help??


in reply to Re: DBI fails to return an error code
in thread DBI fails to return an error code

I'm not entirely sure you are right when you suggest there is a separate err/errstr for each handle. I believe there is only one despite it looking like there is one per handle via the pod.

perl -le 'use strict; use warnings; use DBI; my $h = DBI->connect("dbi +:mysql:database=test", "xxx","yyy", {RaiseError => 0, PrintError => 0 +}) or die $DBI::errstr; my $s = $h->prepare(q/select * from does_not_ +exist/) or die "prepare: " . $DBI::errstr; $s->execute or print "\nex +ecute DBI:" . $DBI::errstr . " sth:", $s->errstr . " dbh:", $h->errst +r; $h->do(q/rubbish/) or print $s->errstr, "\n"; execute DBI:Table 'test.does_not_exist' doesn't exist sth:Table 'test. +does_not_exist' doesn't exist dbh:Table 'test.does_not_exist' doesn't + exist You have an error in your SQL syntax; check the manual that correspond +s to your MySQL server version for the right syntax to use near 'rubb +ish' at line 1

Notice you get the same error from DBI, dbh and sth. Also, if you error on a dbh you can access the same error from the sth. I have this recollection from a dbi-dev posting from way back I could probably dig out.


Comment on Re^2: DBI fails to return an error code
Download Code
Re^3: DBI fails to return an error code
by Neighbour (Friar) on Oct 06, 2011 at 08:27 UTC
    Initially, all errors are set in $DBI::err. However, since all actions involving DBI (which can be from multiple DBI-sources, multiple databases, multiple queries using the same $dbh, $DBI::err will be overwritten quite a lot.
    To avoid getting an error that is generated by an entirely different bit of code (which runs in another thread/process but shares the DBI environment, or even the $dbh), it is recommended to use the handle with the smallest scope (because that way you can be sure to a much better degree that nothing else has overwritten your errorcode/errorstring).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-09-23 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls