So far if you wanted to use Ruby on Rails on Oracle database you needed to use different adapters depending on the Ruby platform that you wanted to use. If you used original MRI (Matz Ruby interpreter) 1.8.6 then hopefully you were using Oracle enhanced adapter. But if you wanted to use JRuby then you needed to use JDBC adapter that is maintained by JRuby team (and which sometimes might work differently than Oracle enhanced adapter). And if you wanted to use new Ruby 1.9.1 then you were out of luck as no adapter supported it.
Therefore I wanted to announce great news that ActiveRecord Oracle enhanced adapter 1.2.0 is released and it supports all three major Ruby platforms!
- Use Oracle enhanced adapter on MRI 1.8.6 with ruby-oci8 1.0.x library or gem
- Use Oracle enhanced adapter on JRuby (so far tested with 1.1.6) with JDBC Oracle driver
- Use Oracle enhanced adapter on Ruby/YARV 1.9.1 with ruby-oci8 2.0 library or gem
This provides you with much more flexibility to develop on one Ruby platform but deploy on another and on all three platforms you can use the same additional functionality that Oracle enhanced adapter provides on top of standard ActiveRecord functionality.
And during testing of Oracle enhanced adapter on all platforms additional milestone was achieved – Oracle enhanced adapter passes 100% ActiveRecord unit tests! But to be honest I need to tell that I needed to patch quite many unit tests for Oracle specifics as not all SQL that runs on MySQL is also valid on Oracle. I published my patched branch of ActiveRecord unit tests at my GitHub fork of Rails – you can clone the repository and verify by yourself.
So please try out new version of Oracle enhanced adapter on any Ruby platform:
gem install activerecord-oracle_enahnced-adapter
If you have any questions please use discussion group or post comments here. In nearest future I will also add more instructions how to install Oracle enhanced adapter on JRuby and Ruby 1.9.1 at GitHub wiki page.

Thanks for your hard work, Raimonds! Will try this now. You should mention that the new version is compatible with Rails 2.3.
Comment by Roob — March 23, 2009 @ 11:59 am |
Good article, I work with oracle and PHP but now I’m studing ruby on rails, I would like help people here in Brasil to migrate to oracle!!!
Comment by Targino Silveira — March 26, 2009 @ 3:10 am |
Amazing news indeed. Getting closer to convincing on Rails migration in some corporations I know…
Thanks!
Rollo
Comment by Rollo Tomazzi — March 28, 2009 @ 8:24 pm |
A ruby newbie here – I am making use of activerecord for my command line tools (not a webapp). Unfortunately I have to deal with a legacy database in Oracle. So far I have been successful, but there are a ton of stored procs that are available and I can make use of. Can you show a sample of your adapter in a stand along program where I can leverage the plsql packages and sprocs. Btw I am using JRuby so I can fall back to CallableStatement when needed.
Thanks.
Comment by kris — April 7, 2009 @ 11:05 pm |
You can use ruby-plsql gem for that – see http://github.com/rsim/ruby-plsql/tree/master
It supports JRuby as well.
Basic example would be the following (before that install activerecord-oracle_enhanced-adapter and ruby-plsql gems):
require “rubygems”
require “activerecord”
require “ruby_plsql”
ActiveRecord::Base.establish_connection(
:adapter=>”oracle_enhanced”,
:host=>”database_host_name”,
:port=>1521,
:username=>”username”,
:password=>”password”)
plsql.connection = ActiveRecord::Base.connection.raw_connection
plsql.some_package.some_function(:parameter1 => “value1″)
Comment by Raimonds Simanovskis — April 8, 2009 @ 7:39 pm |
Gr8 news. I am planning to migrate legacy db & I am going to give a try with 1.9
Comment by sudhakar — May 1, 2009 @ 1:48 pm |
Thanks for your work on this! I’m looking forward to giving it a try, to see if it takes care of the problem I’ve been having with saving dates to oracle (see http://tek-zappeln.blogspot.com/2009/05/saving-dates-to-oracle-with-jruby-rails.html).
Comment by Mike Dietz — May 1, 2009 @ 8:52 pm |
In Oracle enhanced adapter you can use set_date_columns in class definition to specify which columns should store just date without time – this should solve your problem.
Comment by Raimonds Simanovskis — May 2, 2009 @ 8:49 pm |
I can’t get it working on glassfish v3 + netbeans 6.5.1, Ive been trying to work this out for 3 days, don’t have a clue: the library is in every possible location.
SEVERE: ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install ojdbc14.jar library.
SEVERE:
SEVERE: Exception in thread “pool-11-thread-1″
SEVERE: C:/Program Files (x86)/NetBeans 6.5.1/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:232:in `establish_connection’:
Comment by Eduardo — May 27, 2009 @ 10:26 pm |
I had a similar issue when i tried my war file on WINDOWS
The problem seems that ENV["PATH"] is nil for windows and the value is found in ENV["Path"]. So at the top of environment.rb I added …
ENV["PATH"] ||= ENV["Path"]
Comment by Marcus Baguley — July 27, 2009 @ 4:18 am |
Adapter tries to find and load ojdbc.jar file in the following way (see file oracle_enhanced_jdbc_connection.rb in gem directory):
require “java”
require “jruby”
java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
ojdbc_jar = “ojdbc14.jar”
if ojdbc_jar_path = ENV["PATH"].split(/[:;]/).find{|d| File.exists (File.join(d,ojdbc_jar))}
require File.join(ojdbc_jar_path,ojdbc_jar)
end
java.sql.DriverManager.registerDriver Java::oracle.jdbc.driver.OracleDriver.new
Try these command in JRuby irb and try to identify when and why this load exception is raised.
Comment by Raimonds Simanovskis — May 28, 2009 @ 10:53 pm |
Just wanted to tell you all know how much I appreciate your postings guys.
Found you though google!
Comment by bloonsterific — July 10, 2009 @ 2:36 pm |
How can I get ROWID with this adapter?
with OCI, I knew that I get Oracle ROWID.
but How can I do that with enhanced_adapter?
( Actually I want to get ROWID and to update with that ROWID )
plz give me a clue!!
Thanks.
Comment by rainblue — September 21, 2009 @ 10:01 am |
You can specify list of columns you want to select using :select option for find method.
But I would not recommend to use ROWID for updates when using ActiveRecord – the main idea of ActiveRecord is that always you have designated primary key column and the main benefit of ActiveRecord is that you do not need to write standard SQL statements. If ActiveRecord is not suiting your needs then probably you shouldn’t use it and stick with ruby-oci8 to write plain SQL statements.
Comment by Raimonds Simanovskis — September 21, 2009 @ 2:42 pm |
As far as I can tell, the activerecord-oracle-adapter is still using oci8 1.x API; when run against oci8 2.x, it breaks with an error about the undefined method ‘define_a_column’ in OCI8::Cursor. But ruby-oci8 1.x doesn’t support Ruby 1.9. So how did you get the adapter to work with Ruby 1.9.1?
Comment by Mark J. Reed — October 5, 2009 @ 11:16 pm |
(Forgot to check the “notify” box)
Comment by Mark J. Reed — October 5, 2009 @ 11:17 pm |
This post is about activerecord-oracle_enhanced-adapter and not activerecord-oracle-adapter. Original activerecord-oracle-adapter is not anymore maintained and should not be used.
Comment by Raimonds Simanovskis — October 6, 2009 @ 9:03 am |
Hi,
I’m trying to get this working with JRuby, and no luck. The error that I get is:
java.sql.SQLException: Io exception: could not resolve the connect identifier “xxx”
Where “xxx” is the value in my :database value. I put the ojdbc14.jar in the jruby/lib dir and pretty sure I have all of the needed gems. The same example code does work in MRI though, using the oci gem. So I know my oracle tnsnames is setup right.
Any ideas?
Thanks for your awesome work!
Comment by Matt Mitchell — January 14, 2010 @ 6:59 pm |
If xxx is TNS alias defined in tnsnames.ora file then in JRuby you need to set ENV['TNS_ADMIN'] as directory where tnsnames.ora is located (you can also set TNS_ADMIN as environment variable before starting JRuby).
Otherwise you need to set :host and :port connection options to specify database host name and listener port and then :database should be database name on that host.
Comment by Raimonds Simanovskis — January 17, 2010 @ 11:51 pm |