Update statement in active record class |
[eluser]MaDe[/eluser]
Hi there, I found out, that in active record class statements like "UPDATE table SET field1 = field2+1" are not possible, as the $this->db->set() function only accepts arrays of key/value pairs or a key/value pair as 2 parameters. In both cases, the value parameter is escaped, which will not work in the example above. If I'm wrong here, please tell me Would it not be a good solution to have the ability to set only ONE parameter ($this->db->set('field1 = field2 + 1') and NOT escape that one? That would be the same way, the $this->db->where() function works. Wouldn't that be a solution?
[eluser]champs[/eluser]
At first blush, I'm inclined to agree, and that's after trying every AR kludge I could think of. Welcome to CI, by the way.
[eluser]marcoss[/eluser]
[quote author="MaDe" date="1182881565"]Hi there, I found out, that in active record class statements like "UPDATE table SET field1 = field2+1" are not possible, as the $this->db->set() function only accepts arrays of key/value pairs or a key/value pair as 2 parameters. In both cases, the value parameter is escaped, which will not work in the example above. If I'm wrong here, please tell me Would it not be a good solution to have the ability to set only ONE parameter ($this->db->set('field1 = field2 + 1') and NOT escape that one? That would be the same way, the $this->db->where() function works. Wouldn't that be a solution?[/quote] Use $this->db->query(); instead.
[eluser]MaDe[/eluser]
Thanks for the warm welcome, champs! In fact I could use the $this->db->query(), but the advantage of AR is that I can easily put together my statement in several steps instead of appending to a query string. I also do not have to cope with escaping and so on. For that reason I try to use AR as often as possible.
[eluser]marcoss[/eluser]
[quote author="MaDe" date="1182940511"]For that reason I try to use AR as often as possible.[/quote] You will find that sometimes the right tool for the job, is not the easy one
[eluser]MaDe[/eluser]
[quote author="marcoss" date="1182942158"]You will find that sometimes the right tool for the job, is not the easy one [/quote] Sure, but one can help make things easier to use. May there be any chance to have this feature in any of the next codeigniter releases? What do you think?
[eluser]marcoss[/eluser]
[quote author="MaDe" date="1183035620"]Sure, but one can help make things easier to use. May there be any chance to have this feature in any of the next codeigniter releases? What do you think?[/quote] The next version is supposed to ship with an improved database layer, that will included a more robust AR for sure. Found the thread, Quote:Here’s a concreted example of something we’re hoping to achieve for EE 2.0 that will cary over to CI. Currently, EE runs only on MySQL. We’d love, however, for EE to support other DB platforms. To do this, though, will require that the 2000+ database queries that exist in EE be ported over to a more abstracted mechanism. In essence, we need to rip the MySQL queries out of EE and replace them with an active record pattern. http://ellislab.com/forums/viewthread/53619/P15/#262381 |
Welcome Guest, Not a member yet? Register Sign In |