georgiev / rubyfb

ruby/rails Firebird db access library
Other
16 stars 5 forks source link

Problem with rails 3.2.1 + ruby 1.9.2 #7

Closed vitamino closed 12 years ago

vitamino commented 12 years ago

Hi, I have troubles connecting to a fb db.

My setup:

OSX 10.6.8 ruby 1.9.2 (via RVM) rails 3.2.1 rubyfb 0.6.2

Configuration:

# database.yml
firebird:
  adapter: rubyfb
  database: d:\database\mydatabase.gdb
  username: sysdba
  password: xxxxxxxxxx
  host: 123.456.789.000

When I try to connect in rails console I get this error:

ruby-1.9.2-p290 :001 > ActiveRecord::Base.establish_connection(:firebird)
LoadError: Please install the rubyfb adapter: `gem install activerecord-rubyfb-adapter` (no such file to load -- active_support/core_ext/kernel/requires)
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/rubyfb-0.6/lib/active_record/connection_adapters/rubyfb_adapter.rb:4:in `<top (required)>'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
    from (irb):1
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.2-p290 :002 > 

Any help please?

Best regards, Daniele

georgiev commented 12 years ago

First things first - a big FAT WARNING - the OSX support is fairly untested! (although I think it should work) As of this error - something is wrong with your ruby/gem installation - this is activerecord error - the framework does not see rubyfb gem. All that I can suggest is to try a clean (re)install (ruby, rails, rubyfb)

vitamino commented 12 years ago

Hi Georgiev, thank you for the reply. As you can see from this line:

from /Users/xx/.rvm/gems/ruby-1.9.2-p290@test/gems/rubyfb-0.6/lib/active_record/connection_adapters/rubyfb_adapter.rb:4:in `<top (required)>'

the Rubyfb code is run, so the gem is loaded.

I found a similar compatibility problem for another project, it seems something related with activesupport 3.1.0 compatibility. The strange point is that with ruby 1.x + rails 3.1 + activesupport 3.1 the connection object is created but the connection itself give an error (see my other issue), so the problem seems related with rails 3.1

I already reinstalled the whole stack (via RVM), the problem persist.

georgiev commented 12 years ago

Note that the code is run from xxx/rubyfb-0.6/xxx while I would expect to be run from xxx/rubyfb-0.6.2/xxx

vitamino commented 12 years ago

You are right, my fault. I did some test with the older version too and used that output, but the problem is exactly the same with v. 0.6.2

vitamino commented 12 years ago

Ehm... why did you close the issue? :)

georgiev commented 12 years ago

^%$^%#^*&%^%$ - My bad - (those two buttons keep killing me) - reopening

georgiev commented 12 years ago

Ok - it looks like rubyfb_adapter.rb:4 requires a deprecated core extension that is not used any more - can you try to remove that line and see what happens?

vitamino commented 12 years ago

I spent so many hours on this tests that at the end I have not tried the obvious thing! Removing the line the connection object is created.

Now when I setup an activerecord class to access the DB:

class Item < ActiveRecord::Base
  set_table_name "old_items"
end

I get the same error I pointed out in my other issue:

dyld: lazy symbol binding failed: Symbol not found: _isc_attach_database
georgiev commented 12 years ago

Now we'r down to the OSX specifics - I have a very broad idea about the nature of the problem - the rubyfb bundle is failing to resolve the Firebird client library and I have absolutely no idea why. I'll have to do some research, and I hope that you can help with the testing - I don't have OSX.

vitamino commented 12 years ago

Of course, let me know how I can help you

georgiev commented 12 years ago

32 or 64 bit Firebird ?

vitamino commented 12 years ago

I suppose 32bit, this are the server info:

Server Version Info
---------------------------------------------------------------------------
Server Version: WI-V1.5.4.4910 Firebird 1.5
Server Implementation: Firebird/x86/Windows NT
Service Version: 2
georgiev commented 12 years ago

In your Activity Monitor turn on the Kind column, and check the values corresponding to the firebird server process AND your ruby interpreter (just run your server - dont try to use it)

vitamino commented 12 years ago

Please note that Firebird is on Windows server (and it is 32 bit). Locally I have 64 bit ruby.

georgiev commented 12 years ago

Do you have Firebird client library installed on the ruby machine ?

vitamino commented 12 years ago

Locally I have installed the full Firebird 1.5 package so I should have the client.

By the way I tried to connect to the local server too and get the same error. Firebird 1.5 is available only at 32bit. So now I'm going to test locally the 2.5 (64bit) version...

georgiev commented 12 years ago

Rubyfb uses the native Firebird client library so You MUST use same architecture for ruby and Firebird client library to get it working

vitamino commented 12 years ago

I removed the 1.5 package and installed the 2.5-64bit. Same problem. How can I see which client library rubyfb try to use?

georgiev commented 12 years ago

What is the output of otool -L /Users/xx/.rvm/gems/ruby-1.9.2-p290/gems/rubyfb-0.6.2/lib/rubyfb_lib.bundle

vitamino commented 12 years ago
$ otool -L /Users/xx/.rvm/gems/ruby-1.9.2-p290/gems/rubyfb-0.6.2/lib/rubyfb_lib.bundle
/Users/xx/.rvm/gems/ruby-1.9.2-p290/gems/rubyfb-0.6.2/lib/rubyfb_lib.bundle:
    /Users/xx/.rvm/rubies/ruby-1.9.2-p290/lib/libruby.1.9.1.dylib (compatibility version 1.9.1, current version 1.9.1)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
vitamino commented 12 years ago

Georgiev good news! After installing the 64bit version I deleted and recreated the gemset (= recompiled the native extension) and now the connection works! Actually I did some experiments symlinking the library to some locations so I don't know if this helped, I will investigate.

With Rails 3.1 all works perfectly while with Rails 3.2.1 the object fields are mapped ok but fetching records give me this error, that is related to activerecord 3.2.1:

ruby-1.9.2-p290 :002 > class Item < ActiveRecord::Base; set_table_name "items"; end
   (2.5ms)  select first 1 cast(1 as smallint) from rdb$database
  items Columns (4.4ms)   SELECT r.rdb$field_name, r.rdb$field_source, f.rdb$field_type, f.rdb$field_sub_type,
 COALESCE(f.rdb$character_length, f.rdb$field_length) as rdb$field_length, f.rdb$field_precision, f.rdb$field_scale,
 COALESCE(r.rdb$default_source, f.rdb$default_source) as rdb$default_source,
 COALESCE(r.rdb$null_flag, f.rdb$null_flag) as rdb$null_flag
 FROM rdb$relation_fields r
 JOIN rdb$fields f ON r.rdb$field_source = f.rdb$field_name
 WHERE r.rdb$relation_name = 'ITEMS'
 ORDER BY r.rdb$field_position

   (3.1ms)  SELECT rdb$relation_name FROM rdb$relations WHERE rdb$system_flag = 0
   (2.9ms)   SELECT i.rdb$index_name, i.rdb$unique_flag, s.rdb$field_name
 FROM rdb$indices i
 JOIN rdb$index_segments s ON i.rdb$index_name = s.rdb$index_name
 LEFT JOIN rdb$relation_constraints c ON i.rdb$index_name = c.rdb$index_name
 WHERE i.rdb$relation_name = 'ITEMS'
AND c.rdb$constraint_type = 'PRIMARY KEY'
ORDER BY i.rdb$index_name, s.rdb$field_position

(Object doesn't support #inspect)
 =>  
ruby-1.9.2-p290 :005 >   Item
 => Item(name: string)
ruby-1.9.2-p290 :003 > Item.first
NoMethodError: undefined method `accept' for nil:NilClass
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_all'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/querying.rb:38:in `block in find_by_sql'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/explain.rb:40:in `logging_query_plan'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/querying.rb:37:in `find_by_sql'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/relation.rb:170:in `exec_queries'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/relation.rb:159:in `block in to_a'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/explain.rb:33:in `logging_query_plan'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/relation.rb:158:in `to_a'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:377:in `find_first'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:122:in `first'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/activerecord-3.2.1/lib/active_record/querying.rb:5:in `first'
    from (irb):3
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
    from /Users/xx/.rvm/gems/ruby-1.9.2-p290@xxxxxxx/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.2-p290 :004 > 
vitamino commented 12 years ago

Problem solved! I will submit a patch ASAP.

georgiev commented 12 years ago

'NoMethodError: undefined method `accept' for nil:NilClass' error is now fixed in master

vitamino commented 12 years ago

Perfect, same patch ;)

Thank you very much for the great support! Issue closed :)

georgiev commented 12 years ago

By the end of the week I will release 0.6.3 with fixes for both of your issues. I'm glad that I have a confirmed case of working rubyfb on OSX :)

vitamino commented 12 years ago

One more thing I discover during the testing: Rails 3.2 in dev execute automatically the explain() method when a query takes longer than 0.5 secs, so you have to add this method (real or dummy) to the RubyfbAR31Adapter class.