in reply to SQL Stored Procedure return value

One of the things that always bothers me about Sybase (I know ... I know, some people really really like it) is multiple result sets ... they just make me feel icky. Try:

do { while($d = $sth->fetch) { ... do something with the data } } while($sth->{syb_more_results});

You can also skip over result sets you know are not going to have anything by looking at $sth->{syb_result_type}. It's all in DBD::Sybase. And with all things DBD and Sybase, if mpeppler answers, listen to him first.

-derby

Replies are listed 'Best First'.
Re (2): SQL Stored Procedure return value
by VSarkiss (Monsignor) on Jul 17, 2003 at 18:01 UTC

    Output parameters are not returned like a result set. While this is technically a correct answer, it's for a different question. ;-)

      Sure they are. From the DBD::Sybase docs (which also gives the shortcut you've shown in another node):

      If your stored procedure only returns OUTPUT parameters, then you can use this shorthand: $sth = $dbh->prepare('...'); $sth->execute; @results = $sth->func('syb_output_params'); This will return an array for all the OUTPUT parameters in the proc call, and will ignore any other results. The array will be undefined if there are no OUTPUT params, or if the stored procedure failed for some reason. The more generic way looks like this: $sth = $dbh->prepare( "declare \@id_value int, \@id_name exec my_proc @name = 'a string', @number = 1234, @id = @id_value OUTPUT, @out_name = @id_name OUTPUT" ); $sth->execute; do { while($d = $sth->fetch) { if($sth->{syb_result_type} == 4042) { # it's a PARAM result $id_value = $d->[0]; $id_name = $d->[1]; } } } while($sth->{syb_more_results});

      update: Unless of course this is one of those odd little areas where SQLServer and Sybase differ.

      -derby

        Your initial answer only showed retrieving multiple result sets -- the ... was leaving out something important, which your later example showed.

        And I stand by my statement: DBD::Sybase makes output parameters appear to be part of a result set, but in fact they are handled differently by the SQL Server API.

Re: Re: SQL Stored Procedure return value
by mpeppler (Vicar) on Jul 17, 2003 at 19:14 UTC
    I love multiple result sets :-)

    Michael