Ruby on Rails
HowToSetupSybaseAdapterOnRailsOnOSX (Version #21)

These instructions are for Sybase on Mac OS X.

To setup on Win32 with Visual Studio, go to SybaseASEonWin32. To setup on Linux, go to HowToSetupSybaseAdapterOnRails

This was originally written for 10.4 “Tiger”. I’ve added notes for where 10.5 “Leopard” differs.

Install Sybase Open Client for Mac OS X

  1. Used SybaseASE 12.5.3 ESD1 client on Mac OS X 10.4.10 (i.e. Sybase_Client_1253ESD1.pkg)
  2. Add environment variables to ~/.bash_login

    export SYBASE=/Applications/Sybase/System export SYBASE_OCS=OCS-12_5 export PATH=$SYBASE/$SYBASE_OCS/bin:$PATH export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:$SYBASE:$SYBASE/$SYBASE_OCS/lib:$SYBASE/locales
  3. Reload .bash_login (or just start a new Terminal window or shell)

    source ~/.bash_login
  4. Make sure that your interfaces file is properly set up in $SYBASE/interfaces.
  5. On Leopard, you may have to edit $SYBASE/locales/locales.dat
    Add a line to the [macosx] section

    locale = en_US.UTF-8, us_english, utf8
    Other options are:
    • Change the preferences in Terminal.app under Preferences… → Settings → Advanced → Character Encoding: to Western (ISO Latin 1);
    • Or, uncheck the box next to “Set LANG environment variable on startup”
    • Or, just use ITerm
  6. Check if you can access Sybase using isql

    victory:/Users/holt holt$ isql -SHOSTNAMEFROMINTERFACE -Uusername -Ppassword

Download Ruby Sybase Library

  1. Ruby Sybase Library
  2. Unpack the library, and then Edit extconfig.rb

    gunzip sybct-ruby-0.2.9.tar.gz tar -xvf sybct-ruby-0.2.9.tar cd sybct-ruby-0.2.9 vi extconfig.rb
  3. Comment out all the lines that are for Linux and gcc. Uncomment the lines that are for Mac OS X. The settings for 10.4 should work for Leopard, too.
  4. Create the makefile and compile the bundle

    ruby extconf.rb make
  5. Copy sybct.o sybct.bundle sybct.rb sybsql.rb to your ruby path. To find what it is, do:

    victory:/Users/holt holt$ irb irb(main):001:0> $LOAD_PATH => ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/powerpc-darwin8.10.0", "."]

    in my case it was /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0
    NOTE: in ASE15 libct.so.* is called libsybct.so.*. the same applies to other 3 files. ( found by Rasika Ranaweera )
    On Leopard, using the built-in ruby, it will look something like this:

    victory:/Users/holt holt$ irb >> $LOAD_PATH => ["/Library/Ruby/Site/1.8", "/Library/Ruby/Site/1.8/powerpc-darwin9.0", "/Library/Ruby/Site/1.8/universal-darwin9.0", "/Library/Ruby/Site", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin9.0", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0", "."]
  6. Run some tests

    $bash: irb irb(main):001:0> require 'sybsql' => true

    if you did not succeed you would get the following error while including ‘sybsql’ from irb

    $bash: irb irb(main):001:0> require 'sybsql' LoadError: libsybtcl.so: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.so from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.so from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.rb:3 from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybsql.rb:4 from (irb):1

    And if you were to start rails app that uses sybase_adapter you would get the following:

    database configuration specifies nonexistent sybase adapter (ActiveRecord::AdapterNotFound)

    One more test to run would be using ruby isql:

    cd sybct-ruby-0.2.9/

victory:/usr/local/src/sybct-ruby-0.2.9 holt$ ruby -I . ./sample/isql.rb -S HOSTNAMEFROMINTERFACE -U username -P password

!! MAX ROWCOUNT 2000 !!
1→ select count() from sysobjects
2→ go
<- select count(
) from sysobjects
restype =ROW_RESULT

——
914

(row count = 1, tran state = ’completed’)
3→ quit
EOF

  1. Finally let’s get Sybase to be on Rails
    Edit your config/database.yml to look like the following:

    development: adapter: sybase host: SYBASE database: dbName username: someUser password: somePassoword

production:
development

host: should refer to host name that was set up in the $SYBASE/interfaces file.

These instructions are for Sybase on Mac OS X.

To setup on Win32 with Visual Studio, go to SybaseASEonWin32. To setup on Linux, go to HowToSetupSybaseAdapterOnRails

This was originally written for 10.4 “Tiger”. I’ve added notes for where 10.5 “Leopard” differs.

Install Sybase Open Client for Mac OS X

  1. Used SybaseASE 12.5.3 ESD1 client on Mac OS X 10.4.10 (i.e. Sybase_Client_1253ESD1.pkg)
  2. Add environment variables to ~/.bash_login

    export SYBASE=/Applications/Sybase/System export SYBASE_OCS=OCS-12_5 export PATH=$SYBASE/$SYBASE_OCS/bin:$PATH export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:$SYBASE:$SYBASE/$SYBASE_OCS/lib:$SYBASE/locales
  3. Reload .bash_login (or just start a new Terminal window or shell)

    source ~/.bash_login
  4. Make sure that your interfaces file is properly set up in $SYBASE/interfaces.
  5. On Leopard, you may have to edit $SYBASE/locales/locales.dat
    Add a line to the [macosx] section

    locale = en_US.UTF-8, us_english, utf8
    Other options are:
    • Change the preferences in Terminal.app under Preferences… → Settings → Advanced → Character Encoding: to Western (ISO Latin 1);
    • Or, uncheck the box next to “Set LANG environment variable on startup”
    • Or, just use ITerm
  6. Check if you can access Sybase using isql

    victory:/Users/holt holt$ isql -SHOSTNAMEFROMINTERFACE -Uusername -Ppassword

Download Ruby Sybase Library

  1. Ruby Sybase Library
  2. Unpack the library, and then Edit extconfig.rb

    gunzip sybct-ruby-0.2.9.tar.gz tar -xvf sybct-ruby-0.2.9.tar cd sybct-ruby-0.2.9 vi extconfig.rb
  3. Comment out all the lines that are for Linux and gcc. Uncomment the lines that are for Mac OS X. The settings for 10.4 should work for Leopard, too.
  4. Create the makefile and compile the bundle

    ruby extconf.rb make
  5. Copy sybct.o sybct.bundle sybct.rb sybsql.rb to your ruby path. To find what it is, do:

    victory:/Users/holt holt$ irb irb(main):001:0> $LOAD_PATH => ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/powerpc-darwin8.10.0", "."]

    in my case it was /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0
    NOTE: in ASE15 libct.so.* is called libsybct.so.*. the same applies to other 3 files. ( found by Rasika Ranaweera )
    On Leopard, using the built-in ruby, it will look something like this:

    victory:/Users/holt holt$ irb >> $LOAD_PATH => ["/Library/Ruby/Site/1.8", "/Library/Ruby/Site/1.8/powerpc-darwin9.0", "/Library/Ruby/Site/1.8/universal-darwin9.0", "/Library/Ruby/Site", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin9.0", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0", "."]
  6. Run some tests

    $bash: irb irb(main):001:0> require 'sybsql' => true

    if you did not succeed you would get the following error while including ‘sybsql’ from irb

    $bash: irb irb(main):001:0> require 'sybsql' LoadError: libsybtcl.so: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.so from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.so from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybct.rb:3 from /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.10.0/sybsql.rb:4 from (irb):1

    And if you were to start rails app that uses sybase_adapter you would get the following:

    database configuration specifies nonexistent sybase adapter (ActiveRecord::AdapterNotFound)

    One more test to run would be using ruby isql:

    cd sybct-ruby-0.2.9/

victory:/usr/local/src/sybct-ruby-0.2.9 holt$ ruby -I . ./sample/isql.rb -S HOSTNAMEFROMINTERFACE -U username -P password

!! MAX ROWCOUNT 2000 !!
1→ select count() from sysobjects
2→ go
<- select count(
) from sysobjects
restype =ROW_RESULT

——
914

(row count = 1, tran state = ’completed’)
3→ quit
EOF

  1. Finally let’s get Sybase to be on Rails
    Edit your config/database.yml to look like the following:

    development: adapter: sybase host: SYBASE database: dbName username: someUser password: somePassoword

production:
development

host: should refer to host name that was set up in the $SYBASE/interfaces file.