# How to generate sql eports

**URL:** <https://www.ruby-forum.com/t/how-to-generate-sql-eports/178668>\
**Category:** Deployment\
**Created:** [November 9, 2009, 9:04am UTC](https://www.ruby-forum.com/t/how-to-generate-sql-eports/178668 "2009-11-09T09:04:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgatri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mgatri](https://www.ruby-forum.com/u/mgatri)\
**Post date:** [November 9, 2009, 9:04am UTC](https://www.ruby-forum.com/t/how-to-generate-sql-eports/178668/1 "2009-11-09T09:04:38Z")

</div>

Dear all,  
Iâ€™m developing an application dedicated to generate statistical reports,  
I would like that user after saving their stat report they save sql  
queries too. To do that I wrote the following module:

module SqlHunter  
class ActiveRecord::ConnectionAdapters::AbstractAdapter

```
    @@queries = []
    cattr_accessor :queries
    def log_info_with_trace(sql, name, runtime)
     return unless @logger && @logger.debug?
    @@queries << sql
    end
    alias_method_chain :log_info, :trace
end

```

end

in the controller I wrote that

sqlfile =  
File.open(“public/advancedStats/#{@dir\_name}/advancedStatQuery.sql”,  
‘w’)  
@queries = ActiveRecord::ConnectionAdapters::AbstractAdapter::queries  
for query in @queries do  
sqlfile.write("#{query} \n")  
end  
sqlfile.close

I also modified Rails environment by adding this line:

ActiveRecord::Base.logger.level = Logger::DEBUG

This program is working and I can get queries but, all queries. In  
contrast I need only the specific queries done by one user to generate a  
stat report.

Is someone has any idea,  
Thanks,

mgatri
