1 require 'arel/visitors/compat'
5 class SQLServer < Arel::Visitors::ToSql
6 include ArJdbc::MsSQL::LimitHelpers::SqlServerReplaceLimitOffset
9 sel = o.cores.length == 1 && o.cores.first
10 projections = sel && sel.projections.length == 1 && sel.projections
11 projections && Arel::Nodes::Count === projections.first
14 # Need to mimic the subquery logic in ARel 1.x for select count with limit
15 # See arel/engines/sql/compilers/mssql_compiler.rb for details
16 def visit_Arel_Nodes_SelectStatement o
17 order = "ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?
21 sql = o.cores.map do |x|
23 x.projections = [Arel::Nodes::SqlLiteral.new("*")]
24 visit_Arel_Nodes_SelectCore x
27 sql = o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join
30 order ||= "ORDER BY #{@connection.determine_order_clause(sql)}"
31 replace_limit_offset!(sql, limit_for(o.limit).to_i, o.offset && o.offset.value.to_i, order)
32 sql = "SELECT COUNT(*) AS count_id FROM (#{sql}) AS subquery" if subquery
40 class SQLServer2000 < SQLServer
41 include ArJdbc::MsSQL::LimitHelpers::SqlServer2000ReplaceLimitOffset