-
Notifications
You must be signed in to change notification settings - Fork 0
Active Record parallel queries
[url=http://codeigniter.com/forums/viewthread/54113/]forum thread[/url]
This is a replacement of the [b]system/database/DB_active_rec.php[/b] file, allowing you to use several CI Active Record threads at the same time without overlapping.
Here is a piece of the code.
[code] <?php
// ...
/**
-
Active Record Class
-
This is the platform-independent base Active Record implementation class.
-
Changes by Christophe Gragnic on 2007/06/14 are:
-
vars now arrays of old vars
-
added var $ar_identifier and its setter
-
everywhere you had $this->ar_somevar, you now have
-
$this->ar_somevar[$this->ar_identifier]
-
Those changes allow us to use Active Record parallel queries.
-
The "identifier" is a simple string (default:'default').
-
Backward compatible, set_identifier('some_identifier') is optional.
-
Sample code:
-
$this->db->set_identifier('my_first_query');
-
$this->db->from('blabla');
-
$this->db->where('blibli');
-
$this->db->set_identifier('my_second_query');
-
$this->db->from('tatata');
-
$this->db->where('tititi');
-
$this->db->set_identifier('my_first_query');
-
$first_query = $this->db->get();
-
$this->db->set_identifier('my_second_query');
-
$second_query = $this->db->get();
-
@package CodeIgniter
-
@subpackage Drivers
-
@category Database
-
@author Rick Ellis
-
@author Christophe Gragnic (grahack) for the identifier stuff only
-
@link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver {
var $ar_identifier = 'default';
var $ar_select = array('default' => array()); var $ar_distinct = array('default' => FALSE); var $ar_from = array('default' => array()); var $ar_join = array('default' => array()); var $ar_where = array('default' => array()); var $ar_like = array('default' => array()); var $ar_groupby = array('default' => array()); var $ar_having = array('default' => array()); var $ar_limit = array('default' => FALSE); var $ar_offset = array('default' => FALSE); var $ar_order = array('default' => FALSE); var $ar_orderby = array('default' => array()); var $ar_set = array('default' => array());
/**
-
Set_identifier
-
Chooses the channel to use
-
@access public
-
@param string
-
@return object */ function set_identifier($identifier = 'default') { if ( ! is_string($identifier)) { $identifier = 'default'; }
$this->ar_identifier = $identifier;
// we have to init the values only if it is a new key // let's check on the first array if ( ! array_key_exists($identifier, $this->ar_select)) { $this->ar_select [$identifier] = array(); $this->ar_distinct [$identifier] = FALSE; $this->ar_from [$identifier] = array(); $this->ar_join [$identifier] = array(); $this->ar_where [$identifier] = array(); $this->ar_like [$identifier] = array(); $this->ar_groupby [$identifier] = array(); $this->ar_having [$identifier] = array(); $this->ar_limit [$identifier] = FALSE; $this->ar_offset [$identifier] = FALSE; $this->ar_order [$identifier] = FALSE; $this->ar_orderby [$identifier] = array(); $this->ar_set [$identifier] = array(); } return $this; }
-
// ...
[/code]