Monday, 19 September 2011

ruby fetch_hash ArgumentError: NULL pointer given


Recently, One of our servers started to have the following error
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
=> true
irb(main):003:0> conn = Mysql.connect('db01', 'xxxxxx', 'xxxxxx', 'employee')
=> #
irb(main):004:0> a = conn.query("SELECT * FROM employees WHERE id >= 8500 AND id < 9000")
=> #
irb(main):005:0> a.fetch_hash
ArgumentError: NULL pointer given
	from (irb):5:in `fetch_hash'
	from (irb):5
irb(main):006:0> exit
The method fetch_hash is a standard method and works. Here is the versions of MySQL and ruby that I used
-bash-3.2$ mysql --version
mysql  Ver 14.12 Distrib 5.0.89, for unknown-linux-gnu (x86_64) using readline 5.1

-bash-3.2$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
If you face this issue in your servers or anywhere try the following workaround. They have worked for me, and they should work for you as well.
  1. uninstall the MySQL-shared-compat package
  2. Re Install mysql gem

No comments:

Post a Comment