Beruflich Dokumente
Kultur Dokumente
Database Engine
Recipe A: Using Oracle as the Database Engine
So far in the book we have taken a database agnostic approach to the tutorials. One of
the most powerful features of Hobo and Rails using the ActiveRecord Object Relational
Mapping (ORM) capability is that you can usually ignore the backend issue and focus
on solving the business problem.
However, when you are in an environment where the database engine choice has been
made for you, or when you need to access legacy data as one part or your software
solution, you need to learn how to configure Hobo for other databases.
In this recipe we will provide instructions for these two options:
1.Use and existing Oracle database schema.
2.Download and install a fresh Oracle database and create a schema for use with
Hobo.
For either of these options you will first need to install the following two ruby gems:
C:\ruby> gem install rubyoci8 –v 1.0.3
C:\ruby> gem install activerecordoracleadapter
Option1
This is the typical scenario in a development shop that is already using Oracle and you
have the Oracle client software already configured for other tools such as SQL Plus,
Toad, or SQL Developer.
You probably have different database “instances” for development, test, and production
systems. If you are lucky you might even have rights to create a new database user
(i.e,, schema) in your development environment. In most large shops you will probably
need to request that the database administrator (DBA) create one for you.
(Note: the terms “user” and “schema” really are referring to the same thing and are
often used interchangeably by experienced Oracle developers. There is a long history to
this that will confuse users of other database engines where users and schemas are not
equivalent.)
As you learned in earlier tutorials, the database.yml file is the place to configure your
database connections. Creating a new application using the hobo command with the
“d” switch allows you to stipulate which database you will be using, and allows Hobo and
Rails to build a database.yml template tallored to your database.
C:\tutorials> hobo two_table –d oracle
This is what the database.yml file looks like without modification:
When we used SQLite as the default database, Hobo and Rails automatically created a
database called “two_table_development”. When you use an existing Oracle database,
you will need to enter that database name instead of “two_table_development” and use
“two_table_development” as the user name the username. Therefore the entries in the
database.yml file will look more like the following:
development:
adapter: oracle
Once you update the database.yml file and save it you can then run your hobo migration
and the complete tutorials as you before. This time they will run using Oracle as the
back end. That is all there is to it.
Option 2
In this part of the tutorial we will walk you through the steps of downloading, installing,
and configuring Oracle 10g XE (Express Edition), which is a fully functional version of
Oracle with no licensing requirements. It comes with administration tools, a web front
end. It’s only major limitation is that your application can only support a max of 5 GB of
data.
Register for a free membership in the Oracle Technology Network (OTN) and then go to
the following URL to download Oracle Database 10g Release 2 Express Edition for
Windows: