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
3939 alias_method :exec_params_without_profiling , :exec_params
4040 end
4141
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+
4256 def prepare ( *args , &blk )
4357 # we have no choice but to do this here,
4458 # if we do the check for profiling first, our cache may miss critical stuff
@@ -58,7 +72,8 @@ def exec(*args, &blk)
5872 start = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
5973 result = exec_without_profiling ( *args , &blk )
6074 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 )
6277 result . instance_variable_set ( "@miniprofiler_sql_id" , record ) if result
6378
6479 result
You can’t perform that action at this time.
0 commit comments