Arel::Visitors::ToSql
# File lib/arel/visitors/mssql.rb, line 6
6: def select_count? o
7: sel = o.cores.length == 1 && o.cores.first
8: projections = sel.projections.length == 1 && sel.projections
9: Arel::Nodes::Count === projections.first
10: end
Need to mimic the subquery logic in ARel 1.x for select count with limit See arel/engines/sql/compilers/mssql_compiler.rb for details
# File lib/arel/visitors/mssql.rb, line 14
14: def visit_Arel_Nodes_SelectStatement o
15: order = "ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?
16: if o.limit
17: if select_count?(o)
18: subquery = true
19: sql = o.cores.map do |x|
20: x = x.dup
21: x.projections = [Arel::Nodes::SqlLiteral.new("*")]
22: visit_Arel_Nodes_SelectCore x
23: end.join
24: else
25: sql = o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join
26: end
27:
28: order ||= "ORDER BY #{@connection.determine_order_clause(sql)}"
29: replace_limit_offset!(sql, o.limit.to_i, o.offset && o.offset.value.to_i, order)
30: sql = "SELECT COUNT(*) AS count_id FROM (#{sql}) AS subquery" if subquery
31: elsif order
32: sql << " #{order}"
33: else
34: sql = super
35: end
36: sql
37: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.