diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-21 15:40:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-21 15:40:38 -0800 |
commit | c7eef391dbcf3364f3792c0e0bbffd4bc3e139d0 (patch) | |
tree | c8a2bb438272392aaf1126769d213dbabc54c81e /lib | |
parent | 8ed3ab00f1ba8cdf48dea4ca28d2d3a7e73396ab (diff) | |
download | rails-c7eef391dbcf3364f3792c0e0bbffd4bc3e139d0.tar.gz rails-c7eef391dbcf3364f3792c0e0bbffd4bc3e139d0.tar.bz2 rails-c7eef391dbcf3364f3792c0e0bbffd4bc3e139d0.zip |
refactoring custom lock logic to use sql literals
Diffstat (limited to 'lib')
-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 |
3 files changed, 11 insertions, 13 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 |