Wednesday, May 21, 2008

binpatch 1.1.0 released

binpatch is a ports-like framework for building binary patches for OpenBSD.

Thanks Mike Erdely (merdelly@) for contributing to this release.

Visit to learn more about binpatch.

Monday, May 12, 2008

activerecord-informix-adapter available for Rails 2.1 RC

Ruby Inside is carrying the news of Rails 1.2 Release Candidate being tagged by David Heinemeier Hansson. Some of the new features are mentioned, along with instructions for getting Rails 1.2 RC.

I'm glad to see that the activerecord-informix-adapter gem was finally built and published in the Ruby on Rails' gems server, as can be seen by running

gem list --source -r

The gem is listed as activerecord-informix-adapter ( and can be installed by running

sudo gem install activerecord-informix-adapter --source


Saturday, April 26, 2008

From CVS to Git

There has been an exodus of Ruby developers recently, moving from Subversion to Git for SCM. Being a happy CVS user, I was curious about what Git could offer for a team of one developer.

After understanding the workflow used by experienced Git users and its benefits, I started to think the other way around: why use CVS when I can use Git.

Then I decided to move binpatch and Ruby/Informix repositories to Forking, contributing or just tracking the changes is now easier, through an easy to use interface, source code browser with history and RSS feeds.

The following links were especially useful to make the switch:

Binpatch and Ruby/Informix repositories can be found here.

Tuesday, April 01, 2008

Ruby/Informix 0.7.0 released

Yesterday night Ruby/Informix 0.7.0 escaped from my hands, after a vacational sprint that allowed Ruby/Informix to get new and important capabilities. The most obvious one is the support for the INTERVAL data type.

Actually, Ruby/Informix was able to handle insertion of INTERVAL data types already, because Informix accepts an ANSI SQL standard formatted string as an INTERVAL. Today, we can still use a String or use an Interval object for storing and also for retrieving INTERVAL data.

To create an Interval object you can write the following:

Interval = Informix::Interval # for short

ym = Interval.year_to_month(2, 5) #=> "2-05"
ds = Interval.day_to_second(1, 2,
3, 4) #=> "1 02:03:04.00000"


You don't need to specify all the fields of an INTERVAL.

# the rest of the fields are zero
Interval.year_to_month(2) #=> "2-00"
Interval.day_to_second(5) #=> "5 00:00:00.00000"

# using a hash
Interval.year_to_month(:months => 3) #=> "0-03"
Interval.day_to_second(:hours => 2,
:minutes => 5) #=> "0 02:05:00.00000"

You can even use fractions of years, days, hours, minutes or seconds:

Interval.year_to_month(1.5) #=> "1-06"
Interval.day_to_second(:hours => 1.5,
:minutes => 5) #=> "0 01:35:00.00000"

You can use Rationals instead of Floats for exactitud:

# a third of an hour?, not quite
Interval.year_to_month(0.3) #=> "0 00:18:00.00000"

# this is exact
Interval.year_to_month(Rational(1,3)) #=> "0 00:20:00.00000"

This is specially important when working with small fractions of seconds:

:seconds=>1.2) #=> "123456789 00:00:01.19922"
:seconds=>Rational(12,10)) #=> "123456789 00:00:01.20000"

Because when using Floats, there's a limit in the significant digits that can be stored that doesn't exist when using a Rational.

Interval objects have the ability to work with Date, DateTime and Time Ruby objects:

ym = Interval.year_to_month(1, 5) #=> "1-05"
today = #=> "2008-04-01"
ym + today #=> "2009-09-01"

# DAY TO SECOND and Time
ds = Interval.day_to_second(:hours=>3,
:minutes=> 10) #=> "0 03:10:00.00000"
now = #=> "2008-04-01 19:58:04.856533"
ds + now #=> "2008-04-01 23:08:04.856533"

You can't mix INTERVAL YEAR TO MONTH with Time, or INTERVAL DAY TO FRACTION with Date, because are incompatible. If you still want to do something like that, you can use DateTime:

now = #=> "2008-04-01 20:21:42"
ym = Interval.year_to_month(1, 5) #=> "1-05"
ds = Interval.day_to_second(:hours=>3,
:minutes=> 10) #=> "0 03:10:00.00000"

