class TingYun::Agent::Database::Statement
Constants
- SUPPORTED_ADAPTERS_FOR_EXPLAIN
Attributes
binds[RW]
config[RW]
explainer[RW]
name[RW]
sql[RW]
Public Class Methods
new(sql, config={}, explainer=nil, binds=[], name=DEFAULT_QUERY_NAME)
click to toggle source
# File lib/ting_yun/agent/database/statement.rb, line 13 def initialize(sql, config={}, explainer=nil, binds=[], name=DEFAULT_QUERY_NAME) @sql = TingYun::Agent::Database.capture_query(sql) @config = config @explainer = explainer @binds = binds @name = name end
Public Instance Methods
adapter()
click to toggle source
# File lib/ting_yun/agent/database/statement.rb, line 21 def adapter return unless @config @adapter ||= if @config[:adapter] symbolized_adapter(@config[:adapter].to_s.downcase) elsif @config[:uri] && @config[:uri].to_s =~ /^jdbc:([^:]+):/ # This case is for Sequel with the jdbc-mysql, jdbc-postgres, or jdbc-sqlite3 gems. symbolized_adapter($1) else nil end end
explain()
click to toggle source
# File lib/ting_yun/agent/database/statement.rb, line 38 def explain return unless explainable? handle_exception_in_explain do plan = explainer.call(self) return process_resultset(plan, adapter) if plan end end
explainable?()
click to toggle source
# File lib/ting_yun/agent/database/statement.rb, line 47 def explainable? return false unless @explainer && is_select?(sql) if sql[-3,3] == '...' TingYun::Agent.logger.debug('Unable to collect explain plan for truncated query.') return false end if parameterized?(@sql) && @binds.empty? TingYun::Agent.logger.debug('Unable to collect explain plan for parameter-less parameterized query.') return false end if !SUPPORTED_ADAPTERS_FOR_EXPLAIN.include?(adapter) TingYun::Agent.logger.debug("Not collecting explain plan because an unknown connection adapter ('#{adapter}') was used.") return false end true end