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.