I want to test and see if a select statement was executed. with DBD::mySQL I have been able to use
$sth->execute; if ($sth->errstr) { die "Failed to execute ($stmt) - ", $sth->errstr(), "\n"; }
When I tried this with DB2 the script is not dropping into the if statement.
use 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";
here is the output
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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.