method

sanitize_sql_like

Importance_1
v5.2.3 - Show latest stable - 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 “", ”_“ and ”%“.

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

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

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

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