diff options
author | Praveen Devarao <praveen@falcon> | 2010-02-25 12:49:19 +0530 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-02-25 10:59:03 -0300 |
commit | 4525b1ff89a84ba9be70942a3e90c913c162a839 (patch) | |
tree | fb47dc1cebb5d8554c9ad60899e8b94e30f4420e /lib/arel/engines/sql/relations | |
parent | debd111a39a683592873e7af2d277233b6ec14d2 (diff) | |
download | rails-4525b1ff89a84ba9be70942a3e90c913c162a839.tar.gz rails-4525b1ff89a84ba9be70942a3e90c913c162a839.tar.bz2 rails-4525b1ff89a84ba9be70942a3e90c913c162a839.zip |
Moved adding of limit on deletion and adding of limit on update conditions to GenericCompiler, to provide flexibility to handle db specifics
Signed-off-by: Emilio Tagua <miloops@gmail.com>
Diffstat (limited to 'lib/arel/engines/sql/relations')
-rw-r--r-- | lib/arel/engines/sql/relations/compiler.rb | 7 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb index c974e43b88..597ed88683 100644 --- a/lib/arel/engines/sql/relations/compiler.rb +++ b/lib/arel/engines/sql/relations/compiler.rb @@ -21,11 +21,16 @@ module Arel ("#{locked}" unless locked.blank?) end - def limited_update_conditions(conditions) + def limited_update_conditions(conditions, taken) + conditions << " LIMIT #{taken}" quoted_primary_key = engine.quote_table_name(primary_key) "WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" end + def add_limit_on_delete(taken) + "LIMIT #{taken}" + end + def supports_insert_with_returning? false end diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 0a6250a3b9..54eaee9ead 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? ) + (compiler.add_limit_on_delete(taken) unless taken.blank? ) end end @@ -68,9 +68,7 @@ module Arel conditions << " ORDER BY #{order_clauses.join(', ')}" unless orders.blank? unless taken.blank? - conditions << " LIMIT #{taken}" - - conditions = compiler.limited_update_conditions(conditions) + conditions = compiler.limited_update_conditions(conditions,taken) end conditions |