Hello, I am having problems with the find_by_sql while trying to update a table. I am using mysql and rails 2.2.2. A small test like this: User.find_by_sql "update users set name=''Test''" generates a horrible error. I might also add that I have config.gem "mysql" in my environment.rb and that I have tested the update query with sqlite and it works. Any ideas? Thanks, Elías You have a nil object when you didn''t expect it! The error occurred while evaluating nil.all_hashes /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/connection_adapters/mysql_adapter.rb:564:in `select'' /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'' /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'' /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'' /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'' /home/elioncho/.gem/ruby/1.8/gems/activerecord-2.2.2/lib/ active_record/base.rb:635:in `find_by_sql'' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sounds like you should be using "execute" instead of "find_by" since you aren''t trying to find anything. -- 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 -~----------~----~----~----~------~----~------~--~---
Aldo Sarmiento, Thanks for your reply, but the why does the update query inside the find_by_sql using sqlite works? Kind regards, Elías On Jan 23, 5:53 pm, Aldo Sarmiento <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> sounds like you should be using "execute" instead of "find_by" since you > aren''t trying to find anything. > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry typo error. Here it is again: Aldo Sarmiento, Thanks for your reply, but then why does the update query inside the find_by_sql using sqlite works? Kind regards, Elías --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Should I use the execute method then? On Jan 23, 6:17 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sorry typo error. Here it is again: > > Aldo Sarmiento, > > Thanks for your reply, but then why does the update query inside the > find_by_sql using sqlite works? > > Kind regards, > > Elías--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
elioncho wrote:> User.find_by_sql "update users set name=''Test''"Use User.update_all [''name = ?'', ''Test''] or User.update "update users set name=''Test''" -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---