Show SQL request without issuing it

Hi all,

I saw that some object.save is causing the SQL request to crash, but I
don't see the SQL request in the logs (only ruby code that's showing an
error during the .save method).

Is there any way to show the SQL request before it's issued to the
database ?

If you are working in the console you can redirect the logger to
STDOUT (this is from Advanced Rails Recipes)

>> ActiveRecord::Base.logger = Logger.new(STDOUT)

=> #<Logger:0x236aa04 @default_formatter=#<Logger::Formatter:0x236a9c8
@datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:
0x236a98c @filename=nil, @mutex=#<Logger::LogDevice::LogDeviceMutex:
0x236a950 @mon_owner=nil, @mon_waiting_queue=[],
@mon_entering_queue=[], @mon_count=0>, @dev=#<IO:0x2f7d8>,
@shift_size=nil, @shift_age=nil>, @formatter=nil, @level=0>

>> ActiveRecord::Base.clear_active_connections!

=> {}

Best.
MIke

Just to clarify:

This will still issue the SQL statement but will display the SQL
statement that is executed in the console.

Best.
Mike

Mike Breen wrote:

Just to clarify:

This will still issue the SQL statement but will display the SQL
statement that is executed in the console.

Best.
Mike

Great thanks :slight_smile:

Well, sadly, the logs are showing all but the SQL requests who's
crashing :frowning:

I have been seeing this a bit too. Situations where a failure to
updated the database does not result in an error being logged. I also
think I have seen it in other circumstances too (although I suspect
these may be HAML related).

One circumstance whereby I did not receive a mysql error in the log
was after changing some code to access a model attribute, but where
that attribute had not been added to the table. But trying to
subsequently reproduce the situation has not been possible.

Tonypm

ps. As I recall, running the code in the console did result in
showing the error.

Tonypm