On Fri, Sep 02, 2005 at 05:37:57PM -0500, johnnnnnn wrote:
> Capacio, Paula J wrote:
> 
> >my $stmt = 'select count(*) from sysibm.badTblnm ';
> >my $sth = $dbh->prepare($stmt) or die "Prepare Failed\n";
> 
> DBD::DB2 doesn't seem to return false values for failures.

If that's true then it's broken.

It may just be that the prepare() doesn't send the sql to the server
until it's execute()'d - so any sql errors won't be noticed till then.

That's quite common across many drivers (as it saves round-trips to the
server) and is, I think, mentioned in the DBI docs from prepare().

Tim.

> Instead, try 
> checking the sqlstate of the db handle:
> 
> my $sth = $dbh->prepare($stmt);
> if ($dbh->state()) {
>  die "Prepare Failed: " . $dbh->{errstr} . "\n";
> }
> 
> 
> ->state() is available on db handles and statement handles, and contains 
> the five-character sqlstate code.
> 
> Hope that helps.
> 
> -johnnnnnnnn
> 

Reply via email to