[Rails] Bind Variables in Active Record

Dave Steinberg dave at redterror.net
Tue Dec 7 04:08:39 GMT 2004


> 2) Mixing ? and %s is not supported i.e  find_all(["id=? and
> first_name like '%s'", 3 "''''bob'''\'?"])
>
> Is there a legitimate case for this kind of query?

I'd agree with the other comment, I don't think this sort of style should
be encouraged.  I'd vote for converting it into "?"s as the other posted
suggested at least as a transitionary measure, and deprecating it if
possible.

While we're on the topic, I'd like to sneak in a feature request and get
some general feedback.  Could something like this be easily added:

find_all("name = :name AND job = :job", :name => "Bob Dole", :job =>
"Comedian")

I got to liking this style at my day job, so I thought I'd throw it out
there to see if anyone else is interested.  Not a big deal obviously, but
I find it more readable and it prevents me from messing up the order of
the bind variables.

Regards,
-- 
Dave Steinberg
http://www.geekisp.com/



More information about the Rails mailing list