ym + now #=> "2009-09-01 20:21:42"
ds + now #=> "2008-04-01 23:31:42"

But there's still more. What about if I want to know how many minutes are in 3 days and 4 hours?

ds = Interval.day_to_second(:days=> 3,
:hours=> 4) #=> "3 04:00:00.00000"
ds.to_minutes #=> 4560.0

What about seconds

ds.to_seconds #=> 273600

There are some things left to learn about Intervals, but this post has become too long. Don't forget to check the documentation, which has been enriched with more examples.

Thursday, March 27, 2008

Where is the activerecord-informix-adapter gem?

I was waiting for the next release of Ruby on Rails to say this, but it's taking more time than I expected.

Rails/Informix was already imported in the Ruby on Rails SVN repository back on October 14th, 2007, but the activerecord-informix-adapter gem was not available as expected when Ruby on Rails 2.0 was released.

Well, Jeremy Kemper was so kind to tell me on December 27th, 2007, that the activerecord-informix-adapter gem will be available in the next release of Ruby on Rails. It was not available before because it was not connected to the build system. It was already fixed.

Meanwhile, you can take advantage of the Informix adapter now, installing it by hand, following the installation instructions for Rails 1.x, except for the part of editing a file. Just copy the file informix_adapter.rb to the location mentioned, and enjoy!

Tuesday, February 12, 2008

ibm_db and Ruby/Informix interface comparison

Antonio Cangiano, a Software Engineer at IBM, recently posted in his blog an Essential guide to the Ruby driver for DB2, which included some samples of IBM's ibm_db Ruby driver. This driver supports not only DB2, but several IBM databases, Informix included.

As Antonio states in his guide, it was not meant to be thorough (that's what the API reference is for), but it certainly helped to get an idea of how ibm_db looks at work.

Antonio explains in a comment that ibm_db's interface was taken from PHP's DB2 driver, and that same interface was used for the IBM's Ruby and Python drivers.

That helps to explain why the code examples don't look Ruby-ish at all.

Here's one of the simplest examples:

require 'rubygems'
require 'ibm_db'

if conn = IBM_DB::connect("sample", "db2inst1", "mypassword")
if stmt = IBM_DB::exec(conn, sql)
while row = IBM_DB::fetch_assoc(stmt)
puts "#{row['FIRSTNME']} #{row['LASTNAME']}: #{row['EMPNO']}"
puts "Statement execution failed: #{IBM_DB::stmt_errormsg}"
puts "Connection failed: #{IBM_DB::conn_errormsg}"

And here's the equivalent, written with Ruby/Informix:

require 'informix'

Informix.connect("sample", "db2inst1", "mypassword") do |conn|
conn.cursor(sql) do |cur|
cur.each_hash do |row|
puts "#{row['FIRSTNME']} #{row['LASTNAME']}: #{row['EMPNO']}"

The difference is obvious: blocks.

Blocks are one of the nicest features of Ruby. Matz, creator of Ruby, gave an attractive look to an old concept, which made it easy and desirable to use.

You can see blocks everywhere in Ruby as iterations, for resource management, event handling or as high order functions.

Blocks are a distinctive of Ruby. But still no blocks in ibm_db.

Fortunately Informix users have an alternative.

UPDATE: It will be even more succinct using the new features that will be included in the next release but that you can already try grabbing the code from the CVS tree.

require 'informix'

Informix.connect("sample", "db2inst1", "mypassword") do |conn|
conn.each_hash(sql) do |row|
puts "#{row['FIRSTNME']} #{row['LASTNAME']}: #{row['EMPNO']}"

Monday, February 11, 2008

Informix on Rails demo at IBM developerWorks

Some weeks ago, Akmal B. Chaudhri, Senior IT Specialist at IBM, completed a set of demos about working with Informix on Windows.

In part 6 of this set you can find an excellent guide, step by step, from scratch, about how to get Ruby on Rails working with Informix, using Ruby/Informix and Rails/Informix.

Thanks to Akmal for posting this demo and for giving (Ruby|Rails)/Informix a try.