module ActiveRecord::ConnectionAdapters::SQLServer::Showplan

Constants

OPTIONS
OPTION_ALL
OPTION_TEXT
OPTION_XML

Public Instance Methods

explain(arel, binds = []) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 14
def explain(arel, binds = [])
  sql = to_sql(arel)
  result = with_showplan_on { sp_executesql(sql, 'EXPLAIN', binds) }
  printer = showplan_printer.new(result)
  printer.pp
end

Protected Instance Methods

set_showplan_option(enable = true) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 30
def set_showplan_option(enable = true)
  sql = "SET #{showplan_option} #{enable ? 'ON' : 'OFF'}"
  raw_connection_do(sql)
rescue Exception
  raise ActiveRecordError, "#{showplan_option} could not be turned #{enable ? 'ON' : 'OFF'}, perhaps you do not have SHOWPLAN permissions?"
end
showplan_all?() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 43
def showplan_all?
  showplan_option == OPTION_ALL
end
showplan_option() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 37
def showplan_option
  (SQLServerAdapter.showplan_option || OPTION_ALL).tap do |opt|
    raise(ArgumentError, "Unknown SHOWPLAN option #{opt.inspect} found.") if OPTIONS.exclude?(opt)
  end
end
showplan_printer() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 55
def showplan_printer
  case showplan_option
  when OPTION_XML then PrinterXml
  when OPTION_ALL, OPTION_TEXT then PrinterTable
  else PrinterTable
  end
end
showplan_text?() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 47
def showplan_text?
  showplan_option == OPTION_TEXT
end
showplan_xml?() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 51
def showplan_xml?
  showplan_option == OPTION_XML
end
with_showplan_on() { || ... } click to toggle source
# File lib/active_record/connection_adapters/sqlserver/showplan.rb, line 23
def with_showplan_on
  set_showplan_option(true)
  yield
ensure
  set_showplan_option(false)
end