Somehow I can not get the wildcard character "%" to work when using a MySQL find_by_sql statement... As soon as I remove the % character everything works... Is there a workaround, another character to be used ? Thank you very much ! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in order to use the wildcard % you need to use th LIKE statement. select * from table where column like ''%''; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ja Bo wrote:> > Somehow I can not get the wildcard character "%" to work when using a > MySQL find_by_sql statement... > As soon as I remove the % character everything works... > Is there a workaround, another character to be used ? > > Thank you very much !Do you have to drop down to find_by_sql, or can you use a normal find? Example: pages = Page.find(:all, :conditions => "name like ''Wiki%''") or prefix = ''Wiki'' pages = Page.find(:all, :conditions => [''name like ?'', prefix + ''%'']) The key thing is that you need to put the % in the argument you are supplying, because when Rails does substitution into the placeholder (?) it will be doing escaping and quoting for you. regards Justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---