Skip to content
Browse files

updated for Arel 2.0.7, activerecord-jdbc-adapter 1.1.1

  • Loading branch information...
1 parent 7ce8731 commit 184cbd3dad80b3921fc6ecf3b1a4b2dea2cba567 @arkadiyk committed Jan 17, 2011
Showing with 40 additions and 27 deletions.
  1. +2 −2 Gemfile
  2. +6 −6 Gemfile.lock
  3. +10 −6 README.rdoc
  4. +3 −3 Rakefile
  5. +1 −1 lib/arel/visitors/sybase_jtds.rb
  6. +5 −0 lib/arjdbc/sybase_jtds.rb
  7. +13 −9 src/java/arjdbc/sybase/SybaseRubyJdbcConnection.java
View
4 Gemfile
@@ -10,7 +10,7 @@ group :development do
gem "jeweler", "~> 1.5.1"
gem "rcov", ">= 0"
gem "minitest"
- gem "arel", "> 2.0.0"
- gem "activerecord-jdbc-adapter", ">= 1.1.0"
+ gem "arel", "2.0.7"
+ gem "activerecord-jdbc-adapter", "1.1.1"
gem "activerecord", ">= 3.0.3"
end
View
12 Gemfile.lock
@@ -10,30 +10,30 @@ GEM
activesupport (= 3.0.3)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
- activerecord-jdbc-adapter (1.1.0)
+ activerecord-jdbc-adapter (1.1.1)
activesupport (3.0.3)
- arel (2.0.6)
+ arel (2.0.7)
builder (2.1.2)
git (1.2.5)
i18n (0.5.0)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
- minitest (2.0.1)
+ minitest (2.0.2)
rake (0.8.7)
rcov (0.9.9)
rcov (0.9.9-java)
- tzinfo (0.3.23)
+ tzinfo (0.3.24)
PLATFORMS
java
ruby
DEPENDENCIES
activerecord (>= 3.0.3)
- activerecord-jdbc-adapter (>= 1.1.0)
- arel (> 2.0.0)
+ activerecord-jdbc-adapter (= 1.1.1)
+ arel (= 2.0.7)
bundler (~> 1.0.0)
jeweler (~> 1.5.1)
minitest
View
16 README.rdoc
@@ -1,15 +1,20 @@
= ar-sybase-jdbc-adapter
-ar-sybase-jdbc-adapter enhances the Arel 2 activerecord-jdbc-adapter to support "limit" and "offset" for Sybase ASE DB.
+ar-sybase-jdbc-adapter enhances activerecord-jdbc-adapter (Rails 3) to support "limit" and "offset" for Sybase ASE DB.
**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
-Once the project reaches "close to production" functionality I will try to merge it with _activerecord-jdbc-adapter_
+== Usage
+1. Install
+ gem install ar-sybase-jdbc-adapter
+
+2. Configuration
To use this gem, set the "dialect" configuration parameter to "sybase_jtds".
+Example:
-e.g.
development:
adapter: jdbc
username: user_name
@@ -19,6 +24,7 @@ e.g.
driver: net.sourceforge.jtds.jdbc.Driver
url: jdbc:jtds:sybase://host:port/db_name
+
== Offset in Sybase ASE
Sybase is an awful DB in term of support for "offset". I found 2 ways to do it for generic queries:
@@ -77,8 +83,6 @@ fall back to `cursor` and get `@@rowcount` to get the number of rows.
-
-
== Known issues
I am aware of a very strange issue where the driver does not work when the very first query uses "limit()".
@@ -112,6 +116,6 @@ e.g.
== Copyright
-Copyright (c) 2010 arkadiy kraportov. See LICENSE.txt for
+Copyright (c) 2011 arkadiy kraportov. See LICENSE.txt for
further details.
View
6 Rakefile
@@ -15,16 +15,16 @@ Jeweler::Tasks.new do |gem|
gem.name = "ar-sybase-jdbc-adapter"
gem.homepage = "http://github.com/arkadiyk/ar-sybase-jdbc-adapter"
gem.license = "MIT"
- gem.summary = %Q{Adds support for limit and offset for Sybase JDBC driver }
+ gem.summary = %Q{Adds support for limit and offset for Rails 3 and Sybase JDBC driver }
gem.description = %Q{Adds support for limit and offset for Sybase ASE DB to activerecord-jdbc-adapter for Rails 3}
gem.email = "arkadiyk@gmail.com"
gem.authors = ["arkadiy kraportov"]
gem.files = FileList['lib/**/*.rb', 'lib/**/*.jar']
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
- gem.add_runtime_dependency 'activerecord-jdbc-adapter', '>= 1.1.0'
+ gem.add_runtime_dependency 'activerecord-jdbc-adapter', '>= 1.1.1'
# gem.add_runtime_dependency 'activerecord', '>= 3.0.3'
- gem.add_runtime_dependency 'arel', '>= 2.0.6'
+ gem.add_runtime_dependency 'arel', '>= 2.0.7'
gem.add_runtime_dependency 'jdbc-jtds'
gem.add_development_dependency 'minitest', '>= 2.0.0'
end
View
2 lib/arel/visitors/sybase_jtds.rb
@@ -14,7 +14,7 @@ def visit_Arel_Nodes_SelectStatement o
o.offset.expr += 1 if o.offset
sql = super # if offset OR (limit & count) use the Java limit/offset/count parser
else
- limit = o.limit
+ limit = o.limit.expr
o.limit = nil
sql = super
View
5 lib/arjdbc/sybase_jtds.rb
@@ -14,5 +14,10 @@ def self.jdbc_connection_class
def self.column_selector
[/sybase/i, lambda {|cfg,col| col.extend(::ArJdbc::MsSQL::Column)}]
end
+
+ def supports_migrations?
+ false
+ end
+
end
end
View
22 src/java/arjdbc/sybase/SybaseRubyJdbcConnection.java
@@ -23,12 +23,9 @@
package arjdbc.sybase;
import arjdbc.jdbc.RubyJdbcConnection;
-import arjdbc.jdbc.SQLBlock;
import org.jruby.Ruby;
import org.jruby.RubyClass;
-import org.jruby.RubyString;
import org.jruby.runtime.ObjectAllocator;
-import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import java.sql.*;
@@ -100,6 +97,13 @@ protected boolean genericExecute(Statement stmt, String query) throws SQLExcepti
private boolean executeQueryWithOffset(Statement stmt, String query, String limit, String offset, String count)
throws SQLException {
+ try {
+ stmt.execute("close crsr\ndeallocate crsr");
+ } catch (SQLException e) {
+ // could not find a better place to stick this in :(
+ // Maybe cursorOpen flag to ThreadLocal ?
+ }
+
stmt.execute("declare crsr insensitive scroll cursor for " + query);
if(limit != null) {
@@ -121,11 +125,11 @@ private boolean executeQueryWithOffset(Statement stmt, String query, String limi
return result;
-// stmt.execute("close crsr\n deallocate crsr");
-// return result;
-
}
+ private static Pattern COUNT_PATTERN = Pattern.compile("\\sCOUNT\\s*\\(.+\\)", Pattern.CASE_INSENSITIVE);
+ private static Pattern LIMIT_PATTERN = Pattern.compile("\\sLIMIT\\s+(\\d+)", Pattern.CASE_INSENSITIVE);
+ private static Pattern OFFSET_PATTERN = Pattern.compile("\\sOFFSET\\s+(\\d+)", Pattern.CASE_INSENSITIVE);
/**
* Parses MySQL formatted query
* ex. if param is "SELECT COUNT(*) FROM table LIMIT 10 OFFSET 50",
@@ -136,19 +140,19 @@ private boolean executeQueryWithOffset(Statement stmt, String query, String limi
*/
private static Map<String, String> extractLimitOffsetAndCount(String queryString){
Map<String,String> parsedQuery = new HashMap<String,String>();
- Matcher countMatcher = Pattern.compile("\\sCOUNT\\s*\\(.+\\)", Pattern.CASE_INSENSITIVE).matcher(queryString);
+ Matcher countMatcher = COUNT_PATTERN.matcher(queryString);
if(countMatcher.find()) {
parsedQuery.put("count","Y");
queryString = countMatcher.replaceAll(" 'F' as f ");
}
- Matcher limitMatcher = Pattern.compile("\\sLIMIT\\s+(\\d+)", Pattern.CASE_INSENSITIVE).matcher(queryString);
+ Matcher limitMatcher = LIMIT_PATTERN.matcher(queryString);
if(limitMatcher.find()) {
parsedQuery.put("limit",limitMatcher.group(1));
queryString = limitMatcher.replaceAll("");
}
- Matcher offsetMatcher = Pattern.compile("\\sOFFSET\\s+(\\d+)", Pattern.CASE_INSENSITIVE).matcher(queryString);
+ Matcher offsetMatcher = OFFSET_PATTERN.matcher(queryString);
if(offsetMatcher.find()) {
parsedQuery.put("offset",offsetMatcher.group(1));
queryString = offsetMatcher.replaceAll("");

0 comments on commit 184cbd3

Please sign in to comment.
Something went wrong with that request. Please try again.