http://qs321.pair.com?node_id=579546

iguanodon has asked for the wisdom of the Perl Monks concerning the following question:

I just inherited a project where I need to call DB2 stored procedures from Perl. Is it possible to get the return value of DB2 stored procedures with DBD::DB2? What I'm seeing is that I can bind an in/out parameter to the return value, but it never gets populated. For example the procedure call

... my $sth = $dbh->prepare("{?=call some_procedure(?, ?, ?)}"); $sth->bind_param_inout(1, \$status, 20); $sth->bind_param(2, $foo); $sth->bind_param_inout(3, \$bar, 20); $sth->bind_param_inout(4, \$baz, 20); ...

will run with no error, and the two out parameters (3 and 4) will be populated. But the return value of the procedure (parameter 1) is never set, it will contain whatever $status was initialized with.

The procedure definitely returns a value, I can see it in the DB2 procedure debugger, and I'm able to get the return value if I call the procedure from JDBC, so it must be the DBD::DB2 driver that isn't returning the value. This is a bummer because our Java programs rely on the return value to tell whether the procedure call was successful. I'd like the Perl code to work the same way. I could work around this in Perl by returning the the status in another out parameter or by just verifying that all of the out parameters contain valid data but I'd rather be able to just get the procedure return value if possible.

I'm using DBD::DB2 version 0.78 which I realize is rather old but upgrading will require a lot of regression testing, and I don't see anything in the docs for the latest DBD::DB2 version to suggest that it would behave differently with respect to handling of the return value. I'll try the latest DBD::DB2 on a different box but I thought it would be worth asking here first.