CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
How to get error code?

 



tabarry
New User

Mar 2, 2009, 9:16 PM

Post #1 of 4 (2911 views)
How to get error code? Can't Post

I need to catch the error number/error code when my query gives an error. Can anyone let me know how to do it?

The following returns error string, which is NOT what I want.

$DBI::errstr

Thanks


FishMonger
Veteran / Moderator

Mar 2, 2009, 10:48 PM

Post #2 of 4 (2909 views)
Re: [tabarry] How to get error code? [In reply to] Can't Post

It's been awhile since I used this, so I'm not sure if it's a booleon flag or the sql error code, but try $DBI::err


tabarry
New User

Mar 3, 2009, 2:17 AM

Post #3 of 4 (2904 views)
Re: [FishMonger] How to get error code? [In reply to] Can't Post

Thanks, but it is a booleon flag.


1arryb
User

Mar 3, 2009, 7:38 AM

Post #4 of 4 (2901 views)
Re: [tabarry] How to get error code? [In reply to] Can't Post

Hi tabarry,

I also have never had any luck getting the db error codes using DBI::err(). I get the feeling that the quality of the data provided by this call is dbms (or at least DBD::<dbms> module) dependent. All production code I've seen uses DBI::errstr() and parses the string in the error handler.

Usually, I don't bother. I just check to see if I got the result I wanted. Generally, I've found that the db error codes are useful only during post-mortems, when you're trying to figure out what went wrong with your program.

Also, just because your db didn't return an error code doesn't mean you got the result you wanted. So the whole issue of db error codes has to be wrapped in a strategy for dealing with invalid/undesirable query results.

Having said that, both approaches are valid, depending on whether it's ok for your program to die:
1. Check for db errors after each call, either by connect(RaiseError =>1) + eval {}; if ($@) {} OR connect(RaiseError => 0) + DBI::errstr(); or
2. connect(RaiseError => 1, PrintError => 1) and let the program die.

Cheers,

Larry


(This post was edited by 1arryb on Mar 3, 2009, 7:45 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives