Part of the EllisLab Network
   
 
oci8 select bug
Posted: 23 March 2007 10:23 AM   [ Ignore ]  
Summer Student
Total Posts:  13
Joined  03-23-2007

There’s a bug in the oci8 driver that results in the stored statement ID never being changed after the first query is run.

In essence, this means that the first query you run will work just fine, but all subsequent queries on the same page won’t (all the result-related operations will be using the wrong statement ID).  There’s a fairly simple fix:

In oci8_driver.php, change:

function _execute($sql)
{
    
// oracle must parse the query before it is run. All of the actions with
    // the query are based on the statement id returned by ociparse
    
$this->_set_stmt_id($sql);
    
ocisetprefetch($this->stmt_id, 1000);
    return @
ociexecute($this->stmt_id, $this->_commit);
}


to:

function _execute($sql)
{
    
// oracle must parse the query before it is run. All of the actions with
    // the query are based on the statement id returned by ociparse
    
$this->stmt_id = FALSE;
    
$this->_set_stmt_id($sql);
    
ocisetprefetch($this->stmt_id, 1000);
    return @
ociexecute($this->stmt_id, $this->_commit);
}

This will let multiple queries on the same page work properly again.

Active record features for Oracle are still somewhat problematic (I’ve never actually gotten results to go through with their current incarnation), but I may end up debugging it if I have some extra time on my current project.

Profile
 
 
Posted: 11 April 2007 03:47 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  13
Joined  03-23-2007

After seeing jody78’s post on stored procedures, I realized that clearing the statement ID in _execute() breaks stored procedure support.  If you need to use stored procedures in your environment, I suggest the following change instead:

In DB_driver.php (the parent class for the DB drivers), change:

function query($sql, $binds = FALSE, $return_object = TRUE)
{
    
...
    if (
$this->dbdriver == 'oci8')
    
{
        $RES
->stmt_id       = $this->stmt_id;
        
$RES->curs_id       = NULL;
        
$RES->limit_used    = $this->limit_used;
    
}
    
...
}


to:

function query($sql, $binds = FALSE, $return_object = TRUE)
{
    
...
    if (
$this->dbdriver == 'oci8')
    
{
        $RES
->stmt_id       = $this->stmt_id;
        
$RES->curs_id       = NULL;
        
$RES->limit_used    = $this->limit_used;
        
$this->stmt_id      = FALSE;
    
}
    
...
}

Profile
 
 
Posted: 21 May 2007 02:15 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  38
Joined  08-31-2006

Hello,

Thanks for this info, I’ve had the problem too.

The second version of the patch seems to work only for the SELECT statements.
The UPDATE and DELETE ones don’t pass in this part of the code and the ID is not changed (an UPDATE followed by a SELECT becomes twice the same UPDATE).

I’ve updated the code the dirty way by breaking the stored procedure support because I don’t use them but a proper patch should be done (I’m not fluent enough in PHP to do it myself ^^).

Thanks,

Tchule.

Profile
 
 
   
 
 
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: 66426 Total Logged-in Users: 36
Total Topics: 84790 Total Anonymous Users: 3
Total Replies: 455008 Total Guests: 244
Total Posts: 539798    
Members ( View Memberlist )
Newest Members:  llogocsaturkeytherendStudioGeorgiaJZeerfedegheEdgedcenticeRoger_Mxcamilo