Saturday, January 31, 2009

DB2 on Rails

It's time to test running Rails with DB2 as the backend.

I downloaded the information from http://www.alphaworks.ibm.com/tech/db2onrails.

I am running on Linux, so I did:

  • export DB2DIR=/opt/IBM/db2/V9.1_01
  • export DB2LIB=/opt/IBM/db2/V9.1_01/lib32
then:

  • cd Source
  • rake
It failed with the following message:

checking for SQLConnect() in -ldb2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Looking at the mkmf.log, I see:

conftest.c:3: error: ‘SQLConnect’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)

  • It seems the environment variables were not set properly.
  • I ran it again and got the following message:
Database environment is not set up
Run ". /home/db2inst1/sqllib/db2profile" and retry


After sourcing the db2profile, I ran with the following messages:

Loaded suite tests
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 0.593455 seconds.

But I seems the shared library has been generated successfully.

  • cp ibm_db2.so /usr/local/lib/ruby/site_ruby/1.8/i686-linux/
Installing the Adapter

  • cp ibm_db2_adapter.rb /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/
  • vi /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record.rb

Well, after trying that without success, I found the following response in the forum:

Given that RAILS_CONNECTION_ADAPTERS went away, the IBM gem is no longer called "ibm_db2", and that the minimum software requirements have changed, I recommend skipping the "Toolkit for DB2 on Rails" and to start learning about the "ibm_db" gem here: http://rubyforge.org/projects/rubyibm/

N.B. The unwarranted license of DB2 Express-C is currently limited to using 2 processor cores & 2 GB of memory. However, it's still a better option than "Oracle XE".

Starting from scratch...

Monday, January 12, 2009

Ruby and DB2

The next step is my Ruby adventure is to use DB2 as the data source. This will allow to plug RoR to many applications that have DB2 as the backend.

* Some instructions on how to download the DB2 driver is described at: http://wiki.rubyonrails.org/rails/pages/IBM+DB2

* After that, let me try to scaffold a DB2-based application: Tivoli Process Automation Engine

* cd ~/Rails
* mkdir TPAE
* cd TPAE
* rails tpae
* cd tpae/config
* vi database.yml

development:
adapter: ibm_db
database: maxdb71
username: maximo
password: itsmswat
schema: maximo
host: ismdbserver.tivlab.raleigh.ibm.com
port: 50005


* rake db:migrate --trace
* It failed with the following message:
Failed to connect to the [maxdb71] due to:
* It seems the problem is related because I forgot to load the DB2 profile
* . ~db2inst1/sqllib/db2profile
* rake db:migrate --trace
* I got a different problem:
Failed to connect to the [maxdb71] due to: [IBM][CLI Driver] CLI0133E Option type out of range. SQLSTATE=HY092 SQLCODE=-99999
* export LIBPATH=/home/db2inst1/sqllib/lib
* It seems I need to read some instructions on http://www.alphaworks.ibm.com/tech/db2onrails. Another day.

Wednesday, January 7, 2009

Ruby plugin for Eclipse

I found a Ruby plugin for Eclipse at: http://update.aptana.com/update/rails/3.2/

I had first to install Eclipse Monkey, described at http://www.brain-bakery.com/projects/articles/eclipse-monkey-scripting/. Also I had to install the Aptana Studio from: http://www.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration

There are some instructions on how to use at: http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/

Saturday, January 3, 2009

My first experience with Ruby on Rails

It's a new year, so I decided to learn a new language / environment. I chose Ruby on Rails,so here comes my experience.

I am following the tutorial at: http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html, which has been written for Rails 1.2.6. My environment thou is Rails 2.0. So, here are the steps I followed:

  • cd ~/Rails
  • rails cookbook2
  • cd cookbook2
  • rake db:create:all
  • ./script/generate scaffold Category name:string
  • rake db:migrate
  • ./script/server
Then point your browser to http://localhost:30000. It shows the RoR welcome page.

  • Go to file config/routes.rb and file the following line:
ActionController::Routing::Routes.draw do |map|
map.root :controller=> 'categories'
map.resources :categories

Now point your browser to http://localhost:3000/categories, and you are ready to create categories!

Creating the recipe table

  • ./script/generate scaffold Recipe category:references title:string description:string instructions:text
  • rake db:migrate
Now point your browser to http://localhost:3000/recipes and you're ready to create recipes!