Remove apostrophe in query

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

On Mar 1, 10:26 am, LeonS removed_em[email protected] 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?
Thanks

You 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

On 1 March 2010 10:26, LeonS [email protected] 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?
Thanks

You 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.

On Mar 1, 5:26 am, LeonS [email protected] 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 J.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs