Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/arel/visitors/sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def visit_Arel_Nodes_UpdateStatement(o)
end

def visit_Arel_Nodes_Offset(o)
"WHERE [__rnt].[__rn] > (#{visit o.expr})"
"WHERE [raw_sql_].[__rn] > (#{visit o.expr})"
end

def visit_Arel_Nodes_Limit(o)
Expand Down Expand Up @@ -175,9 +175,9 @@ def visit_Arel_Nodes_SelectStatementWithOffset(o)
"FROM (",
"SELECT #{core.set_quantifier ? 'DISTINCT DENSE_RANK()' : 'ROW_NUMBER()'} OVER (ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}) AS [__rn],",
visit_Arel_Nodes_SelectStatementWithOutOffset(o,true),
") AS [__rnt]",
") AS [raw_sql_]",
(visit(o.offset) if o.offset),
"ORDER BY [__rnt].[__rn] ASC"
"ORDER BY [raw_sql_].[__rn] ASC"
].compact.join ' '
end

Expand All @@ -196,7 +196,7 @@ def visit_Arel_Nodes_SelectStatementForComplexCount(o)
("GROUP BY #{core.groups.map { |x| visit x }.join ', ' }" unless core.groups.empty?),
(visit(core.having) if core.having),
("ORDER BY #{o.orders.map{ |x| visit(x) }.join(', ')}" if !o.orders.empty?),
") AS [__rnt]",
") AS [raw_sql_]",
(visit(o.offset) if o.offset)
].compact.join ' '
end
Expand Down Expand Up @@ -335,7 +335,7 @@ def rowtable_projections(o)
x.dup.tap do |p|
p.sub! 'DISTINCT', ''
p.insert 0, visit(o.limit) if o.limit
p.gsub! /\[?#{tn}\]?\./, '[__rnt].'
p.gsub! /\[?#{tn}\]?\./, '[raw_sql_].'
p.strip!
end
end
Expand All @@ -344,7 +344,7 @@ def rowtable_projections(o)
core.projections.map do |x|
x.dup.tap do |p|
p.sub! 'DISTINCT', "DISTINCT #{visit(o.limit)}".strip if o.limit
p.gsub! /\[?#{tn}\]?\./, '[__rnt].'
p.gsub! /\[?#{tn}\]?\./, '[raw_sql_].'
p.strip!
end
end
Expand All @@ -353,9 +353,9 @@ def rowtable_projections(o)
Arel.sql visit(x).split(',').map{ |y| y.split(' AS ').last.strip }.join(', ')
end
elsif select_primary_key_sql?(o)
[Arel.sql("[__rnt].#{quote_column_name(core.projections.first.name)}")]
[Arel.sql("[raw_sql_].#{quote_column_name(core.projections.first.name)}")]
else
[Arel.sql('[__rnt].*')]
[Arel.sql('[raw_sql_].*')]
end
end

Expand Down