Class: Rack::Bug::SQLPanel::Query
- Inherits:
-
Object
- Object
- Rack::Bug::SQLPanel::Query
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, #filtered_backtrace, #has_backtrace?, #root_for_backtrace_filtering
Constructor Details
#initialize(sql, time, backtrace = []) ⇒ Query
Returns a new instance of Query.
11
12
13
14
15
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 11
def initialize(sql, time, backtrace = [])
@sql = sql
@time = time
@backtrace = backtrace
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
56
57
58
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 56
def self.execute(sql)
ActiveRecord::Base.connection.execute(sql)
end
|
Instance Method Details
#execute ⇒ Object
47
48
49
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 47
def execute
self.class.execute(@sql)
end
|
#explain ⇒ Object
32
33
34
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 32
def explain
self.class.execute "EXPLAIN #{@sql}"
end
|
#human_time ⇒ Object
17
18
19
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 17
def human_time
"%.2fms" % (@time * 1_000)
end
|
#inspectable? ⇒ Boolean
21
22
23
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 21
def inspectable?
sql.strip =~ /^SELECT /i
end
|
#profile ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 36
def profile
with_profiling do
execute
self.class.execute <<-SQL
SELECT *
FROM information_schema.profiling
WHERE query_id = (SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)
SQL
end
end
|
#valid_hash?(secret_key, possible_hash) ⇒ Boolean
51
52
53
54
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 51
def valid_hash?(secret_key, possible_hash)
hash = Digest::SHA1.hexdigest [secret_key, @sql].join(":")
possible_hash == hash
end
|
#with_profiling ⇒ Object
25
26
27
28
29
30
|
# File 'lib/rack/bug/panels/sql_panel/query.rb', line 25
def with_profiling
self.class.execute("SET PROFILING=1")
result = yield
self.class.execute("SET PROFILING=0")
return result
end
|