Verse Of The Day

Tuesday, May 29, 2007

Hooking Up Ruby To Oracle

Well, I have to admit this one stumped me for a few days. Actually it stumped me one day, and I got pulled to work on actuall work stuff, and just got back to it a few days later.

I started by following the examples at
to get the Ruby Oracle libraries installed. That part was easy, download the OCI8 Ruby package at and run it.

Then I whipped up a script to test the connection from an example I found online (forget the URL to reference -- sorry if I stole your crap, dude!) That script basically looks like this (with usernames and passwords changed to protect the innocent.


require 'oci8'"user", "password", "oracle_sid").exec("select * from rep") do
|r| puts r.join(", ");

I was pumped! That seems easy, and then I can get out of the MySQL realm and start hooking up Rails to existing enterprise DB's and really show this stuff to be useful in our environment. Sorry MySQL fanatics, we are (mostly) an Oracle shop -- I have nothing against MySQL for my personal projects.

Anyways, she didn't work out so well. I figured it would work since I have Oracle installed on my PC, but got the following popup when I ran that script.

There was also a Ruby stack trace on the command line. Basically I did some Google'ing and found this posting ( which at least gave me the clue I needed to look for OCI.dll on my system. My thought was it was getting confused between the Oracle 8 and Oracle 9 versions loaded on my machine.

Searching and searching, I don't have OCI.dll on my machine. Back to Google (a developer's best friend IMO, it always confuses me when other developers don't try this first when they get stumped) That's when I came across this page ( that let me download OCI.dll. Dropped that in C:\WINNT\system32 (I'm on Windows 2000 at work, might be WINDOWS instead of WINNT for you), and re-ran the above test-conn.rb script.

Ruby on Rails on Oracle, here I come (again)

I'm guessing my next big hurdle (or potentially a roadblock instead of a hurdle) will be the lack of support for complex primary keys. Starting an application from scratch, you can design your database with that limitation in mind, but building applications for existing databases becomes another issue. I'm sure someone smarter than me has already addressed these concerns, so it might just be a matter of more Google searches.

No comments: