Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

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
      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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2016-10-21 13:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.