Module: ArJdbc::MSSQL::ExplainSupport
- Included in:
- ArJdbc::MSSQL
- Defined in:
- lib/arjdbc/mssql/explain_support.rb
Constant Summary collapse
- DISABLED =
Java::JavaLang::Boolean.getBoolean('arjdbc.mssql.explain_support.disabled')
Instance Method Summary collapse
- #explain(arel, binds = []) ⇒ Object
- #set_showplan_option(enable = true) ⇒ Object protected
- #supports_explain? ⇒ Boolean
- #with_showplan_on ⇒ Object protected
Instance Method Details
#explain(arel, binds = []) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/arjdbc/mssql/explain_support.rb', line 11 def explain(arel, binds = []) return if DISABLED sql = to_sql(arel, binds) result = with_showplan_on { exec_query(sql, 'EXPLAIN', binds) } PrinterTable.new(result).pp end |
#set_showplan_option(enable = true) ⇒ Object (protected)
27 28 29 30 31 32 33 |
# File 'lib/arjdbc/mssql/explain_support.rb', line 27 def set_showplan_option(enable = true) option = 'SHOWPLAN_TEXT' execute "SET #{option} #{enable ? 'ON' : 'OFF'}" rescue Exception => e raise ActiveRecord::ActiveRecordError, "#{option} could not be turned" + " #{enable ? 'ON' : 'OFF'} (check SHOWPLAN permissions) due : #{e.inspect}" end |
#supports_explain? ⇒ Boolean
9 |
# File 'lib/arjdbc/mssql/explain_support.rb', line 9 def supports_explain?; ! DISABLED; end |
#with_showplan_on ⇒ Object (protected)
20 21 22 23 24 25 |
# File 'lib/arjdbc/mssql/explain_support.rb', line 20 def with_showplan_on set_showplan_option(true) yield ensure set_showplan_option(false) end |