The only way to get around it is to override the configure_connection function in ActiveRecord. To do this I would recommend making an ApplicationController function named skip_sql? to test whether you want to skip the configure_connection function for some controller#action combinations:
class ApplicationController
def skip_sql?
params[:controller] == "..." && params[:action] == "..."
end
end
Then make this function available to your classes and models:
module SkipSql
module Controller
def self.included(base)
base.prepend_before_filter :assign_skip_sql_to_models
end
def assign_skip_sql_to_models
ActiveRecord::Base.skip_sql_proc = proc {send(:skip_sql?)}
end
end
module Model
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
attr_accessor :skip_sql_proc
def skip_sql?
ActiveRecord::Base.skip_sql_proc.call if ActiveRecord::Base.skip_sql_proc
end
end
def skip_sql?
self.class.skip_sql?
end
end
end
Object.send :include, SkipSql::Model::ClassMethods
ActionController::Base.class_eval {include SkipSql::Controller}
Then skip sql only on the controller#action combinations you have set:
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def configure_connection
unless skip_sql?
encoding = @config[:encoding]
execute("SET NAMES '#{encoding}'", :skip_logging) if encoding
execute("SET SQL_AUTO_IS_NULL=0", :skip_logging)
end
end
end
If the configure_connection one doesn't work I would try the connect method like this:
class ActiveRecord::ConnectionAdapters::MysqlAdapter
alias :old_connect :connect
def connect
old_connect unless skip_sql?
end
alias :old_active? :active?
def active?
skip_sql? ? false : old_active?
end
end
I believe the connect method gets called before the configure connection method, so it should help with the socket issue.