General Usage Information

Connection Options

The following options are supported by the ODBC adapter.

  • :dsn: Specifies the ODBC data source name.
  • :username: Specifies the database user.
  • :password: Specifies the database password.
  • :trace: If set to true, turns on simple call tracing to the log file referenced by ActiveRecord logger. If omitted, :trace defaults to false.
  • :emulate_booleans: Forces a particular numeric column type to be interpreted as holding true/false boolean values rather than numeric values. It is intended for use with databases which do not support a native BOOLEAN type. See emulate_booleans for more information. If omitted, :emulate_booleans defaults to false.
  • :convert_numeric_literals: Required for databases which do not allow numeric values represented as string literals to be inserted into numeric columns. If omitted, :convert numeric_literals defaults to false.

Boolean Emulation

The :emulate_booleans option instructs the adapter to interpret certain numeric column types as holding boolean, rather than numeric, data. It is intended for use with databases which do not have a native boolean data type, or if the ODBC driver does not map a database type to the ODBC SQL_BIT type in its SQLGetTypeInfo( ) output. When boolean emulation is enabled, the adapter will interpret the following column types as boolean. The emulation option is not required for any databases supported by the adapter not appearing in this list. If you wish to use boolean emulation, you should use relevant column type below when defining a table column which will hold boolean data for your Rails model.

Database Surrogate boolean type
Oracle NUMBER(1)


If tracing is enabled through the :trace connect option, when running a Rails application the trace output will go to one of the log files in log directory of your application's directory tree. Depending on the configured environment, this will be one of production.log, development.log or test.log.

Changes in versions 1.5 and 2.0

A typical DSNless connection entry in the databases.yml file is of the form:

    adapter: odbc
    conn_str: DRIVER={DriverName};OPTIONS=;DATABASE=;UID=me;PWD=

where DriverName is defined in odbcinst.ini ($ODBCINSTINI).

When working with the sample application examples, `rake migrate' should be replaced with `rake db:migrate'.

With the Rails 2 Adapter, the procedure to build the scaffold is slightly changed. Previously (in Rails 1.x) there were four steps:

  • Execute: script/generate migration accounts
  • Editing: db/migrate/001_accounts.rb (which defines an empty migration)
  • Execute: rake db:migrate
  • Execute: script/generate scaffold account expenses

This is all replaced by the more streamlined

  • Execute: script/generate scaffold Movie title:string description:text one sheet_url:string

which defines the fields/datatypes etc all in one command.

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