I figured I’d put this in a new post since it involve a lot more than just the num rows problem described farther down the board. I’ve spent most of last night and today crawling through this driver and I’ve figured out where the problems are, unfortunately I don’t have the time to code a proper fix for it all. But basically the driver should be pulled from the stable version of CI until all this is ironed out. As it stands now, you can insert but you can’t select anything, neither using get() nor manually typing a statement and passing it to query() works.
num_rows:
function num_rows()
{
if (function_exists('oci_num_rows'))
{
return @oci_num_rows($this->stmt_id);
}
else
{
return @ocirowcount($this->stmt_id)
}
}
This will not work. oci_num_rows() only returns a value if a fetch has been made. At the point where num_rows is called nothing has been fetched yet. So it always returns 0, which causes result_array() and result_object() to return a blank array. The problem is further confounded because in their infinite wisdom the folks over at PHP did not include any oci method to reset the row pointer in the result set so that if you issue any fetch method you’ve just screwed up the CI’s _fetch_object method - oci_fetch_all will cause any other oci_fetch method to return 0 results since there are no more records.
An ugly hack is to use an oci_fetch_all to get the num. of rows followed by re-executing the statement using oci_execute. I don’t have enough experience with the internal workings of CI to know if that will screw up updates/inserts or deletes - do they call num_rows?
_fetch_object:
Because the oci driver doesn’t implement it’s own result_object method the while statement in _fetch_object screws up the data passed back to result_object.
replacing:
while ($row = oci_fetch_object($id))
{
$result[] = $row;
}
return $result;
with:
return @oci_fetch_object($id);
fixes the problem.
There’s more errors in there (e.g. scaffolding view no longer displays an error message, and shows the correct row count, but does not display an of the table data), but I’ve got 2 months to finish something that should have been given a year so I don’t have timt to devote to finding them all.
- K
