294 | Chapter 9: Incorporating and Extending Rails
In Rails 2.0, the lesser-used connection adapters have been moved out
of Rails trunk and into gems so that they can be installed if needed.
The connection adapters for Firebird, FrontBase, OpenBase, Oracle,
Microsoft SQL Server, and Sybase now live under/adaptersin the
Rails repository.
The gems for these connection adapters are hosted at the Rails gem
server (http://gems.rubyonrails.org) and are named activerecord-
dbname-adapter (for example, activerecord-oracle-adapter or
activerecord-sqlserver-adapter), so they can be installed with a com-
mand such as the following:
$ gem install activerecord-sybase-adapter –source \
http://gems.rubyonrails.org
Incidentally, IBM maintains its own DB2 adapter for ActiveRecord, so
the old ActiveRecord DB2 connection adapter is gone in Rails 2.0.
In order to run the ActiveRecord unit tests, you will need to create test databases.
Thankfully, there are some Rake tasks that automate this process. For a full test of
the “big four” connection adapters from the ground up, follow these steps:
- Install and configure the database servers: MySQL, PostgreSQL, SQLite, and
SQLite3. The client libraries also need to be installed; these are installed with the
server binaries but can be installed separately if the server is on a remote
machine.
For MacPorts users, SQLite 2 can be installed withsudo port install sqlite2
(even though its files are namedsqlitefor historical reasons, the port name is now
sqlite2). If you have previously installed thesqliteport, you should uninstall it
before installingsqlite2 andsqlite3. - Install the Ruby database libraries with RubyGems:
$ sudo gem install mysql
$ sudo gem install postgres
$ sudo gem install sqlite-ruby
$ sudo gem install sqlite3-ruby
Installing themysqllibrary is not strictly necessary; Rails includes a pure-Ruby
MySQL library inactiverecord/lib/active_record/vendor/mysql.rb. This implemen-
tation will be used if no native mysql extension is found, which is useful on sys-
tems like Windows, where a Ruby interpreter can be more accessible than a C
compiler. Additionally, thepostgresgem can be replaced by thepostgres-pr
gem, which is also pure Ruby.
MacPorts users may have some difficulty with these steps; the default configura-
tion scripts look in the/usrand/usr/localtrees for the client libraries installed in
step 1, while MacPorts installs into/opt/local. This can be fixed by passing con-
figuration parameters intogem, which are preceded by--so they are not parsed
as options togem itself:
$ sudo gem install sqlite3-ruby -- --with-sqlite-dir=/opt/local