Configuring Rails Support in SAP Sybase IQ

You can configure Ruby on Rails support in SAP Sybase IQ.

Prerequisites

There are no prerequisites for this task.

Task
  1. Install RubyGems. It simplifies the installation of Ruby packages. The Ruby on Rails download page directs you to the correct version to install. See http://www.rubyonrails.org/.
  2. Install the Ruby interpreter on your system. The Ruby on Rails download page recommends which version to install. See http://www.rubyonrails.org/.
  3. Install Ruby Rails and its dependencies by running the following command:
    gem install rails
  4. Install the Ruby Development Kit (DevKit). Download the DevKit from http://rubyinstaller.org/downloads/ and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit.
  5. Install the SQL Anywhere ActiveRecord support (activerecord-sqlanywhere-adapter) by running the following command:
    gem install activerecord-sqlanywhere-adapter
  6. Add SAP Sybase IQ to the set of database management systems supported by Rails. At the time of writing, Rails 3.1.3 was the current released version.
    1. Configure a database by creating a sqlanywhere.yml file in the Rails configs\databases directory. If you have installed Ruby in the \Ruby directory and you have installed version 3.1.3 of Rails, then the path to this file would be \Ruby\lib\ruby\gems\1.9.1\gems\railties-3.1.3\lib\rails\generators\rails\app\templates\config\databases. The contents of this file should be:

      #
      # SQL Anywhere database configuration
      #
      # This configuration file defines the patten used for
      # database filenames. If your application is called "blog",
      # then the database names will be blog_development,
      # blog_test, blog_production. The specified username and
      # password should permit DBA access to the database.
      #
      
      development:
        adapter: sqlanywhere
        server: <%= app_name %>
        database: <%= app_name %>_development
        username: DBA
        password: sql
      
      # 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: sqlanywhere
        server: <%= app_name %>
        database: <%= app_name %>_test
        username: DBA
        password: sql
      
      production:
        adapter: sqlanywhere
        server: <%= app_name %>
        database: <%= app_name %>_production
        username: DBA
        password: sql

      The sqlanywhere.yml file provides a template for creating database.yml files in Rails projects. The following database options can be specified:

      • adapter – (required, no default). This option must be set to sqlanywhere to use the SQL Anywhere ActiveRecord adapter.
      • database – (required, no default). This option corresponds to DatabaseName in a connection string.
      • server – (optional, defaults to the database option). This option corresponds to ServerName in a connection string.
      • username – (optional, defaults to 'DBA'). This option corresponds to UserID in a connection string.
      • password – (optional, defaults to 'sql'). This option corresponds to Password in a connection string.
      • encoding – (optional, defaults to the OS character set). This option corresponds to CharSet in a connection string.
      • commlinks – (optional). This option corresponds to CommLinks in a connection string.
      • connection_name – (optional). This option corresponds to ConnectionName in connection string.
    2. Update the Rails app_base.rb file. Using the same assumptions in the previous step, this file is located in the path \Ruby\lib\ruby\gems\1.9.1\gems\railties-3.1.3\lib\rails\generators\app_base.rb. Edit the app_base.rb file and locate the following line:

      DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver )

      Add sqlanywhere to the list as follows:

      DATABASES = %w( sqlanywhere mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver )
  7. Follow the tutorial on the Ruby on Rails web site (http://guides.rails.info/getting_started.html) using the following SAP Sybase IQ-specific notes:
    • In the tutorial, you are shown the command to initialize the blog project. Here is the command to initialize the blog project for use with SAP Sybase IQ:

      rails new blog -d sqlanywhere
      
    • After you create the blog application, switch to its folder to continue work directly in that application:

      cd blog
      
    • Edit the gemfile file to include a gem directive for the SQL Anywhere ActiveRecord adapter. Add the new directive following the indicated line below:

      gem 'sqlanywhere'
      gem 'activerecord-sqlanywhere-adapter'
    • The config\database.yml file references the development, test, and production databases. Instead of using a rake command to create the databases as indicated by the tutorial, change to the db directory of the project and create three databases as follows.

      cd db
      iqinit -dba DBA,sql blog_development
      iqinit -dba DBA,sql blog_test
      iqinit -dba DBA,sql blog_production
      cd ..

You have configured Rails support in SAP Sybase IQ.

Next

Start the database server and the three databases as follows.

iqsrv16 -n blog blog_development.db blog_production.db blog_test.db

The database server name in the command line (blog) must match the name specified by the server: tags in the database.yml file. The sqlanywhere.yml template file is configured to ensure that the database server name matches the project name in all generated database.yml files.