Class: ActiveRecord::ConnectionAdapters::MysqlAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_mysql_auto_reconnect_patch.rb

Instance Method Summary collapse

Instance Method Details

#execute(sql, name = nil) ⇒ Object

:nodoc:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ar_mysql_auto_reconnect_patch.rb', line 18

def execute(sql, name = nil) #:nodoc:
  reconnect_lost_connections = true
  begin
    log(sql, name) { @connection.query(sql) }
  rescue ActiveRecord::StatementInvalid => exception
    if reconnect_lost_connections and exception.message =~ /(Lost connection to MySQL server during query
|MySQL server has gone away)/
      reconnect_lost_connections = false
      reconnect!
      retry
    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 install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hash
ing.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