# Get most recent SQL executed from inside script\\console?

**URL:** <https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861>\
**Category:** Rails\
**Created:** [November 21, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861 "2006-11-21T19:39:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 21, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/1 "2006-11-21T19:39:09Z")

</div>

I’m on edge rails, WinXP…

When I do something like:

> > Product.find(:all)

I can open my development log file and find the SQL statements that were  
executed behind the scenes.

But I’m lazy and hate switching between my console session and the log  
file session.

Is there any way to interactive ask ActiveRecord what the most  
reecently-run SQL statement was, so I can stay inside my script\console  
window?

Thanks  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 22, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/2 "2006-11-22T20:03:34Z")

</div>

One trick I like to do is tail the log in the background, then launch  
console.

$ tail -f log/development.log &  
$ ./script/console

So the log’s contents will still show up on stdout along with  
whatever you’re doing in the console:

> > User.find(:first)  
> > User Load (0.000485) SELECT \* FROM users LIMIT 1  
> > =\> #User:0x23dcf2c...

–  
Jeffrey H. (packagethief)

> **[unspace.ca](http://unspace.ca)**
>
> This domain may be for sale!

[http://beginningrails.com](http://beginningrails.com)  
[http://quotedprintable.com](http://quotedprintable.com)

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 22, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/3 "2006-11-22T20:29:26Z")

</div>

Jeffrey H. wrote:

> One trick I like to do is tail the log in the background, then launch  
> console.
> 
> $ tail -f log/development.log &  
> $ ./script/console

Except I’m on Windows.

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 22, 2006, 9:13pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/4 "2006-11-22T21:13:22Z")

</div>

Jeff C. wrote:

> Except I’m on Windows.

I’m sorry. 😉

Have you tried using cygwin? With cygwin, you can have a bash shell on  
your windows box and a slew of other excellent commands (like grep and  
tail), too.

[http://www.cygwin.com/](http://www.cygwin.com/)

-DJCP

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 22, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/5 "2006-11-22T21:26:10Z")

</div>

Daniel Collis-puro wrote:

> Jeff C. wrote:
> 
> > Except I’m on Windows.
> 
> I’m sorry. 😉

Ha! 🙂 Yes, many people have had similar sympathies 🙂

> Have you tried using cygwin? With cygwin, you can have a bash shell on  
> your windows box and a slew of other excellent commands (like grep and  
> tail), too.

True, but I strive for Windows-only solutions as much as I can.

Thanks anyway

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [November 22, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/get-most-recent-sql-executed-from-inside-script-console/76861/6 "2006-11-22T21:47:29Z")

</div>

Jeff wrote:

> True, but I strive for Windows-only solutions as much as I can.

Admirable. But the DOS shell _sucks_. Think of cygwin as augmenting the  
capabilities of windows rather than replacing them. You can access your  
entire windows filesystem through cygwin - I’m not suggesting that you  
run rails in cygwin.

Otherwise, I’d google for “tail for windows” and use that to tail your  
development log. Hacking ActiveRecord to output log information to two  
places (it’s already putting it in development.log) seems. . .  
inelegant.

-DJCP
