Author Archive

DB2 and Ruby on Rails, Part 1

Developerworks has published the first part of a long and detailed article about DB2 on Rails programming. In this article the basics of how to get started, migrations and an introduction to working with XML are covered. In the follow up article, XML will be covered in detail with informative step-by-step instructions on how to use DB2 pureXML™ in Rails. I’m sure you will find them to be extemely useful and informative.

Please visit and rate the first part of the article here.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

May 28 2007 | Announcements and How-to | Comments Off

IBM_DB2 or IBM_DB?

If you haven’t followed the IBM releases of DB2 on Rails very closely, you may be puzzled to find a Rubyforge project alongside the Alphaworks project. I’d like to shortly clarify what’s going on. The Stater Toolkit for DB2 on Rails is an easy, batteries included, one-click installer for Microsoft Windows and was last updated quite some time ago, when our driver and adapter were called IBM_DB2.

IBM’s vision of extending the driver and adapter not only to DB2 for LUW (Linux/Unix/Windows), but also for the other IBM databases, was clearly highlighted by the renaming of the DB2 enablement from IBM_DB2 to IBM_DB.

The new driver and adapter have been released in the Open Source on Rubyforge and they will be continuously improved and supported by IBM. Bugs, suggestions and questions should be posted directly on the homepage of the project at Rubyforge. This release allows users to install a gem or, if they prefer, to get a plugin on an individual project basis. So what will happen to the Alphaworks project?

An updated toolkit will be published very soon, and as you may expect it will automatically install the ibm_db gem along with Ruby, Rails, DB2 9 Fix Pack 2 and more. Windows users who already have several components installed, and users of other operating systems, can directly setup a DB2 development environment through the gem or the plugin, without requiring the toolkit. Others who prefer the comfort of a one click installer, will still find the starter toolkit to be an excellent solution to get everything setup including DB2 itself. If you are still uncertain about something, please feel free to use the comments to ask further questions.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

May 10 2007 | Tips&Tricks | 4 Comments »

Scaffolding XML columns as text area boxes

The Rails adapter and the Ruby driver for IBM DB2 enable you to take full advantage of the exclusive pureXML capabilities. XML fields are properly handled and also recognized when using migrations. We do not bind the content of XML columns to a specific XML Ruby representation (e.g. REXML) but rather let the user decide what they’d prefer to use, in light also of the fact that mapping to a simple string is often all that is required given the fast XQuery/XPath querying features provided out of the box by DB2.

The scaffolding generator ignores XML fields though. This is due to the fact that the bult-in scaffolding generates form elements for only a few datatypes. For example :time and :binary are excluded, and foreign keys are not handled as well. Users will typically want to handle XML fields in a customized way, for instance, showing only certain elements of the XML document in their forms. However if you wish to enable by default the automatic generation of text area boxes when using scaffolding, you can edit C:\ruby\lib\ruby\gems\1.8\gems\actionpack-1.12.5\lib\action_view\helpers\active _record_helper.rb (or the equivalent on your system) by replacing the to_tag method with the following:

def to_tag(options = {})
  case column_type
    when :string
       field_type = @method_name.include?("password") ? "password" : "text"
       to_input_field_tag(field_type, options)
    when :text, :xml
       to_text_area_tag(options)
    when :integer, :float
       to_input_field_tag("text", options)
    when :date
       to_date_select_tag(options)
    when :datetime, :timestamp
       to_datetime_select_tag(options)
    when :boolean
       to_boolean_select_tag(options)
   end
end

As you can see, all we are doing here is adding the XML datatype to the list of cases which require the rendering of a text area box.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

January 06 2007 | How-to and Tips&Tricks | 1 Comment »

Speeding up the ibm_db2 adapter

If you would like to speed up the current 1.1 version of the adapter included in the Starter Toolkit for DB2 on Rails, you can replace the ‘tables’ and ‘colums’ methods from within the ibm_db2_adapter.rb file, with this code here.

This change will allow you to significantly boost your performance level when working with Rails and DB2. As you may note, the crucial change here relies on the fact that a slow driver call is replaced with an ad hoc query to the SYSCAT.

Naturally this will be included with the next toolkit release, which will be out soon. ;-)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

August 21 2006 | Tips&Tricks | Comments Off

IBM DB2 and migrations

There’ve been a few questions about migrations and the IBM DB2 adapter. I’ve written a short list that explains what transformations are supported and what are not so far.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

June 27 2006 | How-to | Comments Off

How to connect Rails to DB2

I’ve just created a page that explains how to configure the database.yml file in Rails so that it works with the IBM DB2 adapter. You can find it here.

We plan to create an extensive FAQ section on this site, where we’ll address several of the main questions that we’ve been receiving over the past few weeks.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

June 22 2006 | How-to | 2 Comments »

« Prev