Sunday, December 4, 2011

[Rails] Re: ActiveRecord::Base.connection.execute is exec?

On 12月5日, 午前5:18, Frederick Cheung <frederick.che...@gmail.com> wrote:
> On Dec 4, 2:59 am, tamagohan <takahashi...@gmail.com> wrote:> 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate