I'm trying to write LIKE query.
I read that pure string quires aren't safe, however I couldn't find any documentation that explain how to write safe LIKE Hash Query.
Is it possible? Should I manually defend against SQL Injection?
I'm trying to write LIKE query.
I read that pure string quires aren't safe, however I couldn't find any documentation that explain how to write safe LIKE Hash Query.
Is it possible? Should I manually defend against SQL Injection?
You can do
For PostgreSQL it will be
To ensure that your query string gets properly sanitized, use the array or the hash query syntax to describe your conditions:
or:
If it is possible that the
query
might include the%
character then you need to sanitizequery
withsanitize_sql_like
first:Using Arel you can perform this safe and portable query: