Using the OpenLink Rails ODBC Adapter with Sybase

Table of Contents

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 Sybase (TDS) agents/Lite drivers are shown below.

Active Record abstract type Ruby type Sybase type
:string String VARCHAR(255)
:boolean Object BIT
:datetime Time DATETIME
:time Time TIME
:timestamp Time DATETIME
:date Date DATE
:text String TEXT
:integer Fixnum INT
:float Float REAL
:binary String IMAGE
:decimal BigDecimal NUMERIC

It is suggested you use these native database types when creating tables to support your Rails models. Example table definitions are attached below:

  • sybase_odbc.sql These are the table definitions used for creating fixtures during testing - similar fixture definitions can be found for other databases in the ActiveRecord sources under active-record-root/test/fixtures/db_definitions.


Set the connection option :convert_numeric_literals to true to avoid errors similar to: "Implicit conversion from datatype VARCHAR to INT is not allowed."

:boolean columns use the BIT SQL type, which does not allow nulls or indexes. If a DEFAULT is not specified for create_table, the column will be declared with DEFAULT 0.

Migrations are supported, but for ALTER TABLE commands to work, the database must have the database option 'select into' set to true with sp_dboption.

    1> use mydb
    2> go
    1> master..sp_dboption mydb, "select into", true
    2> go
    1> checkpoint
    2> go
ODBC-Rails and the ODBC-Rails website are Copyright (C) OpenLink Software 2006-2008