aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-13 10:03:03 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-13 10:03:03 +0000
commit680e4742bec472b649d1260b764fcd0e3ad115b7 (patch)
treeecb7caa58ae02987a9450ae1417b3c2df6c87215 /activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
parent44b64704dd542f114ac1cfab682a9ef30c384e82 (diff)
downloadrails-680e4742bec472b649d1260b764fcd0e3ad115b7.tar.gz
rails-680e4742bec472b649d1260b764fcd0e3ad115b7.tar.bz2
rails-680e4742bec472b649d1260b764fcd0e3ad115b7.zip
r3042@asus: jeremy | 2005-11-13 01:51:08 -0800
MySQL active? and reconnect! References #428. r3043@asus: jeremy | 2005-11-13 01:58:28 -0800 SQLite active? and reconnect! References #428. r3044@asus: jeremy | 2005-11-13 02:02:27 -0800 Update CHANGELOG with admonishment regarding avoidance of the log method. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3001 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.rb37
1 files changed, 22 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 ca410c4add..d58590677b 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -136,6 +136,25 @@ module ActiveRecord
end
+ # CONNECTION MANAGEMENT ====================================
+
+ def active?
+ @connection.stat if @connection.respond_to?(:stat)
+ true
+ rescue Mysql::Error
+ false
+ end
+
+ def reconnect!
+ if @connection.respond_to?(:ping)
+ @connection.ping
+ else
+ @connection.close rescue nil
+ @connection.real_connect(*@connection_options)
+ end
+ end
+
+
# DATABASE STATEMENTS ======================================
def select_all(sql, name = nil) #:nodoc:
@@ -148,22 +167,10 @@ module ActiveRecord
end
def execute(sql, name = nil, retries = 2) #:nodoc:
- unless @logger
- @connection.query(sql)
- else
- log(sql, name) { @connection.query(sql) }
- end
+ log(sql, name) { @connection.query(sql) }
rescue ActiveRecord::StatementInvalid => exception
- if LOST_CONNECTION_ERROR_MESSAGES.any? { |msg| exception.message.split(":").first =~ /^#{msg}/ }
- @connection.real_connect(*@connection_options)
- unless @logger
- @connection.query(sql)
- else
- @logger.info "Retrying invalid statement with reopened connection"
- log(sql, name) { @connection.query(sql) }
- end
- elsif exception.message.split(":").first =~ /Packets out of order/
- raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem update mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information."
+ if exception.message.split(":").first =~ /Packets out of order/
+ raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
else
raise
end