SQL Execute

Hi,

I would like to execute a SQL statement and manipulate its
resultset…
My SQL wont return data that fits on any model, I just would like to
do something like this:

sql = <<-ENDS
SELECT
sum(a) AS F1,
min(b) AS F2
FROM
MyTable
ENDS

resultSet = ActiveRecord::Base.connection.execute(sql)
resultSet.each do |row|
logger.info "Field1: " + resultSet[‘F1’]
logger.info "Field2: " + resultSet[‘F2’]
end

I made this example up to show my idea, my real case is more
complicated, but I think I passed the idea here.

Thanks in advance
Acras


Ricardo A.
[email protected]
Acras Desenvolvimento de Sistemas
+55+41-3232-6404
www.acras.net

Use the select_all method. It returns an array of hashes in the way you
would expect.

Fred

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