mysql - Escape character for underscore in Ruby on Rails queries -


what i'm trying write query following:

foo.where("bar 'bam\_%'") 

the idea being return rows bar, contains string, starts 'bam_' , of indeterminate length thereafter. i've tried pure mysql query in mysql workbench , seems work expected. when in ror, however, seems ignore escape character , treats underscore wildcard is. there not way write in rails can include underscore in query? thanks.

the backslash escape character in ruby strings, \_ means treat _ literal. since _ treated literal anyway, nothing, except treat \ if wasn't there. 1 of ways have backslash in string given ruby literal escape using backslash (e.g. "bar 'bam\\_%'").


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -