I''m getting: malformed format string - %'' When I do something like this: $milestone = "(target_milestone LIKE ''1.0 %'' OR target_milestone LIKE ''TBD%'')" [...] @cond = $open_bugs + " AND product like ''" + $product_name + "''" if $milestone.length > 0 @cond += " AND " + $milestone end [...] @pa_bugs = Bug.find(:all, :conditions => [ @cond \ + " AND priority = ''" + @pri["priority"] + "''" \ + " AND assigned_to = ''" + @asn["assigned_to"].to_s + "''" ], :select => ''bug_id'' ) If I take out the %, no malformed string but, also, wrong search conditions. Can anyone explain what I''m seeing, why, and how to fix it? Thanks! P.S. I searched the archives for "wildcard" and saw a few posts, but none that spoke to this issue. Likewise, Googling ruby rails select percent "malformed format string" didn''t turn up anything helpful. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-03 08:04 UTC
Re: [n00b] wildcard :select in find(:all) -> malformed string
Who is throwing the error: the database or ruby? What is the actualy query that the database handles ? Also do you realise that you could do @pa_bugs = Bug.find(:all, :conditions => [ @cond + " AND priority = ? AND assigned_to = ?", @pri["priority"], @asn["assigned_to"]], :selec => ''bug_id'' Which is both more readable and not vulnerable to sql injection type errors. Fred On 3 Oct 2007, at 01:17, Olie D. wrote:> > > I''m getting: > > malformed format string - %'' > > When I do something like this: > > $milestone = "(target_milestone LIKE ''1.0 %'' OR target_milestone > LIKE ''TBD%'')" > [...] > @cond = $open_bugs + " AND product like ''" + $product_name + "''" > if $milestone.length > 0 > @cond += " AND " + $milestone > end > [...] > @pa_bugs = Bug.find(:all, > :conditions => [ @cond \ > + " AND priority = ''" + > @pri["priority"] + "''" \ > + " AND assigned_to = ''" + > @asn["assigned_to"].to_s + "''" > ], > :select => ''bug_id'' > ) > > If I take out the %, no malformed string but, also, wrong search > conditions. > > Can anyone explain what I''m seeing, why, and how to fix it? > > Thanks! > > P.S. I searched the archives for "wildcard" and saw a few posts, but > none that spoke to this issue. Likewise, Googling > > ruby rails select percent "malformed format string" > > didn''t turn up anything helpful. > -- > 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 -~----------~----~----~----~------~----~------~--~---