Mysql 4.x and Rails : RELEASE SAVEPOINT issue


Today with a project using mysql 4.1.22 that I have to implement some tests, I ran this error with rails 2.3.5 and I think for 2.3.x branch.

Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘RELEASE SAVEPOINT active_record_1′ at line 1: RELEASE SAVEPOINT active_record_1

RELEASE SAVEPOINT is for Mysql 5.x

It is also described here http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/be0bece7cdf052fa?fwc=1

I get it resolved when digging into the activerecord code :
ActiveRecord::ConnectionAdapters::AbstractAdapter defines release_savepoint method.

To get around with this, just add the belowing patch after Rails was loaded (at the bottom of your config/environment.rb for instance)

# As of mysql 4.x does not support "RELEASE SAVEPOINT" statement
if ActiveRecord::Base.connection.instance_variable_get("@connection").get_server_info < '5.0'
  ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
    # Unset release savepoint method 
    def release_savepoint
    end
  end
end

Hope that this can help !

  1. No comments yet.
(will not be published)