diff options
author | Viacheslav Petrenko <slavap@gmail.com> | 2010-12-27 18:16:18 +0200 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-03 10:18:02 -0800 |
commit | 1a246f71616cf246a75ef6cbdb56032e43d4e643 (patch) | |
tree | 81b0795b26766f9c4cdc59c04d20837a5de051f9 /lib/arel/visitors/to_sql.rb | |
parent | ee3c55c84996ad2565762fa1f472259460d7d731 (diff) | |
download | rails-1a246f71616cf246a75ef6cbdb56032e43d4e643.tar.gz rails-1a246f71616cf246a75ef6cbdb56032e43d4e643.tar.bz2 rails-1a246f71616cf246a75ef6cbdb56032e43d4e643.zip |
Patched Arel v2.0.6 to support MSSQL SQL queries. Based on work of James Abley (https://github.com/jabley/arel).
Diffstat (limited to 'lib/arel/visitors/to_sql.rb')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index a2105d7043..7435e41561 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -76,7 +76,7 @@ module Arel [ o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join, ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), - ("LIMIT #{visit o.limit}" if o.limit), + (visit(o.limit) if o.limit), (visit(o.offset) if o.offset), (visit(o.lock) if o.lock), ].compact.join ' ' @@ -84,7 +84,9 @@ module Arel def visit_Arel_Nodes_SelectCore o [ - "SELECT #{o.projections.map { |x| visit x }.join ', '}", + "SELECT", + (visit(o.top) if o.top), + "#{o.projections.map { |x| visit x }.join ', '}", ("FROM #{visit o.froms}" if o.froms), ("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?), ("GROUP BY #{o.groups.map { |x| visit x }.join ', ' }" unless o.groups.empty?), @@ -100,6 +102,15 @@ module Arel "OFFSET #{visit o.expr}" end + def visit_Arel_Nodes_Limit o + "LIMIT #{visit o.expr}" + end + + # FIXME: this does nothing on most databases, but does on MSSQL + def visit_Arel_Nodes_Top o + "" + end + # FIXME: this does nothing on SQLLite3, but should do things on other # databases. def visit_Arel_Nodes_Lock o |