Prepare parametrized PG query for showing query parameters in web panel#405
Prepare parametrized PG query for showing query parameters in web panel#405unavailabl3 wants to merge 1 commit intoMiniProfiler:masterfrom
Conversation
584553e to
006120a
Compare
lib/patches/db/pg.rb
Outdated
| counter = 0 | ||
| loop do | ||
| break if !query.include? "$#{counter+=1}" | ||
| query = query.sub("$#{counter}",parameters[counter-1].to_s) |
There was a problem hiding this comment.
subbing is a bit confusing and can cause a nonsense query to be logged in some cases. For example:
$1 -> hello world's, which technically would need to be 'hello world''s' I think
There was a problem hiding this comment.
an alternative may be a preamble comment that explains the param so there is not confusion. also I think you technically want gsub here, also what if more than 10 params?
$1 -> \* $1 *\ 'hello-world''s'
There was a problem hiding this comment.
What will happen if more than 10 params?
Example from my project
SELECT tag_id FROM categories_tags WHERE category_id IN (11,3001,8794,8797,8788,8784,8783,3682,8789,3683,3680,3005,3686,3685,3684,3681,3679,8793,8787,3004,3006,8343,8791,8348,8354,3000,3003,3010,3007,3002,2999,8792,8795);
|
This is still an issue on |
|
I like having the parameters separate. I want to know what is actually sent to the server. (easier to detect N+1). Is the issue that the parameters are not showing in the UI? But comment if you feel we should modify the sql before we store it. I can look at this. Also, historically, I was under the impression that people were concerned about the parameter values being leaked. It may be the reason the parameters were not included into the ui. Not sure if the hide parameter regex met people's concerns. |
|
Then again, I always put the params back into the query when running it. |
Since Rails 5 has parametrizied query statement like this:
SELECT * FROM 'items' WHERE 'item'.'id' = $1 [['id',123]]So in panel we see
$1instead of123Params are not shown in rack-mini-profiler panel. This commit is a hack (ONLY FOR POSTGRESQL) to see params. Like this we can add for other DBs.
P.S. May be commit needs refactoring for optimization