Welcome Guest, Not a member yet? Register   Sign In
Update statement in active record class
#1

[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 Smile

Would it not be a good solution to have the ability to set only ONE parameter ($this->db->set('field1 = field2 + 1')Wink and NOT escape that one? That would be the same way, the $this->db->where() function works.

Wouldn't that be a solution?
#2

[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.
#3

[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 Smile

Would it not be a good solution to have the ability to set only ONE parameter ($this->db->set('field1 = field2 + 1')Wink 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.
#4

[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.
#5

[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 Wink
#6

[eluser]MaDe[/eluser]
[quote author="marcoss" date="1182942158"]You will find that sometimes the right tool for the job, is not the easy one Wink[/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?
#7

[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.

CI, however, already supports multiple databases via a much nicer DB library then EE and it has an active record system, it’s just not powerful enough in its current form to meet our goals. But it’s a great starting point for our development, so as we move EE to this new database structure and rewrite the engine, it’s going to result in CI automatically getting much more kick-ass database classes.

http://ellislab.com/forums/viewthread/53619/P15/#262381




Theme © iAndrew 2016 - Forum software by © MyBB