# Show SQL request without issuing it

**URL:** <https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493>\
**Category:** Rails\
**Created:** [July 8, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493 "2008-07-08T15:07:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/1 "2008-07-08T15:07:59Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 3:18pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/2 "2008-07-08T15:18:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 3:20pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/3 "2008-07-08T15:20:15Z")

</div>

Just to clarify:

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

Best.  
Mike

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 3:28pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/4 "2008-07-08T15:28:07Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/5 "2008-07-08T15:34:50Z")

</div>

Well, sadly, the logs are showing all but the SQL requests who’s  
crashing ☹

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 9, 2008, 10:32am UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/6 "2008-07-09T10:32:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 9, 2008, 10:37am UTC](https://www.ruby-forum.com/t/show-sql-request-without-issuing-it/142493/7 "2008-07-09T10:37:29Z")

</div>

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

Tonypm
