Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: dbi error handling

by erix (Vicar)
on Dec 21, 2010 at 00:24 UTC ( #878127=note: print w/ replies, xml ) Need Help??


in reply to dbi error handling

select count(*) from table will always have at least one row: an empty table will give 0. (Of course, the table must exist, and the $dbh must be valid).

selectrow_array is just a convenience (it does a combined prepare + execute) for just this kind of SQL where you can be sure there will not be too many rows.

I'd say RaiseError => 1 is indeed the best and easiest way.


Comment on Re: dbi error handling
Replies are listed 'Best First'.
Re^2: dbi error handling
by runrig (Abbot) on Dec 21, 2010 at 17:02 UTC
    I've started the habit of using:
    HandleError => sub { Carp::confess($_[0]) },
    in my connect() code. I started doing this because some versions of DBD::Sybase don't report the line number of the error with just RaiseError set (because the error messages had a newline on the end of them). Also, it's just nice to have a stack trace when a DBI call fails from deep within your function calls.
      Could you explain that a little bit more (I'm a perl beginner) please? Where does that code go? thanks
      I've seen this in the dbi docs
      http://search.cpan.org/~timb/DBI-1.615/DBI.pm#HandleError
      What data is in $_[0]
        Huh, I didn't see that in the docs before (or forgot about it). $_[0] is the first argument to the function, i.e. the first element of the @_ array.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-07-29 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls