Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Bug #681 Oracle numRows() now returns -1 if no row
Submitted: 2004-02-04 15:45 UTC
From: thierrybo Assigned: lsmith
Status: Closed Package: MDB
PHP Version: 4.3.2 OS: Win32 XP
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 20 - 12 = ?

 
 [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

Comments

 [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-07 22:24 UTC] lsmith
This is actually very hackish. For all databases that support numRows() natively they actually buffer the entire result set. MDB emulates this properly instead of sending off another query. The problem is obviously that the buffering is not trivial and the way its implemented in MDB is also somewhat difficult. I am working on a fix, I hope to have it done by tomorrow .. bit busy atm :-/
 [2004-02-15 16:28 UTC] lsmith
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.
 [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
 [2004-02-25 17:23 UTC] lsmith
hmm seems like the bug was not reopened .. anyways I fix it so now hopefully it can stay closed