diff options
author | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2010-02-10 19:50:59 +0200 |
---|---|---|
committer | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2010-03-01 12:02:10 +0200 |
commit | 20a10e5302ce8f912d27c57702b542a019c7f9f9 (patch) | |
tree | 38de3309520244ba6fda99b8d47525852e926491 /lib/arel/engines/sql/relations/writes.rb | |
parent | 98a87e181aed8131797e55db2ca957bc515cdaca (diff) | |
download | rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.tar.gz rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.tar.bz2 rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.zip |
changes for Oracle support - OracleCompiler and corresponding tests with Oracle syntax
Diffstat (limited to 'lib/arel/engines/sql/relations/writes.rb')
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 64 |
1 files changed, 3 insertions, 61 deletions
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 54eaee9ead..4ed817f85d 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -1,77 +1,19 @@ module Arel class Deletion < Compound def to_sql - build_query \ - "DELETE", - "FROM #{table_sql}", - ("WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank? ), - (compiler.add_limit_on_delete(taken) unless taken.blank? ) + compiler.delete_sql end end class Insert < Compound def to_sql(include_returning = true) - insertion_attributes_values_sql = if record.is_a?(Value) - record.value - else - attributes = record.keys.sort_by do |attribute| - attribute.name.to_s - end - - first = attributes.collect do |key| - engine.quote_column_name(key.name) - end.join(', ') - - second = attributes.collect do |key| - key.format(record[key]) - end.join(', ') - - build_query "(#{first})", "VALUES (#{second})" - end - - build_query \ - "INSERT", - "INTO #{table_sql}", - insertion_attributes_values_sql, - ("RETURNING #{engine.quote_column_name(primary_key)}" if include_returning && compiler.supports_insert_with_returning?) + compiler.insert_sql(include_returning) end end class Update < Compound def to_sql - build_query \ - "UPDATE #{table_sql} SET", - assignment_sql, - build_update_conditions_sql - end - - protected - - def assignment_sql - if assignments.respond_to?(:collect) - attributes = assignments.keys.sort_by do |attribute| - attribute.name.to_s - end - - attributes.map do |attribute| - value = assignments[attribute] - "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" - end.join(", ") - else - assignments.value - end - end - - def build_update_conditions_sql - conditions = "" - conditions << " WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank? - conditions << " ORDER BY #{order_clauses.join(', ')}" unless orders.blank? - - unless taken.blank? - conditions = compiler.limited_update_conditions(conditions,taken) - end - - conditions + compiler.update_sql end end end |