Hi, I would like to know for each running model action, how can I retrieve the SQL running behind? I don''t want to scan log each time for the sql running behind. E.g. post.find(:all,:conditions=>{:id=>''1''} I wanna debug the sql generated behind, is that other shorthand function like post.find().show_sql() that enable us to view what''s SQL generated ? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 Reginald James
2009-Feb-14 10:59 UTC
Re: How can I retrieve the SQL during each model action?
xeon wrote:> Hi, > > I would like to know for each running model action, how can I retrieve > the SQL running behind? I don''t want to scan log each time for the sql > running behind. > E.g. post.find(:all,:conditions=>{:id=>''1''} > > I wanna debug the sql generated behind, is that other shorthand > function like post.find().show_sql() that enable > us to view what''s SQL generated ?That sounds like a good idea. Perhaps a :log => :instance_variable_name option to find. One alternative is the query_trace plugin that displays a backtrace for each query, so that the log shows what line of code is associated with each query. -- 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 -~----------~----~----~----~------~----~------~--~---
On Feb 13, 12:59 pm, xeon <xeo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I would like to know for each running model action, how can I retrieve > the SQL running behind? I don''t want to scan log each time for the sql > running behind. > E.g. post.find(:all,:conditions=>{:id=>''1''} > > I wanna debug the sql generated behind, is that other shorthand > function like post.find().show_sql() that enable > us to view what''s SQL generated ? > > ThanksIf you are using the console, you can type:>> set_logger_to Logger.new(STDOUT)An output example:>> Page.find(:all, :conditions=>{:id=>1})SQL (0.000093) SET SQL_AUTO_IS_NULL=0 Page Load (0.000112) SELECT * FROM `pages` WHERE (`pages`.`id` 1) Page Columns (0.001215) SHOW FIELDS FROM `pages` => [#<Page id: 1, .... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the valuable reply. But I found myself most comfortable with: 1) Netbeans debugging 2) ruby-debug (http://railscasts.com/episodes/54-debugging-with-ruby- debug) 3) rdebug with textmate That''s sum out my findings. Hope it helps. But, personally speaking, it will glad to have a shorthand function for developer to dump out the sql generated on the fly, as it effectively save time for browsing the log, run the debugger in console...cheers! On Feb 16, 8:54 pm, Xuan <xua...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 13, 12:59 pm, xeon <xeo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I would like to know for each running model action, how can I retrieve > > the SQL running behind? I don''t want to scan log each time for the sql > > running behind. > > E.g. post.find(:all,:conditions=>{:id=>''1''} > > > I wanna debug the sql generated behind, is that other shorthand > > function like post.find().show_sql() that enable > > us to view what''s SQL generated ? > > > Thanks > > If you are using the console, you can type: > > >> set_logger_to Logger.new(STDOUT) > > An output example:>> Page.find(:all, :conditions=>{:id=>1}) > > SQL (0.000093) SET SQL_AUTO_IS_NULL=0 > Page Load (0.000112) SELECT * FROM `pages` WHERE (`pages`.`id` > 1) > Page Columns (0.001215) SHOW FIELDS FROM `pages` > => [#<Page id: 1, ....--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---