Class: ActiveRecord::ConnectionAdapters::MysqlAdapter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- Defined in:
- lib/mysql_retry_lost_connection.rb
Instance Method Summary collapse
-
#execute(sql, name = nil) ⇒ Object
:nodoc:.
Instance Method Details
#execute(sql, name = nil) ⇒ Object
:nodoc:
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mysql_retry_lost_connection.rb', line 4 def execute(sql, name = nil) #:nodoc: reconnect_lost_connections = true begin log(sql, name) { @connection.query(sql) } rescue ActiveRecord::StatementInvalid => exception RAILS_DEFAULT_LOGGER.info("ActiveRecord::StatementInvalid Error: #{exception.}\n#{exception.backtrace.join("\n")}") if reconnect_lost_connections and exception. =~ /(Lost connection to MySQL server during query|MySQL server has gone away)/ reconnect_lost_connections = false reconnect! retry elsif exception..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 end end |