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

87 lines
2.2 KiB
Ruby
Raw Normal View History

2016-08-31 11:20:36 -04:00
# frozen_string_literal: true
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
2015-07-10 13:49:57 -04:00
o.limit = Arel::Nodes::Limit.new(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 "
2014-04-08 22:43:42 -04:00
collector = inject_join o.values, collector, ', '
end
unless o.wheres.empty?
collector << " WHERE "
2014-04-08 22:43:42 -04:00
collector = inject_join o.wheres, collector, ' AND '
end
unless o.orders.empty?
collector << " ORDER BY "
2014-04-09 18:18:43 -04:00
collector = inject_join o.orders, collector, ', '
2014-04-08 22:43:42 -04:00
end
maybe_visit o.limit, collector
2010-09-23 18:26:08 -04:00
end
def visit_Arel_Nodes_Concat o, collector
collector << " CONCAT("
visit o.left, collector
collector << ", "
visit o.right, collector
collector << ") "
collector
end
2010-09-23 18:26:08 -04:00
end
end
end