On Fri, 2002-06-21 at 10:42, Karyn Ulriksen wrote:
> I'd like to bookmark the mail archive site so that I don't have to go to the
> list to ask for the umpteenth million time what I know has been asked on
> this list...
> 
> I'm having problems with calling an MS SQL stored procedure via DBI (using
> FreeTDS DBD::Sybase).
> 
> I've tried the following formats:
> 
> $dbh->do("execute myprocedure $param1 $param2");
> $dbh->do("execute myprocedure $param1, $param2");

When executing SQL code via DBD::Sybase it pays to remember that we
essentially send the SQL buffer to the server for processing, and then
retrieve the results, whatever they may be.

So the syntax for the SQL (i.e. the bit between the quotes :-) is almost
always the same as the one you'd use in an interactive SQL tool (isql
for Sybase - don't know what MS-SQL has).

Next you need to consider what sort of data your procedure returns. do()
is normally used for statements that don't return any rows.

So the generic way to execute a stored procedure for Sybase and/or
MS-SQL via DBD::Sybase, and to be sure that *all* results have been
retrieved, goes like this:

my $sth = $dbh->prepare("exec my_proc $param1, $param2, ...");
$sth->execute;
do {
    while(my $row = $sth->fetch) {
         .... here you handle the data in $row ....
    }
} while($sth->{syb_more_results});

The DBD::Sybase man page also explains some of this.

As for the scarcity of Sybase or MS-SQL related information on the web -
well unfortunately Sybase isn't as popular as it once was. Another
possibility is that the Sybase way of handling stored procedures is
actually quite simple - there is no logical difference between executing
a stored procedure or executing any other SQL batch, so there isn't
really that much need for extra documentation...

Michael
-- 
Michael Peppler / [EMAIL PROTECTED] / http://www.mbay.net/~mpeppler
[EMAIL PROTECTED] / ZetaTools, Inc / http://www.zetatools.com
ZetaTools: Call perl functions as Sybase stored procedures!

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to