Class: QueryReviewer::SqlSubQuery

Inherits:
OpenStruct
  • Object
show all
Includes:
MysqlAnalyzer
Defined in:
lib/query_reviewer/sql_sub_query.rb

Overview

a single part of an SQL SELECT query

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MysqlAnalyzer

#analyze_extras!, #analyze_key!, #analyze_keylen!, #analyze_query_type!, #analyze_select_type!, #do_mysql_analysis!

Constructor Details

#initialize(parent, cols) ⇒ SqlSubQuery

Returns a new instance of SqlSubQuery.



8
9
10
11
12
13
14
# 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

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



7
8
9
# File 'lib/query_reviewer/sql_sub_query.rb', line 7

def cols
  @cols
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/query_reviewer/sql_sub_query.rb', line 7

def parent
  @parent
end

#warningsObject (readonly)

Returns the value of attribute warnings.



7
8
9
# File 'lib/query_reviewer/sql_sub_query.rb', line 7

def warnings
  @warnings
end

Instance Method Details

#analyze!Object



16
17
18
19
20
21
22
# 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

#tableObject



24
25
26
# File 'lib/query_reviewer/sql_sub_query.rb', line 24

def table
  @table[:table]
end