Ruby Sybase Solaris: Difference between revisions

From EggeWiki
No edit summary
No edit summary
Line 56: Line 56:


I did a <code>make install</code>, but that only installed the .so, and not the require .rb files.  An additional <code>cp sybct.rb sybsql.rb /u/eggebr/pkgs/sunos-5.10-i86pc/lib/ruby/site_ruby/1.8/</code> was needed before I was able to use the library from a Rails script.
I did a <code>make install</code>, but that only installed the .so, and not the require .rb files.  An additional <code>cp sybct.rb sybsql.rb /u/eggebr/pkgs/sunos-5.10-i86pc/lib/ruby/site_ruby/1.8/</code> was needed before I was able to use the library from a Rails script.
In the end, I almost gave up and was going to try using JRuby instead, which would have fixed the database issues, at the cost of introducing plenty of other complexity.

Revision as of 14:32, 5 June 2006

This is seeming to be quite a painful combination. It seems most Ruby on Rails folks are running on some sort of LAMP stack. At home I'm running Ruby / Mac OS X / MySQL, which seems to have plenty of quirks as well. In the financial services sector, Sybase & Solaris are very common place, and Ruby / RoR will need to better support this platform if it's going to see much adaption.

I have the Sybase's OpenClient library built for my platform, without which, this wouldn't be possible. Here's what I've learned so far.

First, I had to track down a library. This was a bit confusing because I've read reports on how Ruby on Rails now supports Sybase. It seems that neither Ruby 1.8.4 (2005-12-24) or Rails has built in support for Sybase. What Ruby needs is a freetds version which has no external dependecies. My route requires the C library from Sybase. Here's the library:

wget http://enjoy1.bb-east.ne.jp/~tetsu/sybct-ruby-0.2.8.tar.gz

The good thing is the file came with an English README file. This was a big help. Unfortunately, the extconf.rb wasn't setup to auto-configure itself. It requires hand editing depending on the platform. This might be because mkmf wasn't as advanced as when this was first written. Here are the changes I had to make:

6c6,7
< sybase = "/opt/sybase-12.5"
---
> # sybase = "/opt/sybase-12.5"
> sybase = "/usr/local/sybase-12.5.1"
21c22
< # $LOCAL_LIBS = "-Xlinker -Bstatic -lct -lcs -ltcl -lcomn -lintl -ltli -Xlinker -Bdynamic -lnsl"
---
> $LOCAL_LIBS = "-Xlinker -Bstatic -lct -lcs -ltcl -lcomn -lintl -Xlinker -Bdynamic -lnsl"
41c42
< $LOCAL_LIBS = "-lct -lcs -lsybtcl -lcomn -lintl -rdynamic -ldl -lnsl -lm"
---
> # $LOCAL_LIBS = "-lct -lcs -lsybtcl -lcomn -lintl -rdynamic -ldl -lnsl -lm"
52c53,57
< 
---
> if PLATFORM =~ /solaris/
> then
>   have_library("nls", "gethostbyname")
>   have_library("socket","gethostbyaddr")
> end

The first change is because my C libraries aren't installed in the usual location. It would be nice to be able to specify this with a --with-sybase-dir option. Next I had to select the correct LOCAL_LIBS for my platform. I don't have a tli module, so I removed that one from the linker. Things seems to work ok with out. Interestingly, I have this module for Sparc but not for Intel Solaris. Lastly, I had to tell it to find and include the socket library. Fortunately, I've ran into this before when working on tibcorv. Additionally, gcc 3.3.2 wasn't working for me. So I switched to use gcc 4.1, which seemed to work better.

After this, I was able to create the Makefile, run make, and then test things out with the included isql program.

$ ruby -I . ./sample/isql.rb -S TEST_NY

!! MAX ROWCOUNT 2000 !!

1-> select user
2-> go
<- select user
restype =ROW_RESULT
     
-----
guest

(row count = 1, tran state = 'completed')

I did a make install, but that only installed the .so, and not the require .rb files. An additional cp sybct.rb sybsql.rb /u/eggebr/pkgs/sunos-5.10-i86pc/lib/ruby/site_ruby/1.8/ was needed before I was able to use the library from a Rails script.

In the end, I almost gave up and was going to try using JRuby instead, which would have fixed the database issues, at the cost of introducing plenty of other complexity.