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

Bug #946 OCIFetchInto:ORA-01002:fetch out of sequence if numrows() called before
Submitted: 2004-03-04 14:23 UTC
From: thierrybo at freesurf dot fr Assigned: lsmith
Status: Closed Package: MDB
PHP Version: 4.3.2 OS: win32XP
Roadmaps: (Not assigned)    
Subscription  


 [2004-03-04 14:23 UTC] thierrybo at freesurf dot fr
Description: ------------ [oci8.php 1.21.4.15] Hi, since recent updates, seems bug #633 is back. I got the error "OCIFetchInto:ORA-01002:fetch out of sequence" if I just call fetchInto() after numRows() (yes, I now removed all numrows from my code where I just want to know if there are any rows and replaced them with fetchInto, but it remains places where I really need to know!). Here is an example with assuming there is only one row in the result set. The $rownum is not reset to 0 when I call fetchInto after numRows. When I leave numRows, variable: $this->highest_fetched_row[$result_value] == 1 Entering fetchInto, line 1532 $rownum == 2 because : $rownum = $this->highest_fetched_row[$result_value] + 1; then line 1552 @OCIFetchInto($result, $buffer, OCI_RETURN_NULLS) fails because cursor is at 2 at this moment, thus 'out of sequence'. Thierry Bothorel Reproduce code: --------------- (simplified) $res = $mdb->query($sql); $counte = $mdb->numRows($res); while ($row = $mdb->fetchInto($res)) {}

Comments

 [2004-03-04 23:31 UTC] thierrybo at freesurf dot fr
Well, I have a fix I have not fully tested. I assume that if numRows() needed to execute OCIFetchInto (highest_fetched_row was not set), the new $highest_fetched_row value is only valid for numRows purpose. Then I copy its value to a $temp variable (not found a better way), set $highest_fetched_row to -1 and return $temp. This way, when I call fetchInto thereafter, $rownum = 0 (line 1532), then $this->results[$result_value][$rownum] exist (line 1534), then we can jump to line 1566 where we only read values in $this->results[$result_value][$rownum] (no need to run OCIFetchInto anymore). Meanwhile I also changed (line 900) $this->current_row[$result_value] into $this->highest_fetch_row[$result_value] as the last index of $this->results[$result_value], since this is the second one that is incremented in the loop. Again, please test if this works also if we call numRows AFTER fetchInto, not before. Diff file : 900c900 < $this->results[$result_value][$this->current_row[$result_value]] = $buffer; --- > $this->results[$result_value][$this->highest_fetched_row[$result_value]] = $buffer; 903a904,905 > $temp = $this->highest_fetched_row[$result_value]; > $this->highest_fetched_row[$result_value] = -1; 906c908 < return(max(0, $this->highest_fetched_row[$result_value])); --- > return $temp; Thierry Bothorel
 [2004-03-05 08:57 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.