This project is archived and is in readonly mode.
#count on decimal column returns BigDecimal
-
Jarrett Meyer
Verified on Ubuntu + sqlite3
ruby-1.9.2-p0 > c = Person.count(:salary)
=> #<BigDecimal:1a30a38,'0.1E1',9(18)> -
Thomas van der Pol
I could not replicate this problem with Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136
Steps:
1) Create new rails app (with sqlite3 as the db adapter - default)
2) generate model with decimal column
3) in rails console, create a few entries
4) TestModel.count(:decimal_column) returned an integer count, not a BigDecimalAs such, I did not try the patch. If this only happens on specific versions of rails, let me know and I'll test on them, as well.
-
Josh Kalderimis
- Importance changed from to Low
Hey qertoip,
Is this a DB specific issue? or were the sqlite tests also failing with your test case?
Josh
-
Thomas van der Pol
As per Josh K's request, I checked the same setup as above in Postgres. (Postgres 9.0.3 on aforementioned platform: Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136)
The outcome is the same:
Salary.count(:amount).class => Fixnum
Where Salary.amount is a decimal column in the migration, a 'numeric' type in the database itself (default behaviour).
Cheers,
Thomas -
Josh Kalderimis
- State changed from new to needs-more-info
- Tag changed from patch to active_record
- Assigned user set to Josh Kalderimis
Hey qertoip and Jarrett,
I am marking this issue as need-more-info until more information is supplied on how to replicate the issue.
Thanks,
Josh
-
Jarrett Meyer
It looks like a different patch was applied to fix a similar problem that also fixed this problem - see ticket 6103.
If I'm reading the git history correctly, this was fixed on Jan 10, 2011. The unit test in my patch file now passes. (Although there is no such unit test currently in 3.0.4.)
-
Josh Kalderimis
Hi Jarrett,
Thanks for looking into this, can you please create a new patch which only includes a test to make sure this does not break in the future. I will then get José or Santiago to look into it further.
Thanks
Josh
-
Jarrett Meyer
Added patch file with just the unit test.
-
karle durante
We use Rails w/ Oracle and have also started seeing that Model.count returns BigDecimal, as opposed to Integer.
Seems this was introduced with Rails 2.3.8 and persists in 2.3.11.
-
Josh Kalderimis
@Karle: As this is not a security issue it will not be applied to 2.3.x branch.
@Jarrett: I just wanted to check, have you confirmed if this is an issue on 3-0-stable and master, or just 3.0.4?
Thanks
Josh
