7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/query_console/queries_controller.rb', line 7
def run
sql = params[:sql]
if sql.blank?
@result = Runner::QueryResult.new(error: "Query cannot be empty")
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace("query-results", partial: "results", locals: { result: @result }) }
format.html { render :_results, layout: false }
end
return
end
config = QueryConsole.configuration
if config.enable_dml
normalized_sql = sql.strip.downcase
if normalized_sql.match?(/\A(insert|update|delete|merge)\b/)
unless params[:dml_confirmed] == 'true'
@result = Runner::QueryResult.new(
error: "DML query execution requires user confirmation. Please confirm the operation to proceed."
)
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace("query-results", partial: "results", locals: { result: @result, is_dml: false }) }
format.html { render :_results, layout: false }
end
return
end
end
end
runner = Runner.new(sql)
@result = runner.execute
@is_dml = @result.dml?
AuditLogger.log_query(
sql: sql,
result: @result,
controller: self
)
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"query-results",
partial: "results",
locals: { result: @result, is_dml: @is_dml }
)
end
format.html { render :_results, layout: false }
end
end
|