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

Search Discussions

  • Frederick Cheung at Dec 4, 2011 at 8:18 pm

    On Dec 4, 2:59 am, tamagohan 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@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.
  • Tamagohan at Dec 5, 2011 at 12:59 am

    On 12月5日, 午前5:18, Frederick Cheung wrote:
    On Dec 4, 2:59 am, tamagohan 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.
  • Frederick Cheung at Dec 5, 2011 at 11:09 am

    On Dec 5, 12:59 am, tamagohan wrote:
    On 12月5日, 午前5:18, Frederick Cheung wrote:

    On Dec 4, 2:59 am, tamagohan 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@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.
  • 高橋正樹 at Dec 5, 2011 at 2:03 pm
    Thanks, Fred!
    I misunderstood..

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

    Masaki
    2011/12/05 20:09 "Frederick Cheung" <frederick.cheung@gmail.com>:
    On Dec 5, 12:59 am, tamagohan wrote:
    On 12月5日, 午前5:18, Frederick Cheung wrote:

    On Dec 4, 2:59 am, tamagohan 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@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.
    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 4, '11 at 8:16p
activeDec 5, '11 at 2:03p
posts5
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

高橋正樹: 3 posts Frederick Cheung: 2 posts

People

Translate

site design / logo © 2021 Grokbase