Skip to Content.
Sympa Menu

freetds - RE: [freetds] empty results on multiple step query

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Adrian Lattke" <adrian AT techonline.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] empty results on multiple step query
  • Date: Sat, 3 Jul 2004 13:45:47 -0400

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






Archive powered by MHonArc 2.6.24.

Top of Page