Thursday, 26 June 2008

Sybase on jruby on rails

It goes without saying that most of what I do is on Sybase. I was looking to build a POC for a data maintenance app a few weeks ago and I decided to try and do it with rails. I quietly realised the only option for using rails in my company would be jruby on rails deployed to tomcat; that is from their point of view it would be a java app.

So I updated my jruby environment to the latest (1.12 at the time of writing) and activerecord-jdbc-adapter to 0.81. As luck would have it some preliminary Sybase code had just been included in this release.

It didn't seem to work, however so I did some investigation. It was clashing with the MS-SQL driver (both can use the jtds driver, and it seems no one had considered the idea of one driver talking to different databases before). This started my interaction with the jruby community. People were extremely helpful and immediately made a change to how the database config worked to add a 'dialect' keyword so we could now use both sybase and MS-SQL with the jtds driver !

I was pretty pumped by now, so I set up the required files for running the simple unit tests, create a test sybase database (15.02 on XP) and started testing. Here is what I went though:

First run - 100% failure
Solution - the primary key definition was gibberish from sybase's point of view. By looking at what the MS-SQL driver did I was able to work out what was needed, added an overriding method and re-tested.

Second run - 70% Success !
This motivated me a lot so I addressed the next issues (drop index syntax) by adding another method and retested.

3rd Run - 99% success !
I was basically there. The last issue required no ruby code changes - just setting 'select into/bulk copy' on for the test database.

4th run - 100% success !
Ok, well there were lots more than 4 runs due to typos, database issues,etc. but only 4 that were relevant to getting the driver passing all the tests.

I have submitted a patch (article title links to the Jira ticket) and hopefully this will make it into an upcoming release. Is you don't want to wait, you should be able to apply the patch to activerecord-jdbc-adapter 0.82.

Not that I never have actually gotten to the rails app yet.. Hopefully soon. Now back to my day job :-(

No comments: