Hi, I want to generate a query with conditions like that :conditions => ["score_team_1 ? score_team_2", compare_sign] . The resulting query ends e.g. with score_team_1 ''='' score_team_2 How can i remove the apostrophes from include into the string? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 1, 10:26 am, LeonS <leonard.stellbr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I want to generate a query with conditions like that > > :conditions => ["score_team_1 ? score_team_2", compare_sign] . > > The resulting query ends e.g. with score_team_1 ''='' score_team_2 > How can i remove the apostrophes from include into the string? > ThanksYou can''t really do that like this - bind variables as designed for inserting literals. ''Normal'' ruby interpolation might be the way forward here (assuming that compare sign is coming from a trusted source, if not sanitize it first). Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 March 2010 10:26, LeonS <leonard.stellbrink-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The resulting query ends e.g. with score_team_1 ''='' score_team_2 > How can i remove the apostrophes from include into the string? > ThanksYou don''t need to use the array to populate conditions, as long as the "compare_sign" isn''t user-supplied data; ie: you *know* that it isn''t going to contain something that will compromise your DB, because you set it earlier. :conditions => "score_team_1 #{compare_sign} score_team_2" ...but there''s probably a *nice* way of doing it. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 1, 5:26 am, LeonS <leonard.stellbr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I want to generate a query with conditions like that > > :conditions => ["score_team_1 ? score_team_2", compare_sign] . > > The resulting query ends e.g. with score_team_1 ''='' score_team_2 > How can i remove the apostrophes from include into the string?You could also consider switching the way the condition is defined: score_team_1 < score_team_2 is equivalent to: score_team_1 - score_team_2 < 0 which (on MySQL - check your DB for details) is equivalent to: SIGN(score_team_1 - score_team_2) = -1 The last form is handy, as the number at the end controls whether you end up with < or >. No idea if the different queries might have different performance - try it and see, if it''s an issue. --Matt Jones -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.