Table of Contents
Installing the Ruby ODBC Module
Ruby modules come as both modules and Gems. The ODBC Adapter for ActiveRecord requires Christian Werner's ODBC module.
Locomotive on Mac OS X
Prebuilt binaries
If you do not wish to build from source, or do not have Xcode installed, we have provided a few binaries of the ODBC module, odbc.bundle, which you can copy into the appropriate location (e.g. /Applications/Locomotive2/Bundles/rails112.locobundle/i386/lib/ruby/site_ruby/1.8/i686-darwin8.6.1/), attached below.
Building from source: preliminary note
You need to ensure that the correct version of ruby is in your PATH. If you run `ruby extconf.rb' (below) in an ordinary Terminal window, the chances are your system-wide installation will be picked-up, from /usr/bin/ruby. If you're using Locomotive, we recommend using its Terminal (either Application/Open Terminal, or shortcut Apple+T), which sets PATH correctly. Then proceed using that terminal window as follows:
All platforms
Download the tarball and unpack. You'll end up with a directory like:
zsh, pizza 10:14AM ruby-odbc-0.9995/ % ls COPYING MANIFEST doc/ odbc.c utf8/ ChangeLog README extconf.rb test/ GPL cqgen.rb init.c test.rb
Here you run the extconf.rb script:
zsh, pizza 10:14AM ruby-odbc-0.9995/ % ruby extconf.rb \
--with-iodbc=/usr/local/iODBC
checking for sql.h... yes
checking for sqlext.h... yes
checking for SQLTCHAR in sqltypes.h... yes
checking for SQLLEN in sqltypes.h... yes
checking for SQLULEN in sqltypes.h... yes
checking for odbcinst.h... no
checking for SQLAllocConnect() in -lodbc... no
checking for SQLAllocConnect() in -liodbc... yes
creating Makefile
zsh, pizza 10:44AM ruby-odbc-0.9995/ %
It's wise to check the resultant Makefile. For example, it should probably have calls to iodbc-config on the CFLAGS and LDFLAGS lines:
CFLAGS = -fno-common -g -Os -pipe -fno-common -pipe -fno-common -pipe \ -fno-common `iodbc-config --cflags` ... LDSHARED = cc $(RC_CFLAGS) -bundle `iodbc-config --libs`
Then it's just a normal make + make install to complete installation:
zsh, pizza 10:44AM ruby-odbc-0.9995/ % make /usr/bin/gcc-4.0 -I. -I. -... cc -dynamic -bundle -undefined suppress -flat_namespace \ `iodbc-config --libs` -o odbc.bundle init.o odbc.o -L"." \ -L"/opt/local/lib" -L. -L/opt/local/lib -lruby -liodbc -lpthread \ -ldl -lobjc zsh, pizza 10:45AM ruby-odbc-0.9995/ % sudo make install Password: /usr/bin/install -m 0755 odbc.bundle /opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.11.0
Testing
To test it, run
zsh% ruby -e 'require "odbc"'
If it doesn't do anything, it's loaded correctly.