rails-sqlserver / tiny_tds

TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Other
607 stars 189 forks source link

NoMethodError: undefined method `[]' for nil:NilClass with not-so-long queries #80

Closed linuxonrails closed 12 years ago

linuxonrails commented 12 years ago

When I execute not-too-long queries (with ids) i have strange errors:

NoMethodError: undefined method `[]' for nil:NilClass

The sql-query has no problem. I only can fix with minor ids (short query). Does'nt matter ids values.

ruby-1.9.2-p290 :039 > Lote.find_all_by_Id_Lote(@solr_ids)
  Lote Load (812.6ms)  EXEC sp_executesql N'SELECT [Lotes].* FROM [Lotes] WHERE [Lotes].[Id_Lote] IN (21451225, 22148639, 22148640, 22148649, 22445971, 22898404, 23208739, 23349359, 27230814, 21596758, 7636981, 7637281, 7637355, 7637385, 29143081, 4537325, 25319890, 22955426, 13616958, 13616962, 13250442, 25110734, 26029717, 13722551, 17261642, 26687000, 26687007, 29892995, 700485, 26667557, 26667555, 26123564, 26203029, 21204430, 28116947, 27498294, 5169364, 6165798, 6168540, 6168655, 6174970, 6778435, 6778506, 6787079, 7176027, 8395749, 30967998, 26550702, 26985715, 29810452)'
NoMethodError: undefined method `[]' for nil:NilClass
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-sqlserver-adapter-3.2.1/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb:26:in `unprepare_sqlserver_statement'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-sqlserver-adapter-3.2.1/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb:11:in `block in exec_explain'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-sqlserver-adapter-3.2.1/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb:11:in `map'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-sqlserver-adapter-3.2.1/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb:11:in `exec_explain'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-3.2.2/lib/active_record/explain.rb:34:in `logging_query_plan'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-3.2.2/lib/active_record/relation.rb:159:in `to_a'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:159:in `all'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:263:in `find_by_attributes'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/activerecord-3.2.2/lib/active_record/dynamic_matchers.rb:45:in `method_missing'
    from (irb):39
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
    from /home/davidm/.rvm/gems/ruby-1.9.2-p290@mobile/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

With only 9 param-ids (!!!) I cannot make left join with other tables :-( but I can with 5-6 params.

    @lotes = Lote.includes(:seccion, :user).where('Id_Lote IN (?)', @solr_ids)

bundle list

Using tiny_tds (0.5.1) 
Using activerecord (3.2.2) 
Using activerecord-sqlserver-adapter (3.2.1) 
ii  freetds-bin                                                 0.82-7
ii  freetds-common                                       0.82-7
ii  freetds-dev                                                0.82-7
ii  libdbd-freetds                                           0.8.3-1-0ubuntu5

Rails 3.2.2

metaskills commented 12 years ago

This looks like an issue with the SQL Server Adapter, not TinyTDS. In fact, it looks like a bug with out explain handler, which you could confirm by disabling in one of a few ways (http://guides.rubyonrails.org/active_record_querying.html#automatic-explain)

Either way, closing this as it is certainly does not look like a TinyTDS issue.