From 20ef2e5e27acc69a827ca66dce0d906863e052d1 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Fri, 23 Jul 2010 23:43:02 -0700 Subject: [PATCH] cleanup connection handling in AR adapter, this should finally resolve GH#31 --- .../connection_adapters/mysql2_adapter.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/active_record/connection_adapters/mysql2_adapter.rb b/lib/active_record/connection_adapters/mysql2_adapter.rb index 334905a..d227ce8 100644 --- a/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -238,7 +238,8 @@ module ActiveRecord end def reconnect! - reset! + disconnect! + connect end def disconnect! @@ -250,7 +251,12 @@ module ActiveRecord def reset! disconnect! - @connection = Mysql2::Client.new(@config) + connect + end + + # this is set to true in 2.3, but we don't want it to be + def requires_reloading? + false end # DATABASE STATEMENTS ====================================== @@ -263,7 +269,6 @@ module ActiveRecord select(sql, name).map { |row| row.values } end - # Executes a SQL query and returns a Mysql2::Result object. Note that you have to free the Result object after you're done using it. def execute(sql, name = nil) if name == :skip_logging @connection.query(sql) @@ -547,7 +552,6 @@ module ActiveRecord end end - # TODO: implement error_number method on Mysql2::Exception def translate_exception(exception, message) return super unless exception.respond_to?(:error_number) @@ -563,7 +567,8 @@ module ActiveRecord private def connect - # no-op + @connection = Mysql2::Client.new(@config) + configure_connection end def configure_connection