(eg. "find minimum time someone has been employed"
Employee.minimum("time")
Employee.maximum("time")
More detail :
http://teapoci.blogspot.com/2008/02/active-record-session-1.html
http://teapoci.blogspot.com/2008/04/ebook-pro-active-record-database-with.html
What I need to do is write a ruby application (one for each sql
statement), where the sql statement is hardcoded into the ruby code.
Employe.find_by_sql("put your sql statement here")
I need the ruby code to:
1) connect to the oracle database
[*] Download ruby-oci8-1.0.1-mswin32.rb here:
http://rubyforge.org/frs/?group_id=256&release_id=21562
[*] After that run it D:>ruby\project_name\ruby
ruby-oci8-1.0.1-mswin32.rb
[*] Then go to {#RAILS_ROOT}/config/database.yml
development:
adapter: oci
host: <host>:<port>/<sid>
username: <user>
password: <password>
If not work, you can make connection testing, create a file is named
testing_oci.rb, then put it and save it after that run it :
#example you have table teapocis
require 'oci8'
connection = OCI8.new('<user>', '<password>', '//<host>:<port>/<sid>')
connection.exec("select * from teapocis") do |row|
puts 'dummy: ' + row[0] # output will be "dummy: data_value"
end
connection.logoff
2) run the sql statement on the oracle database
Store procedure and Transaction Support for Oracle is so friendly in
Ruby. Example Store Procedure :
ActiveRecord::Base.connection.execute('BEGIN do_the_calculation; END;')
3) take the results and return them in an array or
something of that nature (so that they can be used in an html file for
output on the web application)
@variable_name = Employee.find(:all)
This command is the same like
SELECT * FROM employee
The @variable (read : instance variable of variable_name) saved query of
"SELECT * FROM employee", in your html.erb or rhtml just do it.:
<% for posting in @variable_name %>
<p><%= posting.name %> | <%= posting.time %> | <%= posting.salary %></p>
<% end %>
If someone could give me a skeleton of how this should look in ruby or
give me example code I would forever be in your debt.
Thanks
You're welcome
Reinhart
http://teapoci.blogspot.com
My Advice " You should read book :
- PRO ACTIVE RECORD
- BEGINNING RAILS FROM NOVICE TO PROFESIONAL, or book
- AGILE WEB DEVELOPMENT IN RAILS "