aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-22 23:55:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-22 23:55:04 +0000
commite8f664dde0364c84ff31537cc0b5b89683fbbca8 (patch)
tree45c240319dae228ab6359e604cb6a03f7652770f /activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
parentd958f22ecc47f34aced7f5619be483d9686a26f0 (diff)
downloadrails-e8f664dde0364c84ff31537cc0b5b89683fbbca8.tar.gz
rails-e8f664dde0364c84ff31537cc0b5b89683fbbca8.tar.bz2
rails-e8f664dde0364c84ff31537cc0b5b89683fbbca8.zip
MySQL, PostgreSQL: reconnect! also reconfigures the connection. Otherwise, the connection 'loses' its settings if it times out and is reconnected. Closes #2978.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3165 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb34
1 files changed, 19 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 177d201259..76ea6e6530 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -38,17 +38,7 @@ module ActiveRecord
mysql = Mysql.init
mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey]
- if config[:encoding]
- begin
- mysql.options(Mysql::SET_CHARSET_NAME, config[:encoding])
- rescue
- raise ActiveRecord::ConnectionFailed, 'The :encoding option is only available for MySQL 4.1 and later with the mysql-ruby driver. Again, this does not work with the ruby-mysql driver or MySQL < 4.1.'
- end
- end
-
- conn = mysql.real_connect(host, username, password, database, port, socket)
- conn.query("SET NAMES '#{config[:encoding]}'") if config[:encoding]
- ConnectionAdapters::MysqlAdapter.new(conn, logger, [host, username, password, database, port, socket], mysql)
+ ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config)
end
end
@@ -97,10 +87,11 @@ module ActiveRecord
"MySQL server has gone away"
]
- def initialize(connection, logger, connection_options=nil, mysql=Mysql)
+ def initialize(connection, logger, connection_options=nil, config={})
super(connection, logger)
@connection_options = connection_options
- @mysql = mysql
+ @config = config
+ connect
end
def adapter_name #:nodoc:
@@ -144,7 +135,7 @@ module ActiveRecord
end
def quote_string(string) #:nodoc:
- @mysql.quote(string)
+ @connection.quote(string)
end
def quoted_true
@@ -170,7 +161,7 @@ module ActiveRecord
@connection.ping
else
@connection.close rescue nil
- @connection.real_connect(*@connection_options)
+ connect
end
end
@@ -318,6 +309,19 @@ module ActiveRecord
private
+ def connect
+ encoding = @config[:encoding]
+ if encoding
+ begin
+ @connection.options(Mysql::SET_CHARSET_NAME, encoding)
+ rescue
+ raise ActiveRecord::ConnectionFailed, 'The :encoding option is only available for MySQL 4.1 and later with the mysql-ruby driver. Again, this does not work with the ruby-mysql driver or MySQL < 4.1.'
+ end
+ end
+ @connection.real_connect(*@connection_options)
+ execute("SET NAMES '#{encoding}'") if encoding
+ end
+
def select(sql, name = nil)
@connection.query_with_result = true
result = execute(sql, name)