Skip to content
Merged
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
20 changes: 10 additions & 10 deletions lib/arel/visitors/sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def visit_Arel_Nodes_SelectStatementWithOutOffset(o, a, windowed = false)
(projections.map{ |x| v = visit(x); v == "1" ? "1 AS [__wrp]" : v }.join(', ')),
(source_with_lock_for_select_statement(o)),
("WHERE #{core.wheres.map{ |x| visit(x) }.join ' AND ' }" unless core.wheres.empty?),
("GROUP BY #{groups.map { |x| visit x }.join ', ' }" unless groups.empty?),
("GROUP BY #{groups.map { |x| visit(x) }.join ', ' }" unless groups.empty?),
(visit(core.having) if core.having),
("ORDER BY #{orders.map{ |x| visit(x) }.join(', ')}" if !orders.empty? && !windowed)
].compact.join ' '
Expand Down Expand Up @@ -183,18 +183,18 @@ def single_distinct_select_statement?(o)
((p1.respond_to?(:distinct) && p1.distinct) ||
p1.respond_to?(:include?) && p1.include?('DISTINCT'))
end

def windowed_single_distinct_select_statement?(o)
o.limit && o.offset && single_distinct_select_statement?(o)
end

def single_distinct_select_everything_statement?(o)
single_distinct_select_statement?(o) && visit(o.cores.first.projections.first).ends_with?(".*")
end

def top_one_everything_for_through_join?(o)
single_distinct_select_everything_statement?(o) &&
(o.limit && !o.offset) &&
single_distinct_select_everything_statement?(o) &&
(o.limit && !o.offset) &&
join_in_select_statement?(o)
end

Expand All @@ -212,9 +212,9 @@ def function_select_statement?(o)

def eager_limiting_select_statement?(o)
core = o.cores.first
single_distinct_select_statement?(o) &&
(o.limit && !o.offset) &&
core.groups.empty? &&
single_distinct_select_statement?(o) &&
(o.limit && !o.offset) &&
core.groups.empty? &&
!single_distinct_select_everything_statement?(o)
end

Expand All @@ -230,7 +230,7 @@ def complex_count_sql?(o)
o.limit &&
!join_in_select_statement?(o)
end

def select_primary_key_sql?(o)
core = o.cores.first
return false if core.projections.size != 1
Expand Down