Active record doesn't seem to see jdbc adapter


#1

I have a problem that I can’t quite get to the bottom of. I have a DB
that cannot handle the LIMIT clause on the SQL generated in Rails. No
worries because I already have a modified rb file that should handle
it. In fact it has worked in earlier versions of Rails and JRuby.

I did a fresh install of JRuby 1.2.0 and installed rails (2.3.2) and
active record jdbc (0.9.1). I have a sample app that I ran it against
and got an immediate error that the driver couldn’t be found, so copied
the jar to the jruby/lib folder and the error disappeared. However, it
was replaced by the following:

ActiveRecord::ActiveRecordError: [SQL0104] Token LIMIT was not valid.
Valid tokens: FOR SKIP WITH FETCH OPTIMIZE.

I have an adapter named jdbc_db2i5OS.rb that is currently in the
E:\jruby-1.2.0\lib\ruby\gems\1.8\gems\activerecord-jdbc-adapter-0.9.1\lib\jdbc_adapter
folder and I have entry in the
E:\jruby-1.2.0\lib\ruby\gems\1.8\gems\activerecord-jdbc-adapter-0.9.1\lib\active_record\connection_adapters\jdbc_adapter_spec.rb
for the adapter.

The modification to handle the limit clause is:

def add_limit_offset!(sql, options)
  # The DB2 code doesn't work on the AS/400, because the outer

SELECT doesn’t
# preserve row_number() from the inner SELECT. We have to put the
ORDER BY
# in the OVER clause.
if limit = options[:limit]
offset = options[:offset] || 0

    if sql =~ /(\sorder\s+by\s.*)/i
      order_by_clause = $1
    else
      order_by_clause = ""
    end

    # Qualify a lone * with the table name, so we can precede it

with row_number()
table_name = sql.match(/\sfrom\s+(.?)\s/i)[1]
if table_name =~ /.(.
)/
table_name = $1
end
sql.sub!(/SELECT\s+*\s/i, "SELECT #{table_name}.* ")

    sql.sub!(/SELECT/i, "SELECT A.* FROM (" +
        "SELECT row_number() over (#{order_by_clause}) as

internal$rownum, ")
sql << ") A WHERE internal$rownum > #{offset} " +
"AND internal$rownum <= #{limit + offset} " +
“ORDER BY internal$rownum”
end
end

[The complete code is here:
http://petesworkshop.com/downloads/jdbc_db2i5OS.rb]

Can you see why the code isn’t executed? I have tweaked this a bit so
perhaps you can see something I cannot see. It has to be something
simple and probably due to the changes in environment, but I sure can’t
seem to figure out what is missing.

Thanks,

Pete


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#2

I believe this is due to a change in 0.9.1 for how we select adapters.
Previously:

module JdbcSpec::MySQL
def self.adapter_selector
[/mysql/i, lambda {|cfg,adapt| adapt.extend(::JdbcSpec::MySQL)}]
end
end

Now:

module JdbcSpec::MySQL
def self.adapter_matcher(name, *)
name =~ /mysql/i ? self : false
end
end

You probably just need to update your custom DB2 adapter and add a
adapter_matcher method.

/Nick

On Thu, Mar 19, 2009 at 1:22 PM, Pete H. removed_email_address@domain.invalid wrote:

  else

")
perhaps you can see something I cannot see. It has to be something simple
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#3

Yep. That was it!

Thanks Nick.

Pete

Nick S. wrote:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email