aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-02-16 10:29:23 -0300
committerEmilio Tagua <miloops@gmail.com>2010-02-16 10:29:23 -0300
commitf21f289ebf8cd4b89f507d48e62e7c5c986922d8 (patch)
tree1472d42af38aab6c3022132a9a115fd5766410d1 /lib
parent7dc7cd5d6dffae18b41c07ac5c6e291d0ea8cd74 (diff)
downloadrails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.tar.gz
rails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.tar.bz2
rails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.zip
Move update conditions with limit logic into compilers.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/engines/sql/compilers/mysql_compiler.rb3
-rw-r--r--lib/arel/engines/sql/relations/compiler.rb10
-rw-r--r--lib/arel/engines/sql/relations/writes.rb12
3 files changed, 15 insertions, 10 deletions
diff --git a/lib/arel/engines/sql/compilers/mysql_compiler.rb b/lib/arel/engines/sql/compilers/mysql_compiler.rb
index e3cf1f2add..ba3312ba72 100644
--- a/lib/arel/engines/sql/compilers/mysql_compiler.rb
+++ b/lib/arel/engines/sql/compilers/mysql_compiler.rb
@@ -1,6 +1,9 @@
module Arel
module SqlCompiler
class MySQLCompiler < GenericCompiler
+ def limited_update_conditions(conditions)
+ conditions
+ end
end
end
end
diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb
index b85d227705..46f728a7bd 100644
--- a/lib/arel/engines/sql/relations/compiler.rb
+++ b/lib/arel/engines/sql/relations/compiler.rb
@@ -21,6 +21,16 @@ module Arel
("#{locked}" unless locked.blank?)
end
+ def limited_update_conditions(conditions)
+ begin
+ quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key)
+ rescue NameError
+ quote_primary_key = engine.quote_column_name("id")
+ end
+
+ "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})"
+ end
+
protected
def method_missing(method, *args, &block)
relation.send(method, *args, &block)
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb
index 83c5fbad42..30b36ddda8 100644
--- a/lib/arel/engines/sql/relations/writes.rb
+++ b/lib/arel/engines/sql/relations/writes.rb
@@ -5,7 +5,7 @@ module Arel
"DELETE",
"FROM #{table_sql}",
("WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank? ),
- ("LIMIT #{taken}" unless taken.blank? )
+ ("LIMIT #{taken}" unless taken.blank? )
end
end
@@ -69,15 +69,7 @@ module Arel
unless taken.blank?
conditions << " LIMIT #{taken}"
- if engine.adapter_name != "MySQL"
- begin
- quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key)
- rescue NameError
- quote_primary_key = engine.quote_column_name("id")
- end
-
- conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})"
- end
+ conditions = compiler.limited_update_conditions(conditions)
end
conditions