CREATE FUNCTION FUNC_JUST_RETURN_IT(i int)
RETURNS int
NO EXTERNAL ACTION
DETERMINISTIC
RETURN i
@
####
-- execute directly
SELECT DB2INST1.FUNC_JUST_RETURN_IT(42)
FROM SYSIBM.SYSDUMMY1
####
-- prepare, then execute later
SELECT DB2INST1.FUNC_JUST_RETURN_IT(?)
FROM SYSIBM.SYSDUMMY1
####
use strict;
use warnings;
use DBD::DB2;
use DBD::DB2::Constants;
use Test::More;
plan q/no_plan/; # I'm the man with no plan ..
sub DBSETUP_PARAMS {
return ('DBI:DB2:viper', 'db2inst1', '*****');
}
# Call function with unbound value
sub call_func_nobind {
my $cardno = shift;
my $rv = undef;
my $dbh = DBI->connect(DBSETUP_PARAMS());
die(q{Connect failed!}) if (!defined($dbh));
my $sth =
$dbh->prepare(
qq{SELECT DB2INST1.FUNC_JUST_RETURN_IT($cardno) FROM SYSIBM.SYSDUMMY1});
die(q{Prepare failed!}) if (!defined($sth));
$sth->execute() or die (q{execute failed});
die(q{Execute failed!}) if (!defined($sth));
my $row = $sth->fetchrow_arrayref();
($row) ? $row->[0] : undef;
}
# Failing attempt to call function with bound value
sub call_func_bind {
my $cardno = shift;
my $rv = undef;
my $dbh = DBI->connect(DBSETUP_PARAMS());
die(q{Connect failed!}) if (!defined($dbh));
my $sth =
$dbh->prepare(qq{SELECT DB2INST1.FUNC_JUST_RETURN_IT(?) FROM SYSIBM.SYSDUMMY1});
die(q{Prepare failed!}) if (!defined($sth));
$sth->bind_param(1, $cardno);
die(q{bind_param failed!}) if (!defined($sth));
$sth->execute() or die (q{execute failed});
die(q{Execute failed!}) if (!defined($sth));
my $row = $sth->fetchrow_arrayref();
($row) ? $row->[0] : undef;
}
# ------ main ------
cmp_ok(call_func_nobind(q{123456}), q{==}, 123456, q{Expect 123456 returned});
cmp_ok(call_func_bind(q{123456}), q{==}, 123456, q{Expect 123456 returned});
1;
__END__
####
$ /usr/bin/perl -w call.function.pl
ok 1 - Expect 123456 returned
DBD::DB2::db prepare failed: [IBM][CLI Driver][DB2/LINUX] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
DBD::DB2::st execute failed: [IBM][CLI Driver][DB2/LINUX] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
execute failed at call.function.pl line 48.
1..1
# Looks like your test died just after 1.
$