Ruby on Rails
Firebird Adapter

An ActiveRecord Firebird adapter, based on the FireRuby extension, has been submitted as a Rails patch (#1874)

This page provides instructions on how you can “beta test” the new adapter.

Updates

Install ActiveRecord with Firebird Patch

  1. If you haven’t already, install Rails 0.13.1:
    $ gem install rails -r -v ‘0.13.1’
  2. Create a new Rails application (or you could try using an existing one):
    $ rails path-to-your-rails-app
  3. Download the following zip archive of Rails with the Firebird adapter patch (updated on 8/18/2005):
    http://www.kenkunz.net/rails/rails_r2032_plus_firebird.zip
  4. Un-zip the archive in the vendor subdirectory of your Rails application directory. You should now have an rails subdirectory directly under vendor.

Install FireRuby extension

The Firebird Adapter depends on the FireRuby extension (>= 0.3.2) for connecting to a Firebird database from Ruby. FireRuby is available as a gem:

$ gem install fireruby -r -v ‘0.3.2’

Database Setup

  1. You’ll need to create at least one Firebird database to start testing ActiveRecord with Firebird.
  2. I recommend you add an entry to Firebird’s aliases.conf file for your ActiveRecord database(s).
  3. Edit the database.yml file found in the config subdirectory of your Rails app directory. See example at the end of this page or additional example Firebird sample database.yml.

Usage

  1. Read the Firebird adapter documentation! You’ll find this within the rdoc documentation under your-rails-app/vendor/rails/activerecord/doc.
  2. Follow the normal ActiveRecord conventions for table names, primary key columns, etc. The one “extra” you’ll need for Firebird is that you’ll have to create a generator for any tables that require a sequence-based primary key. The default naming convention is table_name_seq. So if you have a users table, you would need to create a corresponding users_seq generator:
    CREATE GENERATOR users_seq;

    Warning: I got a
    generator CLIENTS_SEQ is not defined
    when testing my clients table so I had to use an uppercase name for the generator to work when testing. So the example should read:
    CREATE GENERATOR USERS_SEQ;



    You can override the default sequence name at the AR subclass level. See rdoc documentation.
  3. Be aware that you’re testing a “bleeding edge” version of Rails. The patched version posted here is based on rev. 2032 from the Rails subversion trunk.

Example database.yml for Firebird

development:
  adapter: firebird
  database: rails_development
  host: localhost
  username: rails
  password: rails

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: firebird
  database: rails_test
  host: localhost
  username: rails
  password: rails

Questions/Comments

In Windows (specifically XP, but i think correct for all NT versions)
Ruby.exe can give you error that I can not find fbclient.dll.
This file is used by clients to reach firebird. In default installation it is in


“C:\Program Files\Firebird\Firebird_1_5\bin\fbclient.dll”

copy this file to
 C:\WINDOWS\system32. 

If you forget add your database’s name to aliases.conf, found in


“C:\Program Files\Firebird\Firebird_1_5\aliases.conf”

rails may not reach it. Add this line to aliases.conf

blog_development = G:\projects\DB_files\YOUR_DATABASE.GDB

If you have questions/comments about testing the adapter, post them here or to the Rails mailing list. If you have questions/comments relating to implementation details of the adapter, please post them to the ticket.

Using Firebird to store sessions 26 Jan 2006

NOTE 6-13-06: This bug has a patch which has been applied to the trunk.

There is currently a problem in the Firebird adapter regarding filed lengths of blobs that stops it from being used as the store for sessions. While this is being fixed in the adapter you can use this workaround:

Do not declare the session data field as blob but rather as a varchar. Make sure it is sufficient size to hold the session.

Using autocomplete with Firebird 04 Feb 2006

text_field_with_autocomplete does not work out of the box with Firebird. This is because the script generates a select statement that user the sql command LOWER that is not part of Firebird.

There are 2 workarounds to this: