Activerecord issue - all_hashes error

Hi All,

I’m trying to run a simple Activerecord query (I’m still learning) but
I’m running into a brick wall on the following error:

e[4;36;1mProduct Load (0.0ms)e[0m e[0;1mSELECT * FROM products
LIMIT 1e[0m
(eval):3:in each_hash': NULL pointer given (ArgumentError) from (eval):3:inall_hashes’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/mysql_adapter.rb:605:in
select' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:7:inselect_all_without_query_cache’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in
select_all' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:661:infind_by_sql’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in
find_every' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1505:infind_initial’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:613:in
`find’
from C:/Documents and Settings/XYZ/My
Documents/NetBeansProjects/XYZ/vendor/plugins/testing.rb:32

The code that generates this error is as follows:


require ‘mysql’
require ‘activerecord’

enable activerecord logging

ActiveRecord::Base.logger = Logger.new(STDERR)

ActiveRecord connection

ActiveRecord::Base.establish_connection(
:adapter => “mysql”,
:host => “localhost”,
:username => “root”,
:password => “pw”,
:database => “etd”
)

old-school mysql connection

my = Mysql::real_connect(“127.0.0.1”, “root”, “pw”, “etd”)

create table and insert data

my.query “CREATE TABLE products (
id int(11) NOT NULL auto_increment,
name varchar(255),
PRIMARY KEY (id))”

my.query “INSERT INTO products VALUES(‘1’,‘brick’)”

ActiveRecord class

class Product < ActiveRecord::Base
end

Activerecord query

product_row = Product.find(:first)

Output result

puts product_row.name


Note that I’ve included the create and insert statements for the
convenience of anyone who may want to test this. Once the table and data
are there you can remove these statements and the error still occurs.

Other platform/version details as follows:
Box: Win32 (WinXP)
Activerecord ver: 2.3.4
IDE: Netbeans 6.7.1
Mysql gem ver: 2.8.1

Any help or suggestions on how to fix this would be greatly appreciated.

Regards,

Andre

If anyone is interested, I found a solution to this problem.

See here:
http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407

Looks like MySQL 5.1 client library doesn’t play well with Rails.

Andre

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs