Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3739: md.diff

File md.diff, 1.5 kB (added by anonymous, 3 years ago)
  • activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    old new  
    3333      end 
    3434 
    3535      mysql = Mysql.init 
     36      mysql.reconnect = 1 
    3637      mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey] 
    3738      ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config) 
    3839    end 
     
    177178      end 
    178179 
    179180      def execute(sql, name = nil, retries = 2) #:nodoc: 
     181        repeat = 1 
    180182        log(sql, name) { @connection.query(sql) } 
    181183      rescue ActiveRecord::StatementInvalid => exception 
    182         if exception.message.split(":").first =~ /Packets out of order/ 
     184        if repeat && LOST_CONNECTION_ERROR_MESSAGES.include?(exception.message.split(": ").at(1)) 
     185          reconnect! 
     186          --repeat 
     187          retry  
     188        elsif exception.message.split(":").first =~ /Packets out of order/ 
    183189          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." 
    184190        else 
    185191          raise