[freetds] empty results on multiple step query

Adrian Lattke adrian at techonline.com
Sat Jul 3 13:45:47 EDT 2004


Thanks for your response Michael. 
 
My changes will work for my code because all of my queries return a single result-set, even if they run multiple statements in the same query. I don't think it's good practice when using fetchall_arrayref, to run a query with multiple results-sets.
 
Again, thank you all.
 
-Adrian Lattke

________________________________

From: freetds-bounces at lists.ibiblio.org on behalf of Michael Peppler
Sent: Sat 7/3/2004 11:59 AM
To: FreeTDS Development Group
Subject: RE: [freetds] empty results on multiple step query



On Sat, 2004-07-03 at 17:45, Adrian Lattke wrote:
>  
> Now, I have a different problem on my hands... 4043 will be returned
> if I am fetching a row at a time, but what if I want to return the
> entire result-set?

>     ## Prepare and execute query
>     ($query = $dbh->prepare("set rowcount 0
>                              set TEXTSIZE 128000
>                              $sql"))

This is at least three queries, more depending on what is in $sql.

This means that to fetch the results you must loop, like this:

do {
    $return = $query->fetchall_arrayref();
    ... do something with $return....
} while($query->{syb_more_results});

assuming that fetchall_arrayref() actually does the right thing (I have
to admit that I've never used it, and haven't verified that it does what
it is supposed to do with DBD::Sybase.)

> I have modified my original function, like this:
> 
> ##############################################################
> sub run_sql {
>    ...
>     ## Are results expected?
> #       $return = $query->fetchall_arrayref();
> #       if ($DBI::err)
> #       {
> #           return(0, "Cannot get results: $DBI::errstr");
> #       };
>         while ($return = $query->fetchall_arrayref())
>         {
>             if ($DBI::err)
>             {
>                 return(0, "Cannot get results: $DBI::errstr");
>             };
>             if ($query->{syb_result_type} == 4046)
>             {
>                 return (1, "", $return);
>             }
>         }
>     };
>    ...
> };
> ##############################################################
> 
> Now it all works fine. I thought I should post this in case someone
> else comes accross the same problem.

While this works for you, now, you should be careful about this.

You should really use a loop and check the syb_more_results attribute to
make sure that you really pull back all of the results from your query.

Michael





More information about the FreeTDS mailing list