
1arryb
User
Mar 3, 2009, 7:38 AM
Post #4 of 4
(1898 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)
|