diff options
-rw-r--r-- | History.txt | 6 | ||||
-rw-r--r-- | lib/arel/visitors/mysql.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_mysql.rb | 7 |
3 files changed, 17 insertions, 0 deletions
diff --git a/History.txt b/History.txt index dce98b061b..af20f9d635 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,9 @@ +== 2.0.5 (unreleased) + +* Bug fixes + + * #lock will lock SELECT statements "FOR UPDATE" on mysql + == 2.0.4 * Bug fixes diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index afffd37f9b..143b4d36f4 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -2,6 +2,10 @@ module Arel module Visitors class MySQL < Arel::Visitors::ToSql private + def visit_Arel_Nodes_Lock o + "FOR UPDATE" + end + ### # :'( # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214 diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb index 871d662d4b..8606dc39d4 100644 --- a/test/visitors/test_mysql.rb +++ b/test/visitors/test_mysql.rb @@ -22,6 +22,13 @@ module Arel sql = @visitor.accept(stmt) sql.must_be_like "SELECT FROM DUAL" end + + it 'uses FOR UPDATE when locking' do + stmt = Nodes::SelectStatement.new + stmt.lock = Nodes::Lock.new + sql = @visitor.accept(stmt) + sql.must_be_like "SELECT FROM DUAL FOR UPDATE" + end end end end |