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: Re: [tabarry] How to get error code?: Edit Log



1arryb
User

Mar 3, 2009, 7:38 AM


Views: 2379
Re: [tabarry] How to get error code?

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)


Edit Log:
Post edited by 1arryb (User) 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