diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/visitors/informix.rb | 60 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 3 |
2 files changed, 40 insertions, 23 deletions
diff --git a/lib/arel/visitors/informix.rb b/lib/arel/visitors/informix.rb index 244c68bed3..8de05f60f6 100644 --- a/lib/arel/visitors/informix.rb +++ b/lib/arel/visitors/informix.rb @@ -2,30 +2,48 @@ module Arel module Visitors class Informix < Arel::Visitors::ToSql private - def visit_Arel_Nodes_SelectStatement o - [ - "SELECT", - (visit(o.offset) if o.offset), - (visit(o.limit) if o.limit), - 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.lock) if o.lock), - ].compact.join ' ' + def visit_Arel_Nodes_SelectStatement o, collector + collector << "SELECT " + collector = maybe_visit o.offset, collector + collector = maybe_visit o.limit, collector + collector = o.cores.inject(collector) { |c,x| + visit_Arel_Nodes_SelectCore x, c + } + if o.orders.any? + collector << "ORDER BY " + collector = inject_join o.orders, collector, ", " + end + collector = maybe_visit o.lock, collector end - def visit_Arel_Nodes_SelectCore o - [ - "#{o.projections.map { |x| visit x }.join ', '}", - ("FROM #{visit(o.source)}" if o.source && !o.source.empty?), - ("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?), - (visit(o.having) if o.having), - ].compact.join ' ' + def visit_Arel_Nodes_SelectCore o, collector + collector = inject_join o.projections, collector, ", " + froms = false + if o.source && !o.source.empty? + froms = true + collector << " FROM " + collector = visit o.source, collector + end + + if o.wheres.any? + collector << " WHERE " + collector = inject_join o.wheres, collector, " AND " + end + + if o.groups.any? + collector << "GROUP BY " + collector = inject_join o.groups, collector, ", " + end + + maybe_visit o.having, collector end - def visit_Arel_Nodes_Offset o - "SKIP #{visit o.expr}" + def visit_Arel_Nodes_Offset o, collector + collector << "SKIP " + visit o.expr, collector end - def visit_Arel_Nodes_Limit o - "LIMIT #{visit o.expr}" + def visit_Arel_Nodes_Limit o, collector + collector << "LIMIT " + visit o.expr, collector + collector << " " end end end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 8e254d504b..ee72d864e1 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -107,8 +107,7 @@ module Arel end unless wheres.empty? - collector << " " if values - collector << "WHERE " + collector << " WHERE " collector = inject_join wheres, collector, " AND " end |