PEAR is archived and read-only

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

Home » Database » MDB » Bug #946

OCIFetchInto:ORA-01002:fetch out of sequence if numrows() called before

Details

Submitted2004-03-04 14:23 UTC
Fromthierrybo at freesurf dot fr
Assignedlsmith
StatusClosed
PackageMDB
PHP Version4.3.2
OSwin32XP
Roadmaps(Not assigned)

Comments

[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)) {}

[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