http://www.perlmonks.org?node_id=188269

axelrose has asked for the wisdom of the Perl Monks concerning the following question:

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.