File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,20 @@ class PG::Connection
39
39
alias_method :exec_params_without_profiling , :exec_params
40
40
end
41
41
42
+ def prepare_parameterized_statement ( args )
43
+ if Array === args [ 1 ] && args [ 1 ] . length > 0
44
+ query = args [ 0 ]
45
+ parameters = args [ 1 ]
46
+ counter = 0
47
+ loop do
48
+ break if !query . include? "$#{ counter +=1 } "
49
+ parameter = parameters [ counter -1 ] . is_a? ( String ) ? "'#{ parameters [ counter -1 ] . gsub ( "'" , "''" ) } '" : parameters [ counter -1 ]
50
+ query = query . sub ( "$#{ counter } " , parameter . to_s )
51
+ end
52
+ end
53
+ query
54
+ end
55
+
42
56
def prepare ( *args , &blk )
43
57
# we have no choice but to do this here,
44
58
# if we do the check for profiling first, our cache may miss critical stuff
@@ -58,7 +72,8 @@ def exec(*args, &blk)
58
72
start = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
59
73
result = exec_without_profiling ( *args , &blk )
60
74
elapsed_time = SqlPatches . elapsed_time ( start )
61
- record = ::Rack ::MiniProfiler . record_sql ( args [ 0 ] , elapsed_time )
75
+ query_with_params = prepare_parameterized_statement ( args )
76
+ record = ::Rack ::MiniProfiler . record_sql ( query_with_params , elapsed_time )
62
77
result . instance_variable_set ( "@miniprofiler_sql_id" , record ) if result
63
78
64
79
result
You can’t perform that action at this time.
0 commit comments