ruby与rails版本差异不能连接mysql

由于ruby与rails版本差异,可能会出现在使用低版本的rails时,出现不能连接mysql的情况。

现象:

ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/vendor/mysql.rb:566:in initialize: wrong number of arguments (1 for 0) (ArgumentError)

解决方法

def scramble41(password, message)
    return 0x00.chr if password.nil? or password.empty?
    buf = [0x14]
    #s1 = Digest::SHA1.new(password).digest
    s1 = Digest::SHA1.new
    s1 << password
    s1 = s1.digest
    #s2 = Digest::SHA1.new(s1).digest
    s2 = Digest::SHA1.new << s1
    s2 = s2.digest
    #x = Digest::SHA1.new(message + s2).digest
    x = Digest::SHA1.new << (message + s2)
    x = x.digest
    (0..s1.length - 1).each {|i| buf.push(s1[i] ^ x[i])}
    buf.pack("C*")
  end