I'm calling some stored procedures using DBI 1.32, DBD::ODBC 1.07 and
Perl v5.8.0 (ActivePerl build 805) running on Win2kServer SP4 using
MS SQL 2000.
Am I supposed to initialize the variables I pass to
bind_param_inout()?
I'm using code like this to prepare and call the stored procedures
and fetch the OUTPUT parameters:
sub prepare_sps {
$sp{GetLocationInfo_p}
= $db->prepare('EXEC dbo.GetLocationInfo '. join(', ',('?') x 5));
# parameters 2-5 are OUTPUT!
{
my ($JobCity, $JobState, $JobCountry, $JobZIP)
= ( " "x 50, " "x 50, " ", " "x 5);
my $sp = $sp{GetLocationInfo_p};
$sp->bind_param_inout(2, \$JobCity, 50, DBI::SQL_VARCHAR);
$sp->bind_param_inout(3, \$JobState, 50, DBI::SQL_VARCHAR);
$sp->bind_param_inout(4, \$JobCountry, 2, DBI::SQL_CHAR);
$sp->bind_param_inout(5, \$JobZIP, 5, DBI::SQL_CHAR);
$sp{GetLocationInfo} = sub {
$sp->bind_param(1, $_[0]);
$sp->execute();
$_[1] = $JobCity;
$_[2] = $JobState;
$_[3] = $JobCountry;
$_[4] = $JobZIP;
s/^\s+//,s/\s+$// for ($_[1..4]);
}
};
...
}
...
$sp{GetLocationInfo}->($jobLocationId, $JobCity, $JobState,
$JobCountry, $JobZIP);
The stored proc looks like this:
CREATE PROCEDURE dbo.GetMonsterLocationInfo(
@LocationID Int,
@City varchar(50) OUTPUT,
@State varchar(50) OUTPUT,
@Country char(2) OUTPUT,
@Zip char(5) OUTPUT
) AS
BEGIN
SELECT @Zip = ZipCode, @State = State, @Country = Country, @City =
MappedCity
FROM dbo.LocationLookup WITH (NOLOCK)
WHERE ID = @LocationID
END
The problem is that if I do not initialize the $JobXxxx variables
with those spaces:
my ($JobCity, $JobState, $JobCountry, $JobZIP)
= ( " "x 50, " "x 50, " ", " "x 5);
I only get the first letters of the values. Once I do initialize the
variables I do get the right and complete values even in a loop, even
if the value in a later iteration is longer than the one in a
previous.
I do get the same incorrect results if the variables are undef or "".
Why is that? Is this something I missed in the docs? Or is it a bug
in DBD::ODBC? Or ...?
Thanks, Jenda
== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
I wonder why the whole chemistry industry ignores
computer bugs. We all would gladly pay big bucks
for a functional insecticide.