Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: DBI selectall_arrayref

by jeffa (Bishop)
on Sep 02, 2004 at 17:18 UTC ( [id://388002]=note: print w/replies, xml ) Need Help??


in reply to Re: DBI selectall_arrayref
in thread DBI selectall_arrayref

I find it almost ironic that you mention error checking each query when you quote "If 'RaiseError' is not set ..."

Well, why not just set RaiseError and never need worry about explicitly die'ing yourself? Barring that you are underneath miles of framework and child processes, of course -- but for most everyday uses, this is all you need do:

my $dbh = DBI->connect($ds, $user, $pass, {RaiseError => 1});
Look into HandleError as well.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^3: DBI selectall_arrayref
by davido (Cardinal) on Sep 03, 2004 at 00:04 UTC

    My point is that some error checking needs to be done, and none was being done. If the method is the RaiseError flag, so be it. But something's got to be in place or you'll never know if the DB is connecting, if the statement handles are being prepared and executed, and so on. The irony is that I discussed the more common Perl idiom (or die ...) instead of the more DBI'ish idiom (RaiseError).


    Dave

      ... or you'll never know if the DB is connecting

      Technically speaking, well yes, you could know if the DB is connecting without causing the script to die. If connect() fails, a warning via STDERR is emitted but your script still runs. By specifying {RaiseError => 1}, DBI will, by default, "throw" a die for you, but you can still see why the connect failed without having to explicitly or die $DBI::errstr or use {RaiseError => 1}.

      Finally, telling a "newbie" to go back and add error checking usually results in statements like "I just want to get it to work." That's why i recommend {RaiseError => 1} up front, you only need to add one line of code for error checking across the board. I'm just nitpicking Dave ... you and your point for some error checking are gold. :)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-23 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found