[n00b] wildcard :select in find(:all) -> malformed string

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.

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