Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
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 rifling through the Monastery: (6)
As of 2014-07-12 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls