Repository is archived
No commit activity in last 3 years
No release in over 3 years
Adds support for limit and offset for Sybase ASE DB to activerecord-jdbc-adapter for Rails 3
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0.7
~> 2.0.10
~> 1.0.15
~> 1.6.2
>= 0
~> 2.2.2

Runtime

 Project Readme

* No longer supported *¶ ↑

Finally we moved away from Sybase DB. Therefore this driver is not supported any longer. Please feel free to take ownership of this project

ar-sybase-jdbc-adapter¶ ↑

ar-sybase-jdbc-adapter enhances activerecord-jdbc-adapter (Rails 3) to support .limit and offset for Sybase ASE DB.

At the moment Sybase ASE version 15 or grater is required. If you need it work for ASE version 12, please open an Issue

This project is a proof of concept that Sybase ASE can work nicely with Rails. Once the project reaches “close to production” functionality I will try to merge it with activerecord-jdbc-adapter

If you have any issues with the adapter please add an Issue or fork the project and send a pull request.

Usage¶ ↑

  1. Install

gem install ar-sybase-jdbc-adapter
  1. Configuration

To use this gem, set the “dialect” configuration parameter to “sybase_jtds”. Example:

development:
  adapter: jdbc
  username: user_name
  password: password
  database: your_database
  dialect: sybase_jtds
  driver: net.sourceforge.jtds.jdbc.Driver
  url: jdbc:jtds:sybase://host:port/db_name

Implementation notes¶ ↑

If .limit with no .offset or .count methods is used, the adapter simply adds “TOP” keyword to SQL and sends it to the Sybase server:

User.limit(10)

produces:

SELECT TOP 10 users.* FROM users

The adapter has to rely on Java code to implement .offset or when .count is used together with .offset or .limit. In this case adapter will generate SQL like it was MySQL query:

User.limit(10).offset(20)

produces

SELECT  users.* FROM users LIMIT 10 OFFSET 21

This can be confusing if you are looking at the log file.

Java layer parses the SQL and executes it as multistep scrollable cursor query:

declare crsr  insensitive scroll cursor for
    select * from <original query>
go
open crsr

set cursor rows <limit> for crsr
fetch absolute <offset> from crsr

close crsr
deallocate crsr

Unfortunately this approach is not very efficient for very large OFFSET values. Also scrollable cursor works for Sybase ASE starting from version 15.

I am not a Sybase expert, so Please let me know if you are aware of more efficient ways to do limit and offset.

Known issues¶ ↑

I am aware of a very strange issue where the adapter does not work when the very first query uses “limit()”.

e.g.

$ rails c
Loading development environment (Rails 3.0.3)
irb(main):001:0> Client.limit(10).to_sql
=> "SELECT clients.* FROM clients LIMIT 10"

Otherwise, the adapter works fine by adding the “TOP” keyword to your SQL query:

e.g.

$ rails c
Loading development environment (Rails 3.0.3)
irb(main):001:0> Client.scoped.to_sql
=> "SELECT clients.* FROM clients"
irb(main):002:0> Client.limit(10).to_sql
=> "SELECT TOP 10 clients.* FROM clients"

Contributing to ar-sybase-jdbc-adapter¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 arkadiy kraportov. See LICENSE.txt for further details.