PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB » Bug #681

Oracle numRows() now returns -1 if no row

Details

Submitted2004-02-04 15:45 UTC
Fromthierry dot bo at netcourrier dot com
Assignedlsmith
StatusClosed
PackageMDB
PHP Version4.3.2
OSWin32 XP
Roadmaps(Not assigned)

Comments

[2004-02-04 15:45 UTC] thierry dot bo at netcourrier dot com

Description:
------------
Using MDB1 latest CVS, recent bug fix #633 and #670 creatad a new bug for Oracle. Now Oracle numRows returns -1 if there is no row in the result set, instead of 0, thus breaking code compatibility with other drivers.

Reproduce code:
---------------
$res = $mdb->query("SELECT * FROM MTABLE");
$counte = $mdb->numRows($res);

Expected result:
----------------
$counte == 0 if no row

Actual result:
--------------
$counte = -1

[2004-02-07 00:45 UTC] thierry dot bo at netcourrier dot com

Hi,

I don't know how works the overall MDB api, so the following code may contains stupid things, but here is what I did.
As I seen the oci8 numRows() function in DB was quite more simple than MDB one, I tried to use DB code instead in MDB numRows(). With just little changes from DB, here is what I use now:

function numRows($result)
{
if ($this->options['optimize'] == 'portability') {
$countquery = "SELECT COUNT(*) FROM (".$this->last_query.")";
$save_query = $this->last_query;
$count = $this->query($countquery);
if (MDB::isError($count) ||
MDB::isError($row = $this->fetchRow($count, MDB_FETCHMODE_ORDERED)))
{
$this->last_query = $save_query;
return $this->raiseError(MDB_ERROR_NOT_CAPABLE);
}
return $row[0];
}
return $this->raiseError(MDB_ERROR_NOT_CAPABLE);
}

For the moment it works with my current application.

[2004-02-19 00:07 UTC] thierry dot bo at netcourrier dot com

Hi,

sorry to open this bug again, but this does not works ever for me. Now the function always returns 0, whatever the number of rows.

It seems in the last line of the function :

return(max(0, $this->highest_fetched_row[$result_value];

that the return code is based on a varaible ($this->highest_fetched_row[$result_value]) that is never used or set before inside this function. So in all case it is -1.

Thierry Bothorel