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

refactor mssql nodes to move away from string interpolation

This commit is contained in:
Aaron Patterson 2014-04-08 20:30:40 -07:00
parent 8fc2241df6
commit 03e2006ad9

View file

@ -1,6 +1,14 @@
module Arel
module Visitors
class MSSQL < Arel::Visitors::ToSql
class RowNumber
attr_reader :expr
def initialize node
@expr = node
end
end
private
# `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
@ -10,6 +18,10 @@ module Arel
""
end
def visit_Arel_Visitors_MSSQL_RowNumber o
"ROW_NUMBER() OVER (#{o.expr}) as _row_num"
end
def visit_Arel_Nodes_SelectStatement o
if !o.limit && !o.offset
return super o
@ -55,7 +67,7 @@ module Arel
end
def row_num_literal order_by
Nodes::SqlLiteral.new("ROW_NUMBER() OVER (#{order_by}) as _row_num")
RowNumber.new order_by
end
def select_count? x