in reply to (jeffa) Re: Script does not die when DB connection fails
in thread Script does not die when DB connection fails

Why not check the return code from both prepare and execute. On many database systems prepare will attempt to compile the SQL and will return details of syntax errors.

And rather than checking the return code from every DBI call, why not set the RaiseError attribute when connecting to the database.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

  • Comment on Re: (jeffa) Re: Script does not die when DB connection fails

Replies are listed 'Best First'.
(arturo) Re: Script does not die when DB connection fails
by arturo (Vicar) on May 25, 2001 at 18:09 UTC
    ... why not set the RaiseError attribute when connecting to the database.

    Here, one reason not to do that is that you've got a custom dienice routine you want to call when database calls fail. Now, you *could* redirect errors by setting $SIG{__DIE__}, to point to your dienice routine, but as a couple of wise monks pointed out to me, that could wreak havoc if any modules you've imported contain dies in eval blocks.

    There are two solutions that I can think of that recommend themselves: either keep RaiseError set to false and do all your error checking manually, calling dienice, OR wrap all your DB calls in eval blocks and call dienice with the contents of $@ if it is set (i.e. the standard Perl exception-handling mechanism).

    HTH.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'