What is the proper return value of $dbh->prepare() if the prepare fails?
The primary documentation (CPAN <http://search.cpan.org/%7Etimb/DBI/DBI.pm#prepare> and perldoc DBI) don't say. The most seemingly authoritative source <http://www.perl.com/pub/a/1999/10/DBI.html> 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
Description: Perl program



Reply via email to