2016-08-31 11:20:36 -04:00
|
|
|
# frozen_string_literal: true
|
2018-02-24 01:45:50 -05:00
|
|
|
|
2018-02-24 02:41:47 -05:00
|
|
|
module Arel # :nodoc: all
|
2010-09-23 18:26:08 -04:00
|
|
|
module Visitors
|
|
|
|
class MySQL < Arel::Visitors::ToSql
|
2010-10-19 14:47:00 -04:00
|
|
|
private
|
2018-02-24 01:45:50 -05:00
|
|
|
def visit_Arel_Nodes_Union(o, collector, suppress_parens = false)
|
|
|
|
unless suppress_parens
|
|
|
|
collector << "( "
|
|
|
|
end
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
collector = case o.left
|
|
|
|
when Arel::Nodes::Union
|
|
|
|
visit_Arel_Nodes_Union o.left, collector, true
|
|
|
|
else
|
|
|
|
visit o.left, collector
|
|
|
|
end
|
2011-07-20 17:00:06 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
collector << " UNION "
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
collector = case o.right
|
|
|
|
when Arel::Nodes::Union
|
|
|
|
visit_Arel_Nodes_Union o.right, collector, true
|
|
|
|
else
|
|
|
|
visit o.right, collector
|
|
|
|
end
|
2011-07-20 17:00:06 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
if suppress_parens
|
|
|
|
collector
|
|
|
|
else
|
|
|
|
collector << " )"
|
|
|
|
end
|
2011-07-20 17:00:06 -04:00
|
|
|
end
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def visit_Arel_Nodes_Bin(o, collector)
|
|
|
|
collector << "BINARY "
|
|
|
|
visit o.expr, collector
|
|
|
|
end
|
2011-04-11 13:02:28 -04:00
|
|
|
|
2018-09-27 12:03:13 -04:00
|
|
|
def visit_Arel_Nodes_UnqualifiedColumn(o, collector)
|
|
|
|
visit o.expr, collector
|
|
|
|
end
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
###
|
|
|
|
# :'(
|
|
|
|
# http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
|
|
|
|
def visit_Arel_Nodes_SelectStatement(o, collector)
|
|
|
|
if o.offset && !o.limit
|
|
|
|
o.limit = Arel::Nodes::Limit.new(18446744073709551615)
|
|
|
|
end
|
|
|
|
super
|
2014-03-24 19:26:09 -04:00
|
|
|
end
|
2010-10-19 14:47:00 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def visit_Arel_Nodes_SelectCore(o, collector)
|
|
|
|
o.froms ||= Arel.sql("DUAL")
|
|
|
|
super
|
|
|
|
end
|
2010-11-05 17:28:36 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def visit_Arel_Nodes_UpdateStatement(o, collector)
|
|
|
|
collector << "UPDATE "
|
|
|
|
collector = visit o.relation, collector
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
unless o.values.empty?
|
|
|
|
collector << " SET "
|
|
|
|
collector = inject_join o.values, collector, ", "
|
|
|
|
end
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
unless o.wheres.empty?
|
|
|
|
collector << " WHERE "
|
|
|
|
collector = inject_join o.wheres, collector, " AND "
|
|
|
|
end
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
unless o.orders.empty?
|
|
|
|
collector << " ORDER BY "
|
|
|
|
collector = inject_join o.orders, collector, ", "
|
|
|
|
end
|
2014-04-08 22:43:42 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
maybe_visit o.limit, collector
|
|
|
|
end
|
2010-09-23 18:26:08 -04:00
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
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
|