in reply to Capturing SQL errors in Perl

Concurring with the RaiseError, placeholder, and code tag suggestions, let me also note that there's no need to call finish on DML statements (inserts and updates).

Here's what your code will look like if you follow the advice above:

my @fields = qw( ict_category ict_type ict_subtype ict_instance ict_assign2_grp ict_severity_lvl ict_date ); my @placeholders = map {'?'} @fields; { local $" = ','; $sqlwi = "INSERT INTO $ICT (@fields) VALUES(@placeholders)"; } $dbh->{RaiseError} = 1; eval { my $sth = $dbh->prepare($sqlwi); $sth->execute( $a_catg, $a_type, $a_styp, $a_inst, $a_agrp, $a_sevl, $dat3, ); }; if ($@) { # unable to insert, error message is in $@ ... }

Replies are listed 'Best First'.
Re^2: Capturing SQL errors in Perl
by Red_Dragon (Beadle) on Apr 18, 2008 at 11:30 UTC
    Thank you for investing in me, this example is most helpful, I appreciate it.