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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 4, 2:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> Please in mind, any other process very often update count, not only > add but also subtract > > appreciate any help. > Thank you > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 12月5日, 午前5:18, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 4, 2:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Dec 5, 12:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12月5日, 午前5:18, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Dec 4, 2:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Thanks, Fred! I misunderstood.. I could get affecyed colmun count. Thank you so much! Masaki 2011/12/05 20:09 "Frederick Cheung" <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > On Dec 5, 12:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 12月5日, 午前5:18, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Dec 4, 2:59 am, tamagohan <takahashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > 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 > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.