Get most recent SQL executed from inside script\console?

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

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)


http://beginningrails.com
http://quotedprintable.com

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.

Jeff C. wrote:

Except I’m on Windows.

I’m sorry. :wink:

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/

-DJCP

Daniel Collis-puro wrote:

Jeff C. wrote:

Except I’m on Windows.

I’m sorry. :wink:

Ha! :slight_smile: Yes, many people have had similar sympathies :slight_smile:

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
softiesonrails.com

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs