Forum: Ruby on Rails Problem using ActiveRecord on Windows

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shane C. (Guest)
on 2009-05-04 22:40
Problem
---------
ActiveRecord appears to be failing on my Windows install

Setup
---------
I have MySql version 5.0.51 running on a debian box, let's call it (A)
I have Ruby w/ the ActiveRecord gem installed on an ubuntu box, let's
call it (B)
I have Ruby w/ the ActiveRecord and mysql gems installed on a Windows
box, let's call it (C)

Scenario
---------
I have a simple table named 'Software' in a database named 'master' on
(A).

I have written a dirt simple script to show me all of the records in the
'Software' table.

Here it is:
<code>
require 'rubygems'
require 'activerecord'
require 'pp'

class Software < ActiveRecord::Base
  set_table_name "Product"  # Not "Softwares"
end

ActiveRecord::Base.establish_connection(
  :host => "deb",
  :adapter => "mysql",
  :database => "master",
  :username => "username",  # this is not my real username
  :password => "password",  # this is not my real password
  :autocommit => true
)

pp Software.find(:all)
</code>

(B) executes properly without any problems, however (C) fails to execute
with the following dump...

<code>
(eval):3:in `each_hash': NULL pointer given (ArgumentError)
  from (eval):3:in `all_hashes'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:596:in
`select'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all_without_query_cache'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/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.2/lib/active_record/base.rb:661:in
`find_by_sql'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in
`find_every'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:615:in
`find'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1905:in
`find_all_by_Product_Name'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1890:in
`send'
  from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1890:in
`method_missing'
  from simpleConnectMySql.rb:24     -- this is my simple script
</code>

Any help would be greatly appreciated.  Like I said I'm new to this
ActiveRecord stuff, so it could be a very simple problem.  I'm just
confused because it works perfectly on my ubuntu machine (B).

Thanks guys!
E. Litwin (Guest)
on 2009-05-04 23:01
(Received via mailing list)
What is the primary key in the Product table? Is it 'id' or something
else?

On May 4, 11:40 am, Shane C. <removed_email_address@domain.invalid>
Shane C. (Guest)
on 2009-05-04 23:49
E. Litwin wrote:
> What is the primary key in the Product table? Is it 'id' or something
> else?
>
> On May 4, 11:40�am, Shane C. <removed_email_address@domain.invalid>

It's actually 'Software ID', but I tried defining my class as follows
with the same results:

class Software < ActiveRecord::Base
  set_table_name "Product"  # Not "Softwares"
  set_primary_key "Software ID"
end
This topic is locked and can not be replied to.