ActiveRecord::Base.connection.execute is exec?

Hi all, I update column by 'ActiveRecord::Base.connection.execute' ActiveRecord::Base.connection.execute "UPDATE requests SET count=count +10 WHERE id=1 AND count <= 1000" But, I can't know if condition,..'count <= 1000' is met How can I know if condtion is met?

Please in mind, any other process very often update count, not only add but also subtract

appreciate any help. Thank you Masaki.

Hi all, I update column by 'ActiveRecord::Base.connection.execute' ActiveRecord::Base.connection.execute "UPDATE requests SET count=count +10 WHERE id=1 AND count <= 1000" But, I can't know if condition,..'count <= 1000' is met How can I know if condtion is met?

I think that if you use update rather than execute you'll get the number of modified rows returned.

Fred

Thanks! but sorry...

I want to use execute. Because, I feared race condition. For example, process A get count,...100 process B get count,...100 process A update count to (count + 10),...110 process B update count to (count + 10),...110 But, after 2 proceess, count should be 120.

So, I update count by database, not by application.

Masaki

You've misunderstood me. I meant se ActiveRecord::Base.connection.update "..." which is the same as update except that you get the altered row count (and also clears rails' query cache)

Fred

Thanks, Fred! I misunderstood…

I could get affecyed colmun count. Thank you so much!

Masaki