As always, if this is the wrong mailing list or if this information
exists in a faq I have not found yet, please accept my apologies and
point me in the correct direction.

CLIENT BOX:
  RH Linux (kernel 2.4.3-12)
  Perl 5.6
  Freetds 0.52
  DBI/DBD::Sybase 0.91

Database Server/Box
  Win2000
  SQLServer 7

I have a stored procedure on the SQL Server7
that looks like,

CREATE PROCEDURE AddMe_Out
        @p1 int = 0,
        @p2 int OUTPUT
AS
        SELECT @p2 = 10 * @p1
GO


I can connect and run simple queries and call procedures
that don't send their output via an OUTPUT parameter.
I need to call a procedure (AddMe_Out) that DOES return
its results via OUTPUT.  I have the following code in which
the simple query, and the first procedure call work.  The second
call to the stored procedure 'AddMe_Out' fails with the
error ->"no statement executing at ./sql_test.pl line 38.
That is the fetch.
#----------------------------------------------------------
#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect("dbi:Sybase:server=www3", 'sqltest', 'spamspam', {PrintError => 
0});
unless ($dbh) { die "Unable for connect to server $DBI::errstr"; }


# Very simple select.
# this one works
$sth = $dbh->prepare("select * from authors");
if($sth->execute) {
    while(@dat = $sth->fetchrow)
        { print "@dat\n"; }
}

# a non-OUTPUT flavored call to a stored procedure
# this one works
print "\nCalling a stored procedure -> AddMe \n";
$sth_a = $dbh->prepare( "exec AddMe '43','3'");
if ($sth_a->execute) {
    do {
        while($d = $sth_a->fetch) {
            $id_value = $d->[0];
            print "VAL1: $id_value\n";
        }
    } while($sth_a->{syb_more_results});
}

# AddMe_Out
print "\nCalling a stored procedure -> AddMe_Out \n";
my $sth_b;
$sth_b = $dbh->prepare(
        "declare \@p2_output int
        exec AddMe_Out '3',  \@p2_output output") or
    die "Failed to prepare SQL statement", $sth_b->errstr(), "\n";

$sth_b->execute() or die "Failed to execute", $sth_b::errstr, "\n";

while ($data = $sth_b->fetch) { # line 38
    print "VAL2: $data\n"; # just trying to print anything
}
#----------------------------------------------------------

It appears that that the 'execute' is failing because the fetch
does not think $sth_b has anything to fetch.  I have checked the
stored procedure on the SQL Server via its native interface and
it works there.

Any ideas or comments would be greatly appreciated.

Thanks,
--
John Ulmer


Reply via email to