jeremyevans / sequel

Sequel: The Database Toolkit for Ruby
http://sequel.jeremyevans.net
Other
4.99k stars 1.07k forks source link

NoMethodError (undefined method `new' for BigDecimal:Class) #1675

Closed jrgns closed 4 years ago

jrgns commented 4 years ago

Complete Description of Issue

When retrieving a decimal value from a table, it throws NoMethodError (undefined methodnew' for BigDecimal:Class)`

The field is defined as a decimal(10, 4)

Simplest Possible Self-Contained Example Showing the Bug

2.7.0 :014 > DB[:mytable].where(id: 2).select(:amount).first
Traceback (most recent call last):
       16: from /home/jrgns/myproject/Rakefile:67:in `block (3 levels) in <top (required)>'
       15: from (irb):13
       14: from (irb):14:in `rescue in irb_binding'
       13: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:208:in `first'
       12: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:693:in `single_record'
       11: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:705:in `single_record!'
       10: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:950:in `with_sql_first'
        9: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:942:in `with_sql_each'
        8: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/adapters/tinytds.rb:214:in `fetch_rows'
        7: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/dataset/actions.rb:1089:in `execute'
        6: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/adapters/tinytds.rb:46:in `execute'
        5: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/database/connecting.rb:270:in `synchronize'
        4: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/connection_pool/sharded_threaded.rb:130:in `hold'
        3: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/adapters/tinytds.rb:77:in `block in execute'
        2: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/adapters/tinytds.rb:238:in `block in fetch_rows'
        1: from /home/jrgns/myproject/vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/adapters/tinytds.rb:238:in `each'
NoMethodError (undefined method `new' for BigDecimal:Class)

Casting it to a string returns the value (as a string)

2.7.0 :015 > DB[:mytable].where(id: 2).select(Sequel.cast(:amount, String)).first
 => {:untitled=>"346.95"}

Ruby 2.7 Sequel 5.29.0 MSSQL 2014

jeremyevans commented 4 years ago

This error isn't in Sequel, it's in tiny_tds. See https://github.com/rails-sqlserver/tiny_tds/issues/409. Try using tiny_tds 2.1.2.