README

Path: README
Last Update: Wed Apr 02 18:46:02 -0600 2008

Ruby/Informix — Ruby library for connecting to IBM Informix.

Motivation

The situation that started it all [link].

Download

The latest version of Ruby/Informix can be found at:

rubyforge.org/projects/ruby-informix

Supported platforms

Ruby/Informix has been tested succesfully with Informix 7 and above, and Informix CSDK 2.81 and above, on the following platforms:

  Operating System     Architecture
  -----------------------------------------
  Solaris              SPARC64
  GNU/Linux            x86, x86-64
  Windows XP/2000      x86
  HP-UX 11.11          PA-RISC 2.0 64-bit

Send me an e-mail if you have [un]succesfully tested Ruby/Informix on another platform.

Installation

Requirements

If you want to build Ruby/Informix instead of installing a precompiled gem, you will also need:

  • Microsoft Visual Studio 6.0, for Windows or
  • an ANSI C compiler, for UNIX and Linux

Rubygem installation

gem install ruby-informix

Documentation

RDoc and ri documentation is automatically installed. It can also be found online at:

ruby-informix.rubyforge.org/doc

Examples

Connecting to a database

    db = Informix.connect('stores')

Fetching all records from a table

    cur = db.cursor('select * from stock')
    cur.open
    records = cur.fetch_all
    cur.drop # or close, if you want to reopen it later

Same thing, with blocks

    records = db.cursor('select * from stock') do |cur|
      cur.open
      cur.fetch_all
    end

Inserting records

    stmt = db.prepare('insert into state values(?, ?)')
    stmt.execute('CA', 'California')
    stmt.call('NM', 'New Mexico')
    stmt['TX', 'Texas']

Iterating over a table using a hash (shortcut)

    db.each_hash('select * from customers') do |cust|
      puts "#{cust['firstname']} #{cust['lastname']}"
    end

More examples can be found at:

ruby-informix.rubyforge.org/examples.html

Data types supported

  Informix                          Ruby
  -----------------------------------------------------------------------------
  SMALLINT, INT, INT8, FLOAT,      Numeric
  SERIAL, SERIAL8
  CHAR, NCHAR, VARCHAR, NVARCHAR   String
  DATE                             Date
  DATETIME                         Time
  INTERVAL                         Informix::IntervalYTM, Informix::IntervalDTS
  DECIMAL, MONEY                   BigDecimal
  BOOL                             TrueClass, FalseClass
  BYTE, TEXT                       StringIO, String
  CLOB, BLOB                       Informix::Slob

NULL values can be inserted and are retrieved as nil.

BYTE and TEXT are retrieved as Strings, but for supplying them as input parameters, a StringIO object, or a anyother IO-like object that provides a read method must be used.

Strings can be used in the cases where Informix accepts them for non-character data types, like DATE, DATETIME, INTERVAL, BOOL, DECIMAL and MONEY

Recommendations

  • use blocks to release Informix resources automatically as soon as possible, or use drop
  • you can optimize cursor execution by changing the size of fetch and insert buffers, setting the environment variable FET_BUF_SIZE to up to 32767.

Support

Feel free to send me bug reports, feature requests, comments, patches or questions directly to my mailbox or the following forums:

  • Online forums at Rubyforge [link]
  • Mailing list [link]

Presentations and articles about Ruby/Informix

  • "Talking with Perl, PHP, Python, Ruby to IDS" [link], Eric Herber, The Informix Zone.
  • "Informix on Rails" [link], Guy Bowerman, IBM developerWorks Blogs: Informix Application Development.
  • "Ruby/Informix, and the Ruby Common client" [link], Guy Bowerman, IBM developerWorks Blogs: Informix Application Development.
  • "Using IBM Informix Dynamic Server on Microsoft Windows, Part 6" [link], Akmal B. Chaudhri, IBM developerWorks: On demand demos.

License

Ruby/Informix is available under the three-clause BSD license

 Copyright (c) 2006-2008, Gerardo Santana Gomez Garrido <gerardo.santana@gmail.com>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.

[Validate]