jruby/activerecord-jdbc-adapter — pull request #566 by omarqazi (2014-07-21 09:38:55+00:00)
Title: Set column class correctly when using MySQL adapter

I'm not very familiar with this project or codebase, so apologies in advance if I'm missing something, but this pull request solved a bug that had me pulling my hair out for days.

I have a simple jruby script that uses Arel to build queries. I noticed that building a query with a date worked fine with the mysql2 and PostgresJDBC adapters, but threw an exception when using Mysql JDBC.

ActiveRecord::Base.establish_connection(connection)
t = Arel::Table.new("crimes")
t.engine = ActiveRecord::Base
q = t.project("*").where t[:updated_at].lt(Time.now)
q.to_sql # => throws exception

After digging in a little bit I noticed this commit on May 28 by @kares: https://github.com/jruby/activerecord-jdbc-adapter/commit/b33460f2437d8f6fb70df35050e6651530c9c301

In the commit the column class was switched from being hardcoded to using the jdbc_column_class method. I think the author may have seen the method later down the page, but it's actually not in the same scope as the place it's called from and as a result columns are initialized using the generic JDBC column class rather than the MySQL column class. Then, the program throws an exception because the arguments being passed in to initialize the MySQL column class don't work with the generic JDBC class.

Interested to hear what you guys think about this. I'm using a forked version of this repo in my project now and it's working well now that this change has been applied.