Part of the EllisLab Network
   
 
oci8 & 1.5.0.1
Posted: 09 November 2006 02:48 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  77
Joined  11-08-2006

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

Profile
 
 
Posted: 11 November 2006 02:41 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRank
Total Posts:  2541
Joined  12-21-2001

Thanks.  I was wondering why the original version of the num_rows function was re-running the query (the driver was submitted by one of our users I don’t have an oracle installation to test on).  I thought it was a coding error so I changed it to its current state.  I’ll revert it back the way it was.

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64453 Total Logged-in Users: 21
Total Topics: 80959 Total Anonymous Users: 1
Total Replies: 435688 Total Guests: 192
Total Posts: 516647    
Members ( View Memberlist )