1

I would like to print into log or console the executing sql. Where can I make some settings? In hibernate it is in a config file possibility: I think here should be something like that too.

I have a code part similar to this:

myresult = MyActiveRecordClass.find(:all, :select => "mytable1.*, mytable2.field1", :joins => :mytable2, :conditions => "somefield= #{somefield}", :order => "another_field desc", :offset => offset, :limit => limit)

This is a simpler case to translate by hand, but I would like to have all the native sql in a console or in file. It could be usefully at searching

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
matheszabi
  • 11
  • 2

1 Answers1

1

Rails already displays the SQL in the development log and console (at debug log level - so ensure that the logger is able to display debug log messages).

To also display where in the source code a SQL was called from:

Rails 2: query_trace plugin

Rails 3: Tracing Rails 3 SQL queries (based on query_trace, but works for Rails 3 because query_trace does not currently work on Rails 3)

Community
  • 1
  • 1
Zabba
  • 64,285
  • 47
  • 179
  • 207