method

sanitize_sql_like

Importance_1
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ClassMethods
sanitize_sql_like(string, escape_character = "\\") public

Sanitizes a string so that it is safe to use within an SQL LIKE statement. This method uses escape_character to escape all occurrences of itself, “_” and “%”.

sanitize_sql_like("100% true!")
# => "100\\% true!"

sanitize_sql_like("snake_cased_string")
# => "snake\\_cased\\_string"

sanitize_sql_like("100% true!", "!")
# => "100!% true!!"

sanitize_sql_like("snake_cased_string", "!")
# => "snake!_cased!_string"
Show source
Register or log in to add new notes.