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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2008-Jan-03 01:34 UTC
Re: Extra quotes when substittuting for ? in find_by_sql
On 1/2/08, Mario Flores <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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)])Vote.find( :all, :conditions => [ "created_at #{ (5.days.ago..Time.now).to_s(:db) }" ] ) -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mario Flores
2008-Jan-03 01:39 UTC
Re: Extra quotes when substittuting for ? in find_by_sql
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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Wilden
2008-Jan-03 02:29 UTC
Re: Extra quotes when substittuting for ? in find_by_sql
On Jan 2, 2:27 pm, Mario Flores <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---