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

Cast all search queries to text. #1079

Merged
merged 1 commit into from
Jan 31, 2018
Merged

Cast all search queries to text. #1079

merged 1 commit into from
Jan 31, 2018

Conversation

nickcharlton
Copy link
Member

All Postgres versions since 8.4 require this to be a string. This casts
the table and column to be strings as it's possible that the column name
is nil.

Fixes #620.

@@ -24,7 +24,7 @@ def query
table_name = ActiveRecord::Base.connection.
quote_table_name(@scoped_resource.table_name)
attr_name = ActiveRecord::Base.connection.quote_column_name(attr)
"lower(#{table_name}.#{attr_name}) LIKE ?"
"lower(text(#{table_name}.#{attr_name})) LIKE ?"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are writing the SQL keyword LIKE in all caps, how would you feel about doing LOWER and TEXT in all caps as well? I do this in my SQL style so that keywords and column names are clearly separated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, nice. I'll do that, it's much nicer.

"lower(\"users\".\"name\") LIKE ?"\
" OR lower(\"users\".\"email\") LIKE ?",
"lower(text(\"users\".\"name\")) LIKE ?"\
" OR lower(text(\"users\".\"email\")) LIKE ?",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we write OR and LIKE in caps, but not LOWER or TEXT.

All Postgres versions since 8.4 require this to be a string. This casts
the table and column to be strings as it's possible that the column name
is nil.

Fixes #620.
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