Skip to content
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

Fix query builder bug when params[:q] specified #868

Merged

Conversation

mariusz-blaszczak
Copy link
Contributor

@mariusz-blaszczak mariusz-blaszczak commented Jan 14, 2019

Background

While developing a rails app with camaleon_cms I encountered a bug: #866

I guess it occurs only with postgresql, because I wrote a tmp test inside camaleon_cms gem(which uses sqllite in dummy app) and it wasn't failing.

The problem

The problem was wrong place of closing parenthesis of postgres function LOWER.
When it was after "?" sign, it was causing exception in PG query runner.

It was the query before fix:

SELECT COUNT(DISTINCT "cama_posts"."id")
FROM "cama_posts"
       LEFT OUTER JOIN "cama_posts" "parents_cama_posts" ON "parents_cama_posts"."id" = "cama_posts"."post_parent"
    AND "parents_cama_posts"."post_class" = 'Post'
       LEFT OUTER JOIN "cama_term_taxonomy" ON "cama_term_taxonomy"."id" = "cama_posts"."taxonomy_id" AND
                                               "cama_term_taxonomy"."taxonomy" = 'post_type'
WHERE "cama_posts"."post_class" = 'Post'
  AND "cama_posts"."taxonomy_id" = 2
  AND (LOWER(cama_posts.title) LIKE '%abcd%' OR LOWER(cama_posts.slug LIKE '%abcd%'))
  AND "cama_posts"."status" = 'published'

The fix:

Move closing parenthesis of PG LOWER func to the of slug column.

AND (LOWER(cama_posts.title) LIKE '%abcd%' OR LOWER(cama_posts.slug) LIKE '%abcd%')

More description details about the issue you can find here: #866

Move closing parenthesis of PG LOWER func to the of slug column.

When it was after "?" sign, it was causing exception in PG query runner.
@owen2345 owen2345 merged commit 1cf1126 into owen2345:master Jan 14, 2019
@mariusz-blaszczak mariusz-blaszczak deleted the buxfix/lower-func-in-wrong-place branch January 14, 2019 14:40
@mariusz-blaszczak mariusz-blaszczak restored the buxfix/lower-func-in-wrong-place branch January 14, 2019 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants