Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
      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 making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2015-11-29 11:01 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls