diff --git a/lib/patches/db/pg.rb b/lib/patches/db/pg.rb index b355b2a8..89b481b8 100644 --- a/lib/patches/db/pg.rb +++ b/lib/patches/db/pg.rb @@ -39,6 +39,19 @@ class PG::Connection alias_method :exec_params_without_profiling, :exec_params end + def prepare_parameterized_statement(args) + if if Array === args[1] && args[1].length > 0 + query = args[0] + parameters = args[1] + counter = 0 + loop do + break if !query.include? "$#{counter+=1}" + query = query.sub("$#{counter}",parameters[counter-1].to_s) + end + end + query + end + def prepare(*args, &blk) # we have no choice but to do this here, # if we do the check for profiling first, our cache may miss critical stuff @@ -58,6 +71,7 @@ def exec(*args, &blk) start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = exec_without_profiling(*args, &blk) elapsed_time = SqlPatches.elapsed_time(start) + args[0] = prepare_parameterized_statement(args) record = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time) result.instance_variable_set("@miniprofiler_sql_id", record) if result