Files

Class/Module Index [+]

Quicksearch

Arel::Visitors::SQLServer

Public Instance Methods

select_count?(o) click to toggle source
# File lib/arel/visitors/sql_server.rb, line 9
def select_count? o
  sel = o.cores.length == 1 && o.cores.first
  projections = sel && sel.projections.length == 1 && sel.projections
  projections && Arel::Nodes::Count === projections.first
end
visit_Arel_Nodes_Lock(o) click to toggle source

MS-SQL doesn't support "SELECT...FOR UPDATE". Instead, it needs WITH(ROWLOCK,UPDLOCK) specified after each table in the FROM clause.

So, we return nothing here and add the appropriate stuff using add_lock! above.

# File lib/arel/visitors/sql_server.rb, line 48
def visit_Arel_Nodes_Lock o
end
visit_Arel_Nodes_SelectStatement(o) click to toggle source

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/sql_server.rb, line 17
def visit_Arel_Nodes_SelectStatement o
  if !o.limit && o.offset
    raise ActiveRecord::ActiveRecordError, "You must specify :limit with :offset."
  end
  order = "ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?
  if o.limit
    if select_count?(o)
      subquery = true
      sql = o.cores.map do |x|
        x = x.dup
        x.projections = [Arel::Nodes::SqlLiteral.new("*")]
        visit_Arel_Nodes_SelectCore x
      end.join
    else
      sql = o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join
    end

    order ||= "ORDER BY #{@connection.determine_order_clause(sql)}"
    replace_limit_offset!(sql, limit_for(o.limit).to_i, o.offset && o.offset.value.to_i, order)
    sql = "SELECT COUNT(*) AS count_id FROM (#{sql}) AS subquery" if subquery
  else
    sql = super
  end
  add_lock!(sql, :lock => o.lock && true)
  sql
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.