19 October 2011
To use the Ruby OCI8 Oracle bindings, you need to have at least an Oracle client installed. As I needed an Oracle database on my system, I just did a full database install. Everything worked fine Oracle and Sqlplus wise, so I forged ahead and installed the ruby-oci8 gem:
gem install ruby-oci8
This completed without any errors. However, when I attempted to run it, I got the error:
C:\Users\sodonnel> ruby -r oci8 -e "OCI8.new('scott', 'tiger', 'local11gr2').exec('select * from emp') do |r| puts r.join(','); end" C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': OCI.DLL: 193(%1 is not a valid Win32 application. ) (LoadError) from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.6-x86-mingw32/lib/oci8.rb:38:in `<top (required)>' from <internal:lib/rubygems/custom_require>:33:in `require' from <internal:lib/rubygems/custom_require>:33:in `rescue in require' from <internal:lib/rubygems/custom_require>:29:in `require'
The problem here is that the ruby gem is a pre build binary for 32 bit Windows - it does not attempted to compile against the Oracle libraries (as that would require too many Windows build tools). When it attempts to load the OCI.DLL from the Oracle libraries, it finds a 64 bit library, and the 32 bit build will not work with it.
The solution is to somehow get a working 32 bit OCI.DLL. The easiest way to do this, is to install the Oracle Instant Client along side your Oracle install. Download both instantclient-basic-nt-18.104.22.168.0.zip and instantclient-sdk-nt-22.214.171.124.0.zip from (http://www.oracle.com/technetwork/topics/winsoft-085727.html). Then extract them both into a folder, and add that folder to your path. I put them into:
Then the OCI8 gem should work correctly.