<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>drivers/derby/lib/derby-10.5.3.0.jar</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,6 +6,8 @@
   same thing as recreate_database)
 - Sqlite3 and MSSQL fixes (Jean-Dominique Morani)
 - JRUBY-3512: Treat LONGVARCHAR as a CLOB for Mssql
+- JRUBY-3624: Upgrade Derby to 10.5.3.0 and add native limit/offset
+  support (Christopher Saunders)
 
 == 0.9.1
 </diff>
      <filename>History.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 module Jdbc
   module Derby
-    VERSION = &quot;10.4.2.0&quot;
+    VERSION = &quot;10.5.3.0&quot;
   end
 end
 </diff>
      <filename>drivers/derby/lib/jdbc/derby.rb</filename>
    </modified>
    <modified>
      <diff>@@ -400,6 +400,16 @@ module ::JdbcSpec
       '0'
     end
 
+    def add_limit_offset!(sql, options) #:nodoc:
+      if options[:offset]
+        sql &lt;&lt; &quot; OFFSET #{options[:offset]} ROWS&quot;
+      end
+      if options[:limit]
+        #ROWS/ROW and FIRST/NEXT mean the same
+        sql &lt;&lt; &quot; FETCH FIRST #{options[:limit]} ROWS ONLY&quot;
+      end
+    end
+
     private
     # Derby appears to define schemas using the username
     def derby_schema</diff>
      <filename>lib/jdbc_adapter/jdbc_derby.rb</filename>
    </modified>
    <modified>
      <diff>@@ -274,55 +274,20 @@ public class JdbcDerbySpec {
         }
     }
 
-    @JRubyMethod(name = &quot;add_limit_offset!&quot;, required = 2)
-    public static IRubyObject add_limit_offset(IRubyObject recv, IRubyObject sql, IRubyObject options) {
-        IRubyObject limit = rubyApi.callMethod(options, &quot;[]&quot;, recv.getRuntime().newSymbol(&quot;limit&quot;));
-        rubyApi.setInstanceVariable(recv, &quot;@limit&quot;,limit);
-        IRubyObject offset = rubyApi.callMethod(options, &quot;[]&quot;, recv.getRuntime().newSymbol(&quot;offset&quot;));
-        return rubyApi.setInstanceVariable(recv, &quot;@offset&quot;,offset);
-    }
-
     @JRubyMethod(name = &quot;_execute&quot;, required = 1, optional = 1)
     public static IRubyObject _execute(ThreadContext context, IRubyObject recv, IRubyObject[] args) throws SQLException, java.io.IOException {
         Ruby runtime = recv.getRuntime();
-        try {
-            // TODO: Ouch....this looks fragile
-            RubyJdbcConnection conn = (RubyJdbcConnection) rubyApi.getInstanceVariable(recv, &quot;@connection&quot;);
-            String sql = args[0].toString().trim().toLowerCase();
-            if (sql.charAt(0) == '(') {
-                sql = sql.substring(1).trim();
-            }
-            if (sql.startsWith(&quot;insert&quot;)) {
-                return conn.execute_insert(context, args[0]);
-            } else if (sql.startsWith(&quot;select&quot;) || sql.startsWith(&quot;show&quot;)) {
-                IRubyObject offset = rubyApi.getInstanceVariable(recv, &quot;@offset&quot;);
-                if(offset == null || offset.isNil()) {
-                    offset = RubyFixnum.zero(runtime);
-                }
-                IRubyObject limit = rubyApi.getInstanceVariable(recv, &quot;@limit&quot;);
-                IRubyObject range;
-                IRubyObject max;
-                if (limit == null || limit.isNil() || RubyNumeric.fix2int(limit) == -1) {
-                    range = RubyRange.newRange(runtime, context, offset, runtime.newFixnum(-1), false);
-                    max = RubyFixnum.zero(runtime);
-                } else {
-                    IRubyObject v1 = rubyApi.callMethod(offset, &quot;+&quot;, limit);
-                    range = RubyRange.newRange(runtime, context, offset, v1, true);
-                    max = rubyApi.callMethod(v1, &quot;+&quot;, RubyFixnum.one(runtime));
-                }
-                IRubyObject result = conn.execute_query(context, args[0], max);
-                IRubyObject ret = rubyApi.callMethod(result, &quot;[]&quot;, range);
-                if (ret.isNil()) {
-                    return runtime.newArray();
-                } else {
-                    return ret;
-                }
-            } else {
-                return conn.execute_update(context, args[0]);
-            }
-        } finally {
-            rubyApi.setInstanceVariable(recv, &quot;@limit&quot;, runtime.getNil());
-            rubyApi.setInstanceVariable(recv, &quot;@offset&quot;, runtime.getNil());
+        RubyJdbcConnection conn = (RubyJdbcConnection) rubyApi.getInstanceVariable(recv, &quot;@connection&quot;);
+        String sql = args[0].toString().trim().toLowerCase();
+        if (sql.charAt(0) == '(') {
+            sql = sql.substring(1).trim();
+        }
+        if (sql.startsWith(&quot;insert&quot;)) {
+            return conn.execute_insert(context, args[0]);
+        } else if (sql.startsWith(&quot;select&quot;) || sql.startsWith(&quot;show&quot;)) {
+            return conn.execute_query(context, args[0]);
+        } else {
+            return conn.execute_update(context, args[0]);
         }
     }
 }</diff>
      <filename>src/java/jdbc_adapter/JdbcDerbySpec.java</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>drivers/derby/lib/derby-10.4.2.0.jar</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>6a2f433ce9599d7f23e0f6ceee9835fbef912547</id>
    </parent>
  </parents>
  <author>
    <name>Nick Sieger</name>
    <email>nick@nicksieger.com</email>
  </author>
  <url>http://github.com/nicksieger/activerecord-jdbc-adapter/commit/7c5895c39c8cd280306eb7a30ff26855e125075a</url>
  <id>7c5895c39c8cd280306eb7a30ff26855e125075a</id>
  <committed-date>2009-09-23T19:29:19-07:00</committed-date>
  <authored-date>2009-09-23T19:29:19-07:00</authored-date>
  <message>JRUBY-3624: Upgrade Derby to 10.5.3.0 and add native limit/offset support (Christopher Saunders)</message>
  <tree>6a2a64a4d4d9a19d21844727b4b21d46eb4f377a</tree>
  <committer>
    <name>Nick Sieger</name>
    <email>nick@nicksieger.com</email>
  </committer>
</commit>
