class QueryReviewer::SqlSubQuery

a single part of an SQL SELECT query

Attributes

cols[R]
parent[R]
warnings[R]

Public Class Methods

new(parent, cols) click to toggle source
Calls superclass method
# File lib/query_reviewer/sql_sub_query.rb, line 8
def initialize(parent, cols)
  @parent = parent
  @warnings = []
  @cols = cols.inject({}) {|memo, obj| memo[obj[0].to_s.downcase] = obj[1].to_s.downcase; memo }
  @cols["query_type"] = @cols.delete("type")
  super(@cols)
end

Public Instance Methods

analyze!() click to toggle source
# File lib/query_reviewer/sql_sub_query.rb, line 16
def analyze!
  @warnings = []
  adapter_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:adapter]
  adapter_name = 'mysql' if adapter_name == 'mysql2'
  method_name = "do_#{adapter_name}_analysis!"
  self.send(method_name.to_sym)
end
table() click to toggle source
# File lib/query_reviewer/sql_sub_query.rb, line 24
def table
  @table[:table]
end

Private Instance Methods

praise(options) click to toggle source
# File lib/query_reviewer/sql_sub_query.rb, line 41
def praise(options)
  # no credit, only pain
end
warn(options) click to toggle source
# File lib/query_reviewer/sql_sub_query.rb, line 30
def warn(options)
  if (options[:field])
    field = options.delete(:field)
    val = self.send(field)
    options[:problem] = ("#{field.to_s.titleize}: #{val.blank? ? "(blank)" : val}")
  end
  options[:query] = self
  options[:table] = self.table
  @warnings << QueryWarning.new(options)
end