Saturday, October 2, 2010

Testing ActiceRecord-JDBC with DB2 on Mac OS X

(continued from phosphorescence: Install DB2 on Mac OS X)

I helped to testing ActiveRecord-JDBC with DB2 on my Macmini. But there are two big traps. In this article, I write about the second trap : Testing ActiceRecord-JDBC with DB2 on Mac OS X.

Clone sources and tests from repository

$ git clone

create database for test with CUI

Because of DB2 Express-C V9.5.2 beta for MAC OS X, there are no DB2 Control Center (GUI). So we must create database from DB2 command line processor (CLP).
$ db2 create database blog_dev on ~/weblog_development using codeset UTF-8 territory my_territory collate using SYSTEM
For instance, I set my territory as JP. Then check the conenction to blog_dev database.
$ db2 connect to blog_dev user instance_user_name using instance_user_password
$ db2 disconnect

Fix test file for DB2

The content of activerecord-jdbc-adapter/test/db/db2.rb from repository is below:
config = {
  :username => "blog",
  :password => "",
  :adapter => "jdbc",
  :driver => "",
  :url => "jdbc:db2:weblog_development"

But, there are 3 points to fix.
  1. Because DB2's database user is deeply integrated with OS user, Empty password is not recommended. We should use OS user and password.
  2. Because Database name longer than 8 characters is not allowed in DB2, we must use database name shorter than 8 characters.
  3. Because DB2 for Mac OS X has BUGGY driver for type-2 connection, we must use type-4 connection.
So I edit activerecord-jdbc-adapter/test/db/db2.rb like below:
config = {
  :username => "instance_user_name",
  :password => "instance_user_password",
  :adapter => "jdbc",
  :driver => "",
  :url => "jdbc:db2://localhost:50000/blog_dev"

As you see, I have set the database name as blog_dev in previous instructions, this is the reason.

prepare test

Of course, we must install active-record in JRuby from gem. And one more instruction is below:
$ cd activerecord-jdbc-adapter
$ jruby -S rake java_compile


For instance, test with active-record 2.3.9:
$ jruby -S rake test_db2 AR_VERSION=2.3.9
For instance, test with active-record 3.0.0:
$ jruby -S rake test_db2 AR_VERSION=3.0.0

No comments:

Post a Comment