diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-21 09:20:14 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-21 09:20:14 -0700 |
commit | 2b20a488519716be15fbe351f7da39c9fd70f846 (patch) | |
tree | 00f61fcd6fa5590f1cb94d430c1d5f6322de0e7f /lib/arel/visitors | |
parent | 0e98ef149cd44dc04d40a8553e1743c5cb6d4a7c (diff) | |
download | rails-2b20a488519716be15fbe351f7da39c9fd70f846.tar.gz rails-2b20a488519716be15fbe351f7da39c9fd70f846.tar.bz2 rails-2b20a488519716be15fbe351f7da39c9fd70f846.zip |
making stuff work on mysql
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 4 | ||||
-rw-r--r-- | lib/arel/visitors/update_sql.rb | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index d6a9a3697f..710b6143ec 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -25,7 +25,9 @@ module Arel [ "UPDATE #{visit o.relation}", ("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?), - ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?) + ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?), + ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), + ("LIMIT #{o.limit}" if o.limit), ].compact.join ' ' end diff --git a/lib/arel/visitors/update_sql.rb b/lib/arel/visitors/update_sql.rb new file mode 100644 index 0000000000..02196a0fb0 --- /dev/null +++ b/lib/arel/visitors/update_sql.rb @@ -0,0 +1,26 @@ +module Arel + module Visitors + module UpdateSql + def visit_Arel_Nodes_UpdateStatement o + if o.orders.empty? && o.limit.nil? + wheres = o.wheres + else + stmt = Nodes::SelectStatement.new + core = stmt.cores.first + core.froms = o.relation + core.projections = [o.relation.primary_key] + stmt.limit = o.limit + stmt.orders = o.orders + + wheres = [Nodes::In.new(o.relation.primary_key, [stmt])] + end + + [ + "UPDATE #{visit o.relation}", + ("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?), + ("WHERE #{wheres.map { |x| visit x }.join ' AND '}" unless wheres.empty?) + ].compact.join ' ' + end + end + end +end |