1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/visitors/mysql.rb

83 lines
2.1 KiB
Ruby
Raw Normal View History

2010-09-23 18:26:08 -04:00
module Arel
module Visitors
class MySQL < Arel::Visitors::ToSql
2010-10-19 14:47:00 -04:00
private
2014-04-08 22:43:42 -04:00
def visit_Arel_Nodes_Union o, collector, suppress_parens = false
unless suppress_parens
collector << "( "
end
collector = case o.left
when Arel::Nodes::Union
2014-04-08 22:43:42 -04:00
visit_Arel_Nodes_Union o.left, collector, true
else
2014-04-08 22:43:42 -04:00
visit o.left, collector
end
2014-04-08 22:43:42 -04:00
collector << " UNION "
collector = case o.right
when Arel::Nodes::Union
2014-04-08 22:43:42 -04:00
visit_Arel_Nodes_Union o.right, collector, true
else
2014-04-08 22:43:42 -04:00
visit o.right, collector
end
if suppress_parens
2014-04-08 22:43:42 -04:00
collector
else
2014-04-08 22:43:42 -04:00
collector << " )"
end
end
2014-04-09 00:38:19 -04:00
def visit_Arel_Nodes_Bin o, collector
collector << "BINARY "
visit o.expr, collector
end
###
# :'(
# http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
2014-04-08 22:43:42 -04:00
def visit_Arel_Nodes_SelectStatement o, collector
if o.offset && !o.limit
o.limit = Arel::Nodes::Limit.new(Nodes.build_quoted(18446744073709551615))
end
super
end
2010-10-19 14:47:00 -04:00
2014-04-08 22:43:42 -04:00
def visit_Arel_Nodes_SelectCore o, collector
o.froms ||= Arel.sql('DUAL')
super
end
2014-04-08 22:43:42 -04:00
def visit_Arel_Nodes_UpdateStatement o, collector
collector << "UPDATE "
collector = visit o.relation, collector
unless o.values.empty?
collector << "SET "
collector = inject_join o.values, collector, ', '
end
unless o.wheres.empty?
collector << "SET "
collector = inject_join o.wheres, collector, ' AND '
end
unless o.orders.empty?
collector << "ORDER BY "
collector = inject_join o.wheres, collector, ', '
end
if o.limit
collector << " "
visit(o.limit, collector)
else
collector
end
2010-09-23 18:26:08 -04:00
end
end
end
end