Using the OpenLink Rails ODBC Adapter with MySQL

Table of Contents

Using the Native MySQL ODBC Driver with the Rails ODBC Adapter

The native MySQL ODBC driver requires version 0.9991 (5-Aug-06) of the Ruby ODBC Bridge or greater.

Earlier versions of the bridge contain a bug in the transaction handling - a request to commit on a Rails connection commits all ODBC connections held by the ODBC environment (henv) associated with the Rails application. The ODBC feature which allows committing at the henv level does not work with the native MySQL driver (The SQLEndTran() call appears to succeed, but the MySQL trace shows that a COMMIT or ROLLBACK command does not reach the database). The OpenLink MySQL ODBC driver commits/rolls-back correctly at the henv level so the bug in the Ruby ODBC Bridge prior to release 0.9991 does not show up.

The bug shows up when running the tests in base_test.rb if transactional fixtures are used (i.e. if env var AR_NO_TX_FIXTURES is not set or is set to 'no').

v0.9991 of the Ruby ODBC Bridge commits/rolls-back at the ODBC connection level, as it should, not at the ODBC environment level.

Type Mappings

ActiveRecord defines a number of abstract data types. These and the corresponding Ruby data types are listed in the table below. Which native database types the abstract types map to will depend to some extent on the underlying ODBC driver used by the OpenLink Rails ODBC Adapter. The native type mappings for the OpenLink MySQL agents/Lite drivers are shown below.

Active Record abstract type Ruby type MySQL type
:string String VARCHAR(255)
:boolean Object TINYINT (TINYINT(1) if :emulate_boolean connection option is true)
:datetime Time DATETIME
:time Time TIME
:timestamp Time DATETIME
:date Date DATE
:text String LONGTEXT
:integer Fixnum INTEGER
:float Float DOUBLE
:binary String LONGBLOB
:decimal BigDecimal NUMERIC

It is suggested you use these native database types when creating tables to support your Rails models.

ODBC-Rails and the ODBC-Rails website are Copyright (C) OpenLink Software 2006-2008