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
|
2011-07-20 17:00:06 -04:00
|
|
|
when Arel::Nodes::Union
|
2014-04-08 22:43:42 -04:00
|
|
|
visit_Arel_Nodes_Union o.left, collector, true
|
2011-07-20 17:00:06 -04:00
|
|
|
else
|
2014-04-08 22:43:42 -04:00
|
|
|
visit o.left, collector
|
2011-07-20 17:00:06 -04:00
|
|
|
end
|
|
|
|
|
2014-04-08 22:43:42 -04:00
|
|
|
collector << " UNION "
|
|
|
|
|
|
|
|
collector = case o.right
|
2011-07-20 17:00:06 -04:00
|
|
|
when Arel::Nodes::Union
|
2014-04-08 22:43:42 -04:00
|
|
|
visit_Arel_Nodes_Union o.right, collector, true
|
2011-07-20 17:00:06 -04:00
|
|
|
else
|
2014-04-08 22:43:42 -04:00
|
|
|
visit o.right, collector
|
2011-07-20 17:00:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if suppress_parens
|
2014-04-08 22:43:42 -04:00
|
|
|
collector
|
2011-07-20 17:00:06 -04:00
|
|
|
else
|
2014-04-08 22:43:42 -04:00
|
|
|
collector << " )"
|
2011-07-20 17:00:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-09 00:38:19 -04:00
|
|
|
def visit_Arel_Nodes_Bin o, collector
|
|
|
|
collector << "BINARY "
|
|
|
|
visit o.expr, collector
|
2011-04-11 13:02:28 -04:00
|
|
|
end
|
|
|
|
|
2010-10-20 20:16:18 -04:00
|
|
|
###
|
|
|
|
# :'(
|
|
|
|
# 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
|
2014-03-24 19:26:09 -04:00
|
|
|
if o.offset && !o.limit
|
2015-07-10 13:49:57 -04:00
|
|
|
o.limit = Arel::Nodes::Limit.new(18446744073709551615)
|
2014-03-24 19:26:09 -04:00
|
|
|
end
|
2010-10-20 20:16:18 -04:00
|
|
|
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
|
2010-11-05 17:28:36 -04:00
|
|
|
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?
|
2014-04-11 19:14:04 -04:00
|
|
|
collector << " SET "
|
2014-04-08 22:43:42 -04:00
|
|
|
collector = inject_join o.values, collector, ', '
|
|
|
|
end
|
|
|
|
|
|
|
|
unless o.wheres.empty?
|
2014-04-11 19:14:04 -04:00
|
|
|
collector << " WHERE "
|
2014-04-08 22:43:42 -04:00
|
|
|
collector = inject_join o.wheres, collector, ' AND '
|
|
|
|
end
|
|
|
|
|
|
|
|
unless o.orders.empty?
|
2014-04-11 19:14:04 -04:00
|
|
|
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
|
|
|
|
|
2014-10-23 20:22:17 -04:00
|
|
|
maybe_visit o.limit, collector
|
2010-09-23 18:26:08 -04:00
|
|
|
end
|
|
|
|
|
2015-12-31 20:22:07 -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
|