• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom backport of unbuffered_row in CI2

#1
In a CI2 project I work on, I really need the unbuffered_row() function that exists only in CI3. The project will be migrated to CI3 later this year, but for now I want to add the function in CI2 to address a memory issue. Here are the changes I made. Can someone knowing very well how the database classes works,  tell me if those changes will cause problems? Especially the removal of the call to num_rows().

This is what I added to system/database/DB_result.php:
PHP Code:
public function unbuffered_row($type 'object')
{
    if (
$type === 'array')
    {
        return 
$this->_fetch_assoc();
    }
    elseif (
$type === 'object')
    {
        return 
$this->_fetch_object();
    }

    
/*
     * _fetch_object has no parameter in CI2, and I don't need it anyway, so I'm throwing an exception here.
     */
    // return $this->_fetch_object($type);

    
throw new Exception("Invalid type ($type)");


In system/database/DB_driver.php, near the end of the query() function, I removed the call to num_rows() because it fetched all the rows. Also, it's not there in CI3, and for now I haven't seen any problem:
PHP Code:
// oci8 vars must be set before calling this
/* $RES->num_rows = $RES->num_rows();     REMOVED */ 


So, will it work? Thank you for your feedback!

PS: I know very well it's a bad idea to make changes to core classes, but it's a temporary fix. The project will be migrated to CI3 later this year.
Test your translation files with Translation Tester
Reply

#2
Ok, obviously, the num_rows variable is not set before calling result_array() (this is for my other queries not using unbuffered_row).

So I should change this :
PHP Code:
if($query->num_rows 0

To this :
PHP Code:
if($query->num_rows() > 0


And I think it will work...
Test your translation files with Translation Tester
Reply

#3
One last change, num_rows must be set to 0. Now I think it works.

PHP Code:
// oci8 vars must be set before calling this
/* $RES->num_rows = $RES->num_rows();     REMOVED */ 
$num_rows 0

@Narf, @Kilishan, I'd like your feedback on this. Am I shooting myself in the foot? Tongue
Test your translation files with Translation Tester
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.