-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prepare parametrized PG query for showing query parameters in web panel #405
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Since Rails 5 has parametrizied query statement like this:
SELECT * FROM 'items' WHERE 'item'.'id' = $1 [['id',123]]
So in panel we see
$1
instead of123
Params 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