Chris Scharf
2006-Apr-20 13:50 UTC
[Rails] How to find the last SQL statement executed in ActiveRecord
Is there a method for retrieving the last SQL statement executed by ActiveRecord? I realize I can open the log file, but I''m looking for a programmatic way. -- Posted via http://www.ruby-forum.com/.
Emin Hasanov
2006-Apr-20 14:22 UTC
[Rails] How to find the last SQL statement executed in ActiveRecord
you can always save that for your reference, but why do you need it? there may be a better solution for the problem On 4/20/06, Chris Scharf <scharfie@gmail.com> wrote:> > Is there a method for retrieving the last SQL statement executed by > ActiveRecord? I realize I can open the log file, but I''m looking for a > programmatic way. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060420/eebe5839/attachment.html
Chris Scharf
2006-Apr-20 14:29 UTC
[Rails] Re: How to find the last SQL statement executed in ActiveRec
Emin Hasanov wrote:> you can always save that for your reference, but why do you need it? > there > may be a better solution for the problemI''m building a new ActiveRecord ''Acts'' module, and when running the unit tests, I''d like to output the queries that are being build to ensure that the options I provide are working. -- Posted via http://www.ruby-forum.com/.
Leon Leslie
2006-Apr-20 14:41 UTC
[Rails] Re: How to find the last SQL statement executed in ActiveRec
ActiveRecord::Base.logger = Logger.new(STDERR) ActiveRecord::Base.colorize_logging = false On 4/20/06, Chris Scharf <scharfie@gmail.com> wrote:> Emin Hasanov wrote: > > you can always save that for your reference, but why do you need it? > > there > > may be a better solution for the problem > > I''m building a new ActiveRecord ''Acts'' module, and when running the unit > tests, I''d like to output the queries that are being build to ensure > that the options I provide are working. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Never be afraid to try something new. Remember, amateurs built the ark; professionals built the Titanic!
Jean-François
2006-Apr-20 14:48 UTC
[Rails] Re: How to find the last SQL statement executed in ActiveRec
Hello Chris,> Emin Hasanov wrote: > > you can always save that for your reference, but why do you need it? > > there > > may be a better solution for the problem > > I''m building a new ActiveRecord ''Acts'' module, and when running the unit > tests, I''d like to output the queries that are being build to ensure > that the options I provide are working.Maybe you can have a look at Zach Dennis'' plugin : "Here is a link to 0.0.1 of the ActiveRecord IO Mode plugin: http://www.mktec.com/oss/rails-plugins/active_record_io_mode.0.0.1.tgz It is more documentation then code, and only 201 lines. It works successfully with the MysqlAdapter. I believe it should work for Postgres, but I''m not a Postgres user so any feedback would be great. Any Oracle, MSSQL, SQLite, etc... users please let me know if this works or not for you." -- Jean-Fran?ois. -- ? la renverse.
Chris Scharf
2006-Apr-20 15:27 UTC
[Rails] Re: Re: How to find the last SQL statement executed in Activ
Jean-Fran?ois wrote:> Hello Chris, > >> Emin Hasanov wrote: >> > you can always save that for your reference, but why do you need it? >> > there >> > may be a better solution for the problem >> >> I''m building a new ActiveRecord ''Acts'' module, and when running the unit >> tests, I''d like to output the queries that are being build to ensure >> that the options I provide are working. > > Maybe you can have a look at Zach Dennis'' plugin : > > "Here is a link to 0.0.1 of the ActiveRecord IO Mode plugin: > http://www.mktec.com/oss/rails-plugins/active_record_io_mode.0.0.1.tgz > > It is more documentation then code, and only 201 lines. It works > successfully with the MysqlAdapter. I believe it should work for > Postgres, but I''m not a Postgres user so any feedback would be great. > Any Oracle, MSSQL, SQLite, etc... users please let me know if this works > or not for you." > > -- Jean-Fran?ois.Surely there is something in ActiveRecord itself to get this for me. What I want is to be able to say something like: ActiveRecord::Base.connection.last_sql Again, I know I can use the logger, but I don''t want EVERY query - just the most recent one that AR "built" based on a find(...) or whatever. -- Posted via http://www.ruby-forum.com/.