Skip to Content.
Sympa Menu

freetds - Re: [freetds] DBD::Sybase doesn't return number of rows affected

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Michael Peppler <mpeppler AT peppler.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] DBD::Sybase doesn't return number of rows affected
  • Date: Fri, 16 Apr 2010 06:52:31 +0200

On Apr 16, 2010, at 4:26 AM, Srdan Dukic wrote:

> On 16 April 2010 04:35, Robert Gonzalez <robert AT robert-gonzalez.com> wrote:
>
>> I think that might actually actually be the way that MSSQL returns true
>> values. I ran into this once in a script I was working on where I was
>> expected a 1 returned for success but got back a -1. Not sure why it does
>> that, but in almost every case where I expected a boolean true value
>> expressed as an int I got a -1 in return. Stupid, I know, but manageable
>> when you know what to expect.
>>
>
> Woops. I just realised that I made a mistake in describing the problem. The
> code returns the correct number of rows on insert statements, but when I do
> a select statement:
>
> ...
> $query = "SELECT * FROM Simple.dbo.test";
> $sth = $dbh->prepare ($query) or die 'prepare failed\n';
> $sth->execute() or die "unable to execute query $query error $DBI::errstr";
>
> $rows = $sth->rows ;
> print "$rows rows returned by query\n";
> .....
>
> It outputs:
>
> -1 rows returned by query
>
> Not sure if this is intended behaviour (i.e. there is another way to get the
> number of rows returned) or a bug.
>

This is the expected behavior. There is no way to know the number of rows
that a query *will* return until all the rows have been fetched, because rows
could be added or deleted from under the query engine while it is processing
the query (the tables aren't locked for the duration of the query!)

Michael
--
Michael Peppler
Sybase on Linux FAQ: http://www.peppler.org/FAQ/linux.html

"A successful [software] tool is one that was used to do something undreamed
of by its author." -- S. C. Johnson










Archive powered by MHonArc 2.6.24.

Top of Page