PDA

View Full Version : DB2/win32: Raiseerror and $handle->errstr()


BoL
11-27-02, 12:41
Hello,

I use
$x->execute() or
print 'Error:',$dbh->errstr();
to show an error to my user.
but the error is always:
[IBM][CLI Driver] CLI0125E Function sequence error. SQLSTATE=HY010

If I want to see the real errormessage I have to initialize my DB2 connection with 'RaiseError => 1'.
But now the script stops and show me the error without running the rest of my script :(
on the website I see now:
Software error:
DBD::DB2::db prepare failed: [IBM][CLI Driver][DB2/NT] SQL0104N
with Problemdescription ...

all I want ... BUT the script stopps!!

Can I get these detailed errormessage without stopping of my script??
And how can I get this?

Paul
12-06-02, 18:40
Wrap the call in an 'eval' and then check for $@

like so:

sub db_execute {
my $sql = $_[0];
my $ignore_when_fail = $_[1];
eval { $dbh->do($sql) };
if ($@) {
if(defined($ignore_when_fail)) {
print "\nQuery failed:\n$sql\n\n$@";
return 0;
} else { die "\nQuery failed:\n$sql\n\n$@"; }
}
return 1;
}

BoL
12-11-02, 05:07
thanks ...