Welcome Guest, Not a member yet? Register   Sign In
Extending Active Record offer
#1

[eluser]Alexxz[/eluser]
I am have a little problem with Active record. In my code I need to reset not completed AR query. It is something like
Code:
try{
    $this->db->set(...);
    $this->db->set(...);
    $this->db->set(...);
    $this->db->insert('table1');
} catch (Exception $e) {
    $this->db->set(...);
    $this->db->set(...);
    $this->db->insert('table2');
}

So if I have some exception in the first section, the second section added to the first and
I'm have a DB error. For me I'm write little function reset

Code:
function reset() {
    $this->_reset_select();
    $this->_reset_write();
}

My code now looks like
Code:
try{
    $this->db->set(...);
    $this->db->set(...);
    $this->db->set(...);
    $this->db->insert('table1');
} catch (Exception $e) {
    $this->db->reset();  // resetting previous AR
    $this->db->set(...);
    $this->db->set(...);
    $this->db->insert('table2');
}

May be it is a good idea to extend Active record?




Theme © iAndrew 2016 - Forum software by © MyBB