From 03e2006ad97cabb689e2a84bdbf9300baaf518b5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Apr 2014 20:30:40 -0700 Subject: refactor mssql nodes to move away from string interpolation --- lib/arel/visitors/mssql.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/arel/visitors/mssql.rb b/lib/arel/visitors/mssql.rb index ef0b78058e..cc077d863b 100644 --- a/lib/arel/visitors/mssql.rb +++ b/lib/arel/visitors/mssql.rb @@ -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 -- cgit v1.2.3