aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/to_sql.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-10-12 16:36:30 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-10-12 16:36:30 -0700
commit9367992b4cc274766d3dd099330bbe610c8038f4 (patch)
treef924d7d2a5d043f971d23d92ad09e0046b5a6fbe /lib/arel/visitors/to_sql.rb
parente2322265cc84ddd204fddbc1398db42179f6a31b (diff)
downloadrails-9367992b4cc274766d3dd099330bbe610c8038f4.tar.gz
rails-9367992b4cc274766d3dd099330bbe610c8038f4.tar.bz2
rails-9367992b4cc274766d3dd099330bbe610c8038f4.zip
more roflscaling strings in the visitor
Diffstat (limited to 'lib/arel/visitors/to_sql.rb')
-rw-r--r--lib/arel/visitors/to_sql.rb34
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index ee6ca6fb92..76355a00df 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -47,6 +47,7 @@ module Arel
SPACE = ' ' # :nodoc:
COMMA = ', ' # :nodoc:
GROUP_BY = ' GROUP BY ' # :nodoc:
+ ORDER_BY = ' ORDER BY ' # :nodoc:
WINDOW = ' WINDOW ' # :nodoc:
AND = ' AND ' # :nodoc:
@@ -164,14 +165,31 @@ key on UpdateManager using UpdateManager#key=
end
def visit_Arel_Nodes_SelectStatement o
- [
- (visit(o.with) if o.with),
- o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
- ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
- (visit(o.limit) if o.limit),
- (visit(o.offset) if o.offset),
- (visit(o.lock) if o.lock),
- ].compact.join ' '
+ str = ''
+
+ if o.with
+ str << visit(o.with)
+ str << SPACE
+ end
+
+ o.cores.each { |x| str << visit_Arel_Nodes_SelectCore(x) }
+
+ unless o.orders.empty?
+ str << SPACE
+ str << ORDER_BY
+ len = o.orders.length - 1
+ o.orders.each_with_index { |x, i|
+ str << visit(x)
+ str << COMMA unless len == i
+ }
+ end
+
+ str << " #{visit(o.limit)}" if o.limit
+ str << " #{visit(o.offset)}" if o.offset
+ str << " #{visit(o.lock)}" if o.lock
+
+ str.strip!
+ str
end
def visit_Arel_Nodes_SelectCore o