tmtm / ruby-mysql

MySQL connector for Ruby. pure Ruby version.
MIT License
143 stars 34 forks source link

Mysql#errno and ActiveRecord #1

Closed julian7 closed 14 years ago

julian7 commented 14 years ago

I tried to use ruby-mysql with ActiveRecord (not the new version, but it seems the last one suffers from the same problem), and I got an error about Nil class doesn't respond to zero?.

The calling code in question looks like this:

def active?
  ...
  if @connection.respond_to?(:errno)
    @connection.errno.zero?
  else
    true
  end
end

Therefore, I suggest changing Mysql#errno to this: def errno @last_error && @last_error.errno || 0 end

tmtm commented 14 years ago

Thank you. I fixed it. http://github.com/tmtm/ruby-mysql/commit/59b76daede4872338183dadd19ff1e432b828dd5