Permalink
Browse files

mysql will lock for update

  • Loading branch information...
1 parent 43b0b62 commit 3e928ee400d083e7391474c61c8fcef74f0c848a @tenderlove tenderlove committed Nov 22, 2010
Showing with 17 additions and 0 deletions.
  1. +6 −0 History.txt
  2. +4 −0 lib/arel/visitors/mysql.rb
  3. +7 −0 test/visitors/test_mysql.rb
View
@@ -1,3 +1,9 @@
+== 2.0.5 (unreleased)
+
+* Bug fixes
+
+ * #lock will lock SELECT statements "FOR UPDATE" on mysql
+
== 2.0.4
* Bug fixes
@@ -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
@@ -22,6 +22,13 @@ module Visitors
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

0 comments on commit 3e928ee

Please sign in to comment.