Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: want to skip displaying of "DBD::Oracle::st execute failed:" error messages showing full query

by boftx (Deacon)
on Apr 07, 2015 at 17:04 UTC ( [id://1122719]=note: print w/replies, xml ) Need Help??


in reply to want to skip displaying of "DBD::Oracle::st execute failed:" error messages showing full query

Simply wrap your execute statement in an eval block and catch the error. (I'd say use Try::Tiny but it doesn't play nice with DBI, at least for me.)

eval { $sth->execute(); ... }; if ( $@ ) { # log the full error message write_log( $sth->errstr ); # and re-throw the common message die 'HEY!!!! Something is messed up here!'; }
By all means keep RaiseError => 1 and PrintError => 0 for this to work.

EDIT:

On a side note, it is extremely poor practice (and bad security) to interpolate values directly into the SQL statement. Use placeholders instead and supply the values as params to the execute statement instead.

my $sql = q{INSERT INTO mytable VALUES ( ?,?,? )}; eval { $dbh->do( $sql, undef, ($val1, $val2, $val3) ); }; if ( $@ ) } # error trapping here ... }

You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^2: want to skip displaying of "DBD::Oracle::st execute failed:" error messages showing full query; Try::Tiny
by Anonymous Monk on Apr 07, 2015 at 21:39 UTC

    What problems did you encounter when using Try::Tiny (to catch DBI errors)?

      I'll have to go back and find a copy of the offending code and sanitize it. It is now accepted practice at $work to use eval for DBI operations, and Try::Tiny for everything else.

      You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

        Thankyou all for your help :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found