Part of the EllisLab Network
   
 
Active Record identifier to be able to use parallel queries
Posted: 13 June 2007 02:12 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  492
Joined  02-21-2007

Let me tell you a story.

I use Active Records in my models, so I can retrieve some data. Nice.
I use Rapyd, which really rocks. I just discovered the _pre_process and _post_process, so I play with it a bit. Very nice.

But when I use my Active-Record-data-retrieving inside the Rapyd processes, the $this->db receives all the Active Record settings (my model ones AND Rapyd ones), so it breaks.
I couldn’t find something like this on the forums.

What do people here think about an optional identifier, like a simple string, that would allow kinds of distinct accesses to $this->db?

After looking at DB_active_rec.php, I had some ideas. If nobody stops me, that’s what I may try in few days:

1) change those vars to be arrays of what they where before
(only four lines to change in the code, but the arrays will not contain the same stuff).

var $ar_select      = array();
var
$ar_distinct    = FALSE;
var
$ar_from        = array();
var
$ar_join        = array();
var
$ar_where       = array();
var
$ar_like        = array();
var
$ar_groupby     = array();
var
$ar_having      = array();
var
$ar_limit       = FALSE;
var
$ar_offset      = FALSE;
var
$ar_order       = FALSE;
var
$ar_orderby     = array();
var
$ar_set         = array();

2) add

var $ar_identifier = 'default_id';

3) add a basic setter

function set_identifier( $identifier )

4) change every AR function to affect the param sent right in front of the right identifier.

Then we will be able to do this:

$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();

Any comments?

Profile
 
 
Posted: 13 June 2007 05:51 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  156
Joined  05-19-2006

The only way i’ve found to play with AR is to “store & reset” query (this is what i do in the DataSet component to exec 2 different queries).

so, basically

- I store temp. query:  $sql1 = $this->db->_compile_select();
- I clean all or single arrays: $this->db->_reset_select();  or $this->db->ar_select = array() , etc..
- then it’s possible to do other AR stuffs..  and prepare $sql2 = $this->db->_compile_select();

Really not a great thing (all used method an properties are intended to be private..), with many limitations but it has less impact to an hack.

Other consideraton, in rapyd some components like DataGrid, DataFilter, etc.. need to share “current AR partial queries”:
i.e.  DF prepare the “where” clause,  and DG manage “order by” and “limit”.

Thierry adds some consideration about a current limitation in rapyd:
It work with “defalt” DB connection (referenced in all “Data"components), but we should extend the concept to work with any.

I’m interested to your solution or “hack” for rapyd about p-queries.

 Signature 

rapyd framework / demo

Profile
 
 
Posted: 14 June 2007 05:49 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  763
Joined  06-11-2007

grahack: Your method seems to be far superior to Felice’s, id go for it if I were you. Post it all back here when you are done!

 Signature 

PhilSturgeon.co.uk - Personal blog site using my new CMS.
StyleDNA Ltd - CodeIgnitor Web Development, Hosting and Design.
_________________

Helpers: Asset Helper, BBCode Helper
Libraries: Layout Lib
_________________

Theres no place like 127.0.0.1

Profile
 
 
Posted: 18 June 2007 12:30 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  492
Joined  02-21-2007

Here is the wiki page.
It seems to work well for me.

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: 64453 Total Logged-in Users: 19
Total Topics: 80961 Total Anonymous Users: 0
Total Replies: 435696 Total Guests: 184
Total Posts: 516657    
Members ( View Memberlist )