rowland/fb

Using gem 'fb' with Rails 3.2.12 in production mode

mahasamatman opened this issue · 3 comments

Hi!
In my Rails 3.2.12 application i need to connect to Firebird server located in local network from server with application.
The next code works well in development mode

require 'fb'
include Fb
db = Database.new(
  :database => Rails.configuration.firebird_url,
  :username => Rails.configuration.firebird_username,
  :password => Rails.configuration.firebird_password,
  :encoding => 'cp1251')

conn = db.connect rescue db.create.connect

client = conn.query(:hash, 'select * from "SomeTable" where "ID"= ?', id)

But returns nothing (query returns nothing) in production mode.
It also works well in rails console both in production and development.
Maybe some part of Rails refuses connection or data returned by query.
Please, help me to figure out this problem.

Does your Rails application us activerecord-fb-adapter? Are there appropriate entries in database.yml for each profile (development and production)? If so, then you should be able to access the connection using ActiveRecord::Base.connection.raw_connection, rather than coding your own.

Please define "nothing" in the context of your query returning nothing. The method will raise an exception or return an array of hashes, possibly an empty array if your query returns an empty set.

I did not use activerecord-fb-adapter, because Firebird isn't primary database for application, just get some data from FBDB. And think that i don't need install adapter for just few queries. Connection is established as shown up here (directly in the controller). And all of the the queries returns nil values in production without exceptions (exactly nil). Checked it just now.
And as i noticed, in development queries returns values as it should be - an arrays of hashes. Its just strange for me.

So i think i have try to install the adapter, rewrite my code and see what would happen

Your reason for not using the adapter is sound. At this point, I would not suggest rewriting your code.

I suspect an exception is being swallowed somewhere. Try removing the "rescue db.create.connect" after the db.connect. That's something that's mainly useful for test scripts. Your production database shouldn't need to be initialized at this point and it makes little sense to create the database and immediately query from a table which hasn't been created, much less populated.

Since it works in development mode and the fb driver is unaware of such distinctions, I suspect something about the connection parameters is incorrect.