Class: Rack::Bug::SQLPanel::QueryResult
- Inherits:
-
Object
- Object
- Rack::Bug::SQLPanel::QueryResult
show all
- Includes:
- FilteredBacktrace
- Defined in:
- lib/rack/bug/panels/sql_panel/query.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#backtrace, backtrace_regexp, #filtered_backtrace, #has_backtrace?, root_for_backtrace_filtering
Constructor Details
#initialize(sql, time, backtrace = [], result = nil) ⇒ QueryResult
Returns a new instance of QueryResult.
11
12
13
14
15
16
17
18
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 11
def initialize(sql, time, backtrace = [], result=nil)
Rails.logger.debug{ "QueryResult: #{sql}" }
@sql = sql
@time = time
@backtrace = backtrace
@result = result
@results = nil
end
|
Instance Attribute Details
#sql ⇒ Object
Returns the value of attribute sql.
8
9
10
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 8
def sql
@sql
end
|
#time ⇒ Object
Returns the value of attribute time.
9
10
11
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 9
def time
@time
end
|
Class Method Details
.execute(sql) ⇒ Object
Downside is: we re-execute the SQL…
52
53
54
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 52
def self.execute(sql)
ActiveRecord::Base.connection.execute(sql)
end
|
Instance Method Details
#column_names ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 25
def column_names
if result.respond_to?(:fields)
return result.fields
else
return result.fetch_fields.map{|col| col.name}
end
end
|
#execute ⇒ Object
56
57
58
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 56
def execute
self.class.execute(@sql)
end
|
#human_time ⇒ Object
43
44
45
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 43
def human_time
"%.2fms" % (@time * 1_000)
end
|
#inspectable? ⇒ Boolean
47
48
49
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 47
def inspectable?
sql.strip =~ /^SELECT /i
end
|
#result ⇒ Object
20
21
22
23
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 20
def result
@results ||= execute
return @results
end
|
#rows ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 33
def rows
if result.respond_to?(:values)
result.values
else
result.map do |row|
row
end
end
end
|
#valid_hash?(secret_key, possible_hash) ⇒ Boolean
60
61
62
63
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 60
def valid_hash?(secret_key, possible_hash)
hash = Digest::SHA1.hexdigest [secret_key, @sql].join(":")
possible_hash == hash
end
|