There are currently 3 Ruby/DB2 binding that appear to work.
One of them is the driver and adapter provided directly by IBM.
The adapter and driver name changed from ‘ibm_db2’ to ‘ibm_db’ to reflect its support for all IBM data servers. That has to be considered when registering in active_record.rb and also in the config/database.yml. Documentation is available in the rubyibm project, on RubyForge.
Starter Toolkit for DB2® on Rails is a conveniently-packaged set of products and technologies that enables the quick creation of a configuration for building DB2 Web applications using Ruby on Rails technology.
There are two packages available, a win32 all inclusive toolkit, or the source code only (less than 200KB).
The toolkit for Windows includes:
Note: The following update of the Starter Toolkit will contain the latest IBM_DB gem from RubyForge, but current version is 0.2.0 (compared to IBM_DB-0.7.0)
The source code package includes code for the driver and the adapter and it’s suitable for Windows®, Linux® and Unix®.
There are two type of connections available to suite your needs: through an Alias or through TCP/IP address. Typically the Alias based connection is used to connect to a local database (cataloged), while the net address one is used for remote databases. The local or remote DB2 server you are connecting to, must be running on a compatible operating system (currently Windows, Linux and Unix only, but in the future it will work on iSeries through DB2 Connect).
development:
adapter: ibm_db2
database: demo
username: db2admin
password: db2password
schema: cangiano
Database represents the alias DEMO. All the fields above are mandatory except for schema. If you don’t specify any schema, the adapter will use the username by default.
development: adapter: ibm_db2 database: demo username: db2admin password: db2password schema: cangiano host: myhostname port: 50000
‘host’ can be an hostname or an IP address. Again, schema is optional, and defaulted to the specified username.
Linux/Unix users will need to set the environment with the command: source /home/db2inst1/sqllib/db2profile (or equivalent on your machine). Please also note that you need to specify ‘ibm_db2’ and not ‘db2’ in order to use the IBM adapter. The IBM driver is an evolution of Sam Ruby’s port of the php ibm_db2 extension.
Information entered by Antonio Cangiano, feel free to email me (run require 'base64';puts Base64.decode64("Y2FuZ2lhbm9AY2EuaWJtLmNvbQ==\n") to get my email address)
The file you will want to download the most recent version of ruby-db2 (currently ruby-db2-0.4.4.tgz).
Follow the instructions in the README. If you are using DB2 V8.1 you will
need to set the DB2DIR environment variable, as it defaults to compile against
V7.1.
export DB2DIR=/opt/IBM/db2/V8.1 ruby setup.rb config ruby setup.rb setup sudo ruby setup.rb install
Once installed, you should be able to use DB2 with a configuration similar to
the following. One additional connection parameter is available for DB2,
:schema.
sample: adapter: db2 database: sample username: sample_user password: my_sample_user_password schema: sample
DB2 ships with full ODBC bindings and as such works very well with unixODBC.
Setup the odbcinst.ini and odbc.ini files correctly and ruby-odbc just works.
Unfortunately there does not seem to be a good ActiveRecord odbc driver for
rails quite yet. But once one does exist, this should be a valid option.
# odbcinst.ini [DB2] Description = DB2 Driver Driver = /home/db2inst1/sqllib/lib/libdb2.so FileUsage = 1 DontDLClose = 1
[sample] Description = sample Driver = DB2
The following note below no longer applies to the latest IBM_DB gem (adapter & driver) with regards to numeric values quoting and scaffolding. Some migration limitations are still documented (rename_column and remove_column on zOS) but work-around available.
these may be outdated statements and don’t apply to the IBM DB2 driver and adapter
DB2 effectively doesn’t work. There are too many things not yet supported for
even basic scaffolding to work. Has anyone ever built a website with Rails and
DB2? It seems to be there’s a long way to go before it will be at the level as
MySQL support is today. Is anyone working on this?
Please create tickets for the things you’re finding that “doesn’t work”.
Currently, I believe DB2 is passing just about all the unit tests. So if
there’s something that doesn’t work, we want to know about it. Do note,
though, that DB2 requires things like proper quoting based on the field types.
So you can’t do Person.find(“1”) and have it work like in MySQL, you need
Person.find(1). So all type-casting is yours to do—DavidHeinemeierHansson.