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

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Dear Monks,

I need some help with DBI:

My strategy is to use RaiseError=>1 and define a general die handler like this

use strict; use DBI; use Carp ('verbose'); ... my $dbh = DBI->connect( $dsn, $username, $password, $options ) or die "cannot connect to '$dsn'\n"; $dbh->{HandleError} = sub { warn $DBI::errstr; # how to display the last statement ?? Carp::confess }; ... my $insstm = "insert into mytable values ( ?, ? )"; my $inssth = $dbh->prepare( $insstm ); for ( 1..3 ) { $inssth->execute( myseq.nextval, $_ ); }
First the confess messages are somehow shortened like this:
main::__ANON__('DBD::Oracle::st execute failed: ORA-01722: UngM-|ltige Zahl (DBD E...', 'DBI::st=HASH(0x820cacc)', undef) called at insert-test.pl line 61
To facilitate debugging I need to see the actual statment executed. How can I achieve this?

Thanks very much for your time,
Axel.

In reply to DBI HandleError statement display by axelrose

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.