I tried to use named parameters in my SQL query , using find_by_sql Order.find_by_sql ([select * from orders where amount > ? and quantity > ?", [ @amount, @quantity ] works;.. but Order.find_by_sql ([select * from orders where amount > :amount and quantity > :quantity ", [ :amount => @amt, :quantity => @qty ] is not working a I wrong or should I use a plain select string ? tfyl kad -- 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-20 19:01 UTC
Re: find_by_sql with named parameterized sql
The latter isn''t working because you are inserting symbols directly in the sql, and as far as I know this isn''t allowed. What''s wrong with using the first alternative? On Jan 20, 3:39 pm, Kad Kerforn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I tried to use named parameters in my SQL query , using find_by_sql > > Order.find_by_sql ([select * from orders where amount > ? and quantity > > ?", [ @amount, @quantity ] works;.. > but > Order.find_by_sql ([select * from orders where amount > :amount and > quantity > :quantity ", [ :amount => @amt, :quantity => @qty ] is not > working > a I wrong or should I use a plain select string ? > > tfyl > > kad > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-20 19:05 UTC
Re: find_by_sql with named parameterized sql
By the way, I reccomend doing this instead: @order = Order.find(:all, :conditions => ["amount > ? and quantity > ?", @amount, @quantity] Just in case you feel like making the orders table a legacy table called "15_t_orders" or whatever, you''re keeping your app DRY by using the rails finders instead of sql, and only having the data finding itself in the sql part. On Jan 20, 8:01 pm, "augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The latter isn''t working because you are inserting symbols directly in > the sql, and as far as I know this isn''t allowed. What''s wrong with > using the first alternative? > > On Jan 20, 3:39 pm, Kad Kerforn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > I tried to use named parameters in my SQL query , using find_by_sql > > > Order.find_by_sql ([select * from orders where amount > ? and quantity > > > ?", [ @amount, @quantity ] works;.. > > but > > Order.find_by_sql ([select * from orders where amount > :amount and > > quantity > :quantity ", [ :amount => @amt, :quantity => @qty ] is not > > working > > a I wrong or should I use a plain select string ? > > > tfyl > > > kad > > > -- > > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---