SQL Anywhere Ruby Driver

This is a native SQL Anywhere driver for Ruby. This library wraps the functionality provided by the SQL Anywhere DBCAPI library. This driver is intended to be a base-level library to be used by interface libraries such as Ruby-DBI and ActiveRecord.

This driver can be used with SQL Anywhere 10 and later versions.

This driver is licensed under the Apache License, Version 2.

The official code repository is located on GitHub. The repository can be cloned with:

   git clone git://github.com/sqlanywhere/sqlanywhere.git

Build Instructions


All Platforms

To build the library (.so), use:


To build and install the gem, use:

   rake gem
   rake install

The other rake tasks are

   rake clean   -> Cleans up all temp files (ex *.~)
   rake clobber -> Cleans up all built files (ex *.gem, *.o, *.so)

Additional Install Notes for Windows

The popular One-Click Ruby Installer for Windows (RubyInstaller) is built using Microsoft Visual C++ 6.0. Since problems can arise by combining binaries from different compilers, we advise you use this compiler.

If you want to use a more recent version of the MS C++ compiler, you will need to make a few changes:

  1. Open the file: libruby1.8i386-mswin32config.h, and comment out the first three lines so they look like:

     //#if _MSC_VER != 1200
     //#error MSC version unmatch
   This removes the check for C++ Version 6.0
  1. Open rakefile and set:

       APPLY_MANIFEST = true

    This will add the manifest to the compiled binaries.

By default, rake will attempt to use Microsoft nmake when building under Windows. To use another make program, set:


Running Unit Tests

  1. Change to the the test directory

     cd test
  2. Create a testing database:

     dbinit test
  3. Start the testing database:

     dbeng11 test.db
  1. Create the test schema:

     dbisql -c "eng=test;uid=dba;pwd=sql" test.sql
  2. Run the unit tests:

     ruby sqlanywhere_test.rb

If the tests fail to run, make sure you have set up the SQL Anywhere environment variables correctly. For more information review the online documentation here.


This script makes a connection, prints Successful Ruby Connection to the SQL Anywhere console, then disconnects.

   # load the SQLAnywhere gem
     require 'rubygems'
     gem 'sqlanywhere'
     unless defined? SQLAnywhere
       require 'sqlanywhere'

   # create an interface
   api = SQLAnywhere::SQLAnywhereInterface.new()

   # initialize the interface (loads the DLL/SO)
   SQLAnywhere::API.sqlany_initialize_interface( api )

   # initialize our api object

   # create a connection
   conn = api.sqlany_new_connection()

   # establish a connection
   api.sqlany_connect(conn, "uid=dba;pwd=sql")

   # execute a query without a result set
   api.sqlany_execute_immediate(conn, "MESSAGE 'Successful Ruby Connection'")

   # disconnect from the database

   # free the connection resources

   # free resources the api object uses

   # close the interface
   SQLAnywhere::API.sqlany_finalize_interface( api )





Generated with the Darkfish Rdoc Generator 1.1.6.