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
|
2010-11-22 17:28:34 -05:00
|
|
|
def visit_Arel_Nodes_Lock o
|
2011-02-21 18:14:29 -05:00
|
|
|
if o.expr.is_a?(String)
|
|
|
|
o.expr
|
2011-01-20 00:37:05 -05:00
|
|
|
else
|
|
|
|
"FOR UPDATE"
|
|
|
|
end
|
2010-11-22 17:28:34 -05:00
|
|
|
end
|
|
|
|
|
2010-10-20 20:16:18 -04:00
|
|
|
###
|
|
|
|
# :'(
|
|
|
|
# http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
|
|
|
|
def visit_Arel_Nodes_SelectStatement o
|
2010-12-27 11:16:18 -05:00
|
|
|
o.limit = Arel::Nodes::Limit.new(18446744073709551615) if o.offset && !o.limit
|
2010-10-20 20:16:18 -04:00
|
|
|
super
|
|
|
|
end
|
2010-10-19 14:47:00 -04:00
|
|
|
|
2010-11-05 17:28:36 -04:00
|
|
|
def visit_Arel_Nodes_SelectCore o
|
|
|
|
o.froms ||= Arel.sql('DUAL')
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-09-23 18:26:08 -04:00
|
|
|
def visit_Arel_Nodes_UpdateStatement o
|
|
|
|
[
|
|
|
|
"UPDATE #{visit o.relation}",
|
|
|
|
("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
|
|
|
|
("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
|
|
|
|
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
|
2011-01-03 19:19:57 -05:00
|
|
|
(visit(o.limit) if o.limit),
|
2010-09-23 18:26:08 -04:00
|
|
|
].compact.join ' '
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|