diff options
-rw-r--r-- | lib/arel/select_manager.rb | 12 | ||||
-rw-r--r-- | lib/arel/visitors/mysql.rb | 6 | ||||
-rw-r--r-- | lib/arel/visitors/postgresql.rb | 6 | ||||
-rw-r--r-- | test/visitors/test_mysql.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_postgres.rb | 4 |
5 files changed, 15 insertions, 17 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 249ad680a7..adffcca764 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -37,9 +37,15 @@ module Arel @ctx.wheres.map { |c| to_sql.accept c } end - def lock locking = true - # FIXME: do we even need to store this? If locking is +false+ shouldn't - # we just remove the node from the AST? + def lock locking = Arel.sql('FOR UPDATE') + case locking + when true + locking = Arel.sql('FOR UPDATE') + when Arel::Nodes::SqlLiteral + when String + locking = Arel.sql locking + end + @ast.lock = Nodes::Lock.new(locking) self end diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index dad4d5e3b2..4f029245ac 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -3,11 +3,7 @@ module Arel class MySQL < Arel::Visitors::ToSql private def visit_Arel_Nodes_Lock o - if o.expr.is_a?(String) - o.expr - else - "FOR UPDATE" - end + visit o.expr end ### diff --git a/lib/arel/visitors/postgresql.rb b/lib/arel/visitors/postgresql.rb index 68b483910e..c423dc6fc6 100644 --- a/lib/arel/visitors/postgresql.rb +++ b/lib/arel/visitors/postgresql.rb @@ -3,11 +3,7 @@ module Arel class PostgreSQL < Arel::Visitors::ToSql private def visit_Arel_Nodes_Lock o - if o.expr.is_a?(String) - o.expr - else - "FOR UPDATE" - end + visit o.expr end def visit_Arel_Nodes_SelectStatement o diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb index ee70d4c174..3c15c218b2 100644 --- a/test/visitors/test_mysql.rb +++ b/test/visitors/test_mysql.rb @@ -31,12 +31,12 @@ module Arel describe 'locking' do it 'defaults to FOR UPDATE when locking' do - node = Nodes::Lock.new true + node = Nodes::Lock.new(Arel.sql('FOR UPDATE')) @visitor.accept(node).must_be_like "FOR UPDATE" end it 'allows a custom string to be used as a lock' do - node = Nodes::Lock.new('LOCK IN SHARE MODE') + node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE')) @visitor.accept(node).must_be_like "LOCK IN SHARE MODE" end end diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 169510185e..74446c23ba 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -9,13 +9,13 @@ module Arel describe 'locking' do it 'defaults to FOR UPDATE' do - @visitor.accept(Nodes::Lock.new(true)).must_be_like %{ + @visitor.accept(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{ FOR UPDATE } end it 'allows a custom string to be used as a lock' do - node = Nodes::Lock.new('FOR SHARE') + node = Nodes::Lock.new(Arel.sql('FOR SHARE')) @visitor.accept(node).must_be_like %{ FOR SHARE } |