How does one write a prepared statement with LIKE using find_by_sql. For example the problem with soemthing like this is that extra quotes are put around the ? Product.find_by_sql(["SELECT * FROM products WHERE name LIKE ''%?%''"], params[:name]) Thanks John --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2007 9:07 AM, jmark <jmark-GzgP2VM9KJ0N+BqQ9rBEUg@public.gmane.org> wrote:> > How does one write a prepared statement with LIKE using find_by_sql. > > For example the problem with soemthing like this is that extra quotes > are put around the ? > Product.find_by_sql(["SELECT * FROM products WHERE name LIKE ''%?%''"], > params[:name])Perhaps you could try Product.find_by_sql(["SELECT * FROM products WHERE name LIKE ?"], "%#{params[:name]}%") Not positive it''ll work though. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you Pat. Your solution worked On Dec 16, 11:15 am, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 16, 2007 9:07 AM, jmark <jm...-GzgP2VM9KJ0N+BqQ9rBEUg@public.gmane.org> wrote: > > > > > How does one write a prepared statement with LIKE using find_by_sql. > > > For example the problem with soemthing like this is that extra quotes > > are put around the ? > > Product.find_by_sql(["SELECT * FROM products WHERE name LIKE ''%?%''"], > > params[:name]) > > Perhaps you could try > Product.find_by_sql(["SELECT * FROM products WHERE name LIKE ?"], > "%#{params[:name]}%") > > Not positive it''ll work though. > > Pat--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---