Extra quotes when substittuting for ? in find_by_sql

Hi,

I’m trying to select items created within a certain date range, but seem
to keep getting a small syntax error - extra single quotes - whenever I
try to use the built in range helper.

This works fine.

@temp_top_ten = Video.find_by_sql([“select * from votes WHERE created_at
BETWEEN ? AND ?”, (1.month.ago).to_s(:db), (Time.now).to_s(:db)])

But when I combine them to use the helper link this:

@temp_top_ten = Video.find_by_sql([“select * from votes WHERE created_at
?”, (1.month.ago…Time.now).to_s(:db)])

I get this error MYSQL error becuase my querry is formatted by rails
with extra quotes and escaped quotes: select * from votes WHERE
created_at ‘BETWEEN ‘2007-12-03 17:17:07’ AND ‘2008-01-02 17:17:07’’

Is there some trick to correct this formating? Thanks so much for the
help!

On 1/2/08, Mario F. [email protected] wrote:

@temp_top_ten = Video.find_by_sql([“select * from votes WHERE created_at
?”, (1.month.ago…Time.now).to_s(:db)])

Vote.find( :all, :conditions => [ “created_at #{
(5.days.ago…Time.now).to_s(:db) }” ] )

–
Greg D.
http://destiney.com/

Thanks, Greg!

I only wish I could use the built in find methods. I didn’t include my
whole query so I could keep my question easy to read, but I’ve got a
number of other conditions and counting going on that prevent me from
using those built in methods. My votes table is also going to be quite
large, so I’m trying to keep as much as possible in sql for performance
reasons.

Thanks!

On Jan 2, 2:27 pm, Mario F. [email protected]
wrote:

I get this error MYSQL error becuase my querry is formatted by rails
with extra quotes and escaped quotes: select * from votes WHERE
created_at ‘BETWEEN '2007-12-03 17:17:07' AND '2008-01-02 17:17:07'’

As far as I can see, this bug isn’t in the ActiveRecord class, but by
the connector’s quote method.

Just in case you wanted to track the problem down yourself.

///ark