Unfortunately, yes, rows() certainly can and will be greater than zero
for the last fetch() when one or more rows are returned since it is
reporting how many rows where fetched overall by the database query, not
the last DBI call.
I believe it is impossible to use rows() after a single fetch() to
determine whether no not the fetch() returned a row.
The return value from fetch() when defined does:
*fetchrow_arrayref <http://search.cpan.org/%7Etimb/DBI/DBI.pm#___top>*
$ary_ref = $sth->fetchrow_arrayref;
$ary_ref = $sth->fetch; # alias
Fetches the next row of data and returns a reference to an array
holding the field values. Null fields are returned as |undef| values
in the array. This is the fastest way to fetch data, particularly if
used with |$sth->bind_columns|.
If there are no more rows or if an error occurs, then
|fetchrow_arrayref| returns an |undef|. You should check |$sth->err|
afterwards (or use the |RaiseError| attribute) to discover if the
|undef| returned was due to an error.
Note that the same array reference is returned for each fetch, so
don't store the reference and then use it after a later fetch. Also,
the elements of the array are also reused for each row, so take care
if you want to take a reference to an element. See also
"bind_columns" <http://search.cpan.org/%7Etimb/DBI/DBI.pm#bind_columns>.
- philip
John Siracusa wrote:
On 8/8/07 10:55 AM, Philip Dye wrote:
$rv = $sth->rows;
Returns the number of rows affected by the last row affecting
command, or -1 if the number of rows is not known or not available.
In SVN, I changed in from:
if($rows > 0)
to
if($rows > 0 || $rows == -1)
which should cover all bases...unless some DBD returns -1 when zero rows are
found? Hrm...
-John
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object