rails-sqlserver/activerecord-sqlserver-adapter — Issue #142: NoMethodError: undefined method `use_utc=' 
Author: tomlobato
Created: 2011-11-11 03:31:32+00:00
State: open

Hi all,
I got below error when accessing mssql2005 from ubuntu (10.10) / rails (3.1.1) / activerecord-sqlserver-adapter (3.1.3):

----------------------------------------------------------------
root@graficos:~/graf2# rails c
Loading development environment (Rails 3.1.1)
irb(main):001:0> Servico.count
Ruby ODBC v0.99992 or higher is required.
ActiveRecord::StatementInvalid: NoMethodError: undefined method `use_utc=' for #: EXEC sp_executesql N'SELECT @@version'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:359:in `handle_to_names_and_values_odbc'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:344:in `handle_to_names_and_values'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:313:in `raw_select'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `log'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:310:in `raw_select'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:293:in `do_exec_query'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:22:in `exec_query'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/database_statements.rb:242:in `select'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_one'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:30:in `select_value'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver_adapter.rb:199:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.1.3/lib/active_record/connection_adapters/sqlserver/schema_statements.rb:276:in `info_schema_query'
... 13 levels...
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:92
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:712:in `call'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:712:in `default'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:712:in `[]'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:712:in `columns'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:728:in `column_names'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/relation/calculations.rb:192:in `aggregate_column'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/relation/calculations.rb:213:in `execute_simple_calculation'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/relation/calculations.rb:187:in `perform_calculation'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/relation/calculations.rb:155:in `calculate'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/relation/calculations.rb:58:in `count'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:445:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:445:in `count'
----------------------------------------------------------------

After commenting these lines, .count, .last, .first (tested until now) started to work:

428 on:
connection_adapters/sqlserver_adapter.rb: #c.use_utc = ActiveRecord::Base.default_timezone == :utc

359 on:
connection_adapters/sqlserver/database_statements.rb: #@connection.use_utc = ActiveRecord::Base.default_timezone == :utc

It appears that ODBC::Database in sqlserver/core_ext/odbc.rb is lacking use_utc. I`ll follow using and testing to see if all work fine after commenting these lines. I`m not sure if it is a bug or compatibility issue.
If you have any suggestion for solve, please tell me.