Jordan

You can try the following

my $sth = $dbh->prepare(" SELECT no_such_column FROM schema.table");
if (DBI->err lt 0) {
    warn "SQL Error!\n";
} else {
    warn "All is well.\n";
}

You can also reach Perl Component Owners for DBD::DB2 by mailing to 
opendev (AT) us (DOT) ibm (DOT) com


Thanks and Regards, 

Tarun  Pasrija 
System Software Engineer 
Open Source - Common AD 
India Software Labs - IBM India Pvt Ltd. 
Tel(Off)    +91 80 402 55265 
Tel(Mob)   +91 9972200221 
  My Profile 
  My Blog  
  My Wiki 
  My Cattail 






From:
Jordan Macdonald <[email protected]>
To:
[email protected]
Date:
08/07/2009 03:01 PM
Subject:
Return value of $dbh->prepare() on error



What is the proper return value of $dbh->prepare() if the prepare fails? 
The primary documentation (CPAN and perldoc DBI) don't say. The most 
seemingly authoritative source I can find says that it should return 
undef, and this is buoyed out by multiple examples from various locations 
which test for the failure of my $sth = $dbh->prepare($sql); using if 
(!$sth) or if (!defined($sth)).
However, the behaviour of the test program (attached) shows it returning 
what appears to be the statement handle for a null statement:
DBD::DB2::db prepare failed: [IBM][CLI Driver][DB2/LINUX] SQL0204N 
"SCHEMA.TABLE" is an undefined name.  SQLSTATE=42704
All is well.
$VAR1 = bless( {}, 'DBI::st' );
What is the correct behaviour? And what is the correct way to test for the 
failure of my $sth = $dbh->prepare($sql);?
[attachment "tmp.pl" deleted by Tarun Pasrija1/India/IBM] 

<<image/jpeg>>

<<image/gif>>

<<image/jpeg>>

<<image/jpeg>>

<<image/jpeg>>

Reply via email to