Ingres Ruby Learn

From Ingres Community Wiki

(Redirected from Ruby Driver)
Jump to: navigation, search

Ruby is an interpreted scripting language for object-oriented programming which is open source and free. Like Perl, it has excellent support for text files. It runs on multiple platforms including Linux, Unix, Windows and Mac OS.

Ruby is similar to Python in that it provides a transition from the procedural to the object-oriented programming paradigms. Python has functions for procedural and methods for objects and then bridges them. Ruby, on the other hand, is purely object-oriented, but can do procedural things (unlike Smalltalk). Ruby’s syntax and design are heavily influenced by Perl, so Perl programmers should feel comfortable with Ruby. Ruby, in fact, has been touted as a possible Perl replacement. It is unlikely, however, to replace Python because their design philosophies are quite different. Ruby was originally developed around 1993-1995 to provide a true object-oriented language, which the developer felt did not exist in current languages such as Perl and Python.

A lot of the interest in Ruby has come about due to the popular Ruby on Rails project, which provides a programmer-friendly (productive) development environment for database-backed web applications.

Contents

Ruby Driver: Project Resources

The Driver is currently in Alpha Status.

Setup

To build and install the Ingres Ruby interface, the following components are required:

  • Ingres 2.6 or above. At a minimum, an Ingres client installation is required on the same machine as the Ruby installation. For a list of Ingres binary and source downloads, see http://www.ingres.com.
  • Ruby, preferably at version 1.8.5 or later. Additional Ruby components or related products (such as Active Record or Rails) may also be required depending on how Ruby will be used with Ingres. See below for details.
  • C compiler (for example, GNU/C on Linux and UNIX, or Microsoft Visual Studio 6 on Windows). The C compiler is not needed if using a pre-built version of the Ingres Ruby driver.

Note: Ruby does not yet support building on later versions of Microsoft Visual Studio.

  • The Ingres Ruby AR adapter source code and driver binary. The source code for the driver is also needed if not using the pre-built binary.

Building and Installing the Ingres Ruby AR Adapter/Driver

Ingres AR Adapter

At a minimum, Ruby's Active Record must be installed. If running Rails, this will already exist as part of the Rails installation. For non-Rails users, AR may come with Ruby or may be installed separately as a Ruby “gem” into the Ruby installation.

There are several steps required to install the Ingres AR adapter into the Ruby AR installation.

Note: If only using the Ingres Ruby driver interface (not AR), installation of the adapter can be skipped and you can go directly to installation of the driver below.

Typically, the base path of the AR installation will be similar to the following and will be referred to hereafter in this documentation as AR_BASE (where the last digits in the path refer to the AR version):

UNIX/Linux: /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2

Windows: C:\ruby\lib\ruby\gems\1.8\gems\activerecord-1.15.3

To install the Ingres AR adapter into the Ruby AR installation

  1. Copy the adapter file, ingres_adapter.rb, to the AR_BASE/lib/active-record/connection_adapters directory.
  2. Add Ingres as a valid database to AR. Edit active_record.rb file in AR_BASE/lib by adding “ingres” to the end of a line that looks like: RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase ingres )
  3. Set up database connection information. Create a new directory called native_ingres under the AR_BASE/test/connections directory. Copy and edit the sample connection.rb file to define database name, user ID, password information.
  4. Set II_DATE_FORMAT to SWEDEN. Either set this as an OS environment variable in your RAILS application environment or as an Ingres variable (with the ingsetenv command). This restriction will be removed in the future. Also, code in the adapter file, if uncommented (scan for SWEDEN), may allow successful processing without setting II_DATE_FORMAT.
  5. For each Rails application accessing Ingres, edit the database.yml file in the application's config folder to specify the Ingres adapter plus database and user information. The following is a sample entry for a local Ingres database connection named my_rails_app_development:

development:

   adapter: ingres
   database: my_rails_app_development
   username: ingres
   password: ingres
   host: localhost

For remote connections, change database and host to Ingres remote connection format in either “vnode::databasename” where vnode is a name configured in the Ingres Network Utility or a dynamic vnode in @host,protocol,port[user,pwd]” format. For details, see the Ingres Connectivity Guide.

Testing ActiveRecord Support

See How to test Ruby on Rails with Ingres for information on Unit testing Rails against Ingres

Ingres Ruby Driver

A binary version of the driver is provided for Windows (Ingres.so). If using the provided binary, skip to the install step below.

The driver can also be built from the source provided (Ingres.c). To build and install the Ingres Ruby driver, the following components are needed AND MUST BE IN YOUR PATH:

  • Ingres installation
  • C compiler (for example, GNU/C on Linux and UNIX, or Microsoft Visual Studio 6 on Windows).

To build the driver

  1. Copy source Ingres.c and extconf.rb to your build directory (anywhere).
  2. Create the makefile using the Ruby mkmf utility. Run the following command after customizing it to your installation of Ingres:
ruby -r mkmf extconf.rb
    --with-ingres-include='/opt/Ingres/IngresII/ingres/files/'
    --with-ingres-lib='/opt/Ingres/IngresII/ingres/lib/'

A sample createMake.bat has been included for Windows. The utility mkmf pulls configuration information from the extconf.rb file, which may need slight library name changes for different versions of Ingres or operating systems; see comments in extconf.rb file.

The output should look similar to the following:

$ ruby -r mkmf extconf.rb --with-ingres-include='/usr/ingres/files/' --with-ingres-lib='/usr/ingres/lib'
checking for iiapi.h... yes
checking for main() in -lingres... yes
checking for main() in -lingres... yes
creating Makefile
  1. Compile and link the driver. Type make on Linux and UNIX or nmake on Windows. This should compile and link cleanly, creating output shared library Ingres.so.
  • On Windows, this is a DLL, but is nevertheless suffixed with “.so” rather than “.dll”.
  • On Windows, you can ignore warnings about the compiler and linker flags being unknown options.
  • On Windows with Ruby versions later than 1.8.5, the following error may be seen on the link:

cannot open input file "msvcrt-ruby18.lib"

This can be resolved by removing the (lower case) “libpath =” line in the makefile.

To install the driver

Type make install. (On Windows, type nmake).

Or, with the pre-built Windows binary, copy Ingres.so to Ruby i386-msvcrt directory, such as: c:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt.

Known Issues and Limitations

Please report any known issues today through the forum.

Features Not Included

The following features are currently not included in the Ingres Open Source Ruby interface

  • Only one Ingres connection at a time is supported from an application.
  • Data types not supported are: float4, float8, money, bigint, decimal, and ANSI date/time/timestamp.
  • You can find a list of all the missing features in the Ruby Project Page

Resources

Personal tools
Developing With