Ruby application for sql statements

Hello everybody,

I am currently working on a database system that utilizes ruby on
rails
with a oracle database. Here’s the situation:
the ruby on rails web application is up and running (scaffolds have
been generated);
my oracle database is full of tables that are populated with data;
there is a successful connection between rails and my oracle database;
however, what still needs to be done is I currently have sql
statements/queries in which I am using to mine data from my database
(eg. “find minimum time someone has been employed”
Select min(time) from table…etc)

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.
I need the ruby code to:

  1. connect to the oracle database
  2. run the sql statement on the oracle database
  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)

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

StudxXxent wrote:

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.
I need the ruby code to:

  1. connect to the oracle database
  2. run the sql statement on the oracle database
  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)

You need to learn about ActiveRecord. This is too large a subject for a
quick answer on a forum.

Start with Rails tutorials. Take the time to understand how they are
using ActiveRecord, how the models relate to database tables and how the
#find method works for extracting data, including uses of #has_many,
#belongs_to and #has_one for linking models and use of :includes in the
#find method for doing implicit joins on tables.

Search for information about ActiveRecord to take you further. It
sounds like you are trying to fit Rails to an existing database schema,
so google for “rails activerecord legacy schema” and you should get a
few sites with advice on ways to access existing schemas from rails.

The ActiveRecord reference is available starting here:
http://api.rubyonrails.com/classes/ActiveRecord/Base.html
however this is a reference and probably will only be useful as such
alongside tutorials and other material.

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