When I tried this with DB2 the script is not dropping into the if statement.$sth->execute; if ($sth->errstr) { die "Failed to execute ($stmt) - ", $sth->errstr(), "\n"; }
here is the outputuse strict; use DBI; use DBD::DB2; my $db2_user = 'USER'; my $db2_pass = 'PASSWORD'; my $dbh = DBI->connect('dbi:DB2:DB2', $db2_user, $db2_pass, {AutoCommi +t => 0, RaiseError => 0, PrintError => 1}) or die "Cant connect to D +B - $DBI::errstr\n"; my $stmt = "select ID from RULE where key = 123"; my $sth = $dbh->prepare($stmt) or die "Cant prepare ($stmt) - $DBI::er +rstr\n"; $sth->execute or die "Cant execute ($stmt) - $DBI::errstr\n"; if ($sth->errstr) { die "Failed to execute ($stmt) - ", $sth->errstr(), "\n"; } print "the execute should have failed before here\n"; my $col1; $sth->bind_col(1,\$col1); while ($sth->fetch) { print "id is: $col1\n"; } print "should not get here\n"; $sth->finish() or die "Cant close sth - $DBI::errstr\n"; $dbh->disconnect() or die "Cant disconnect from DB - $DBI::errstr\n";
C:\PerlScripts>test.pl the execute should have failed before here DBD::DB2::st fetch failed: [IBM][CLI Driver][DB2] SQL0904N Unsuccessf +ul execution caused by an unavailable resource. Reason code: "00C900 +81", type of resource : "00000200", and resource name: "SHTDB038.SHTT09Z1". SQLSTATE=57011 should not get here C:\PerlScripts>
In reply to DB2 checking for an error on select by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |