Hi Britt, welcome to the list This sounds strange. I did a test once with SQL server and did not encounter this problem. Admittedly, the tests were not intensive, but I think I was able to use the find method correctly. victor Britt Selvitelle wrote:> Hey guys and gals, > > This is my first message to the list, as I just started kicking around > with Ruby and RoR development, so ... hey :) > > We''re (unfortunately) using MS SQLServer at work, so I''ve been working > with that a lot recently. Under the abstract_adapter.rb, numeric > datatypes are defined as floats. The problem this causes is RoR renders > all numeric types then as 123.0 ... even if they have no scale defined > (a scale of 0 essentially denotes an integer representation). > > This is of course a problem with an ID is of numeric type, because to > RoR 123 !== 123.0, so it cannot find a record when doing something like > /my_controller/show/123.0 > > As a temporary solution I''ve patched sqlserver_adapter to represent > numerics as integer types. > I guess 2 things should possibly be fixed: > > (1) When rendering floats, if there is no value past the decimal, it > should not render the .0 (can this be specified somewhere in code already?) > > (2) Logically when computing IDs 123 should == 123.0 > > Thoughts? > > Britt > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Britt Selvitelle wrote:> We''re (unfortunately) using MS SQLServer at work, so I''ve been working > with that a lot recently. Under the abstract_adapter.rb, numeric > datatypes are defined as floats. The problem this causes is RoR renders > all numeric types then as 123.0 ... even if they have no scale defined > (a scale of 0 essentially denotes an integer representation). > > As a temporary solution I''ve patched sqlserver_adapter to represent > numerics as integer types. > I guess 2 things should possibly be fixed: > (1) When rendering floats, if there is no value past the decimal, it > should not render the .0 (can this be specified somewhere in code already?) > (2) Logically when computing IDs 123 should == 123.0 > Thoughts?Apparently MSSQL is an excellent RDBMS, maybe you aren''t so bad off :) The adapter should map 0-scale numeric columns to Integer and the rest to Float. Then you don''t need equality and rendering hacks. I assume this column info may be queried. In general, I''d like to see *all* the adapters map numeric columns to BigDecimal rather than Float. SQL Numeric and Ruby BigDecimal let you specify how many significant digits you want, avoiding round-off hell. Spare a penny? http://www.ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/ jeremy
Jeremy Kemper wrote:>Britt Selvitelle wrote: > > >>We''re (unfortunately) using MS SQLServer at work, so I''ve been working >>with that a lot recently. Under the abstract_adapter.rb, numeric >>datatypes are defined as floats. The problem this causes is RoR renders >>all numeric types then as 123.0 ... even if they have no scale defined >>(a scale of 0 essentially denotes an integer representation). >> >>As a temporary solution I''ve patched sqlserver_adapter to represent >>numerics as integer types. >>I guess 2 things should possibly be fixed: >>(1) When rendering floats, if there is no value past the decimal, it >>should not render the .0 (can this be specified somewhere in code already?) >>(2) Logically when computing IDs 123 should == 123.0 >>Thoughts? >> >> > >Apparently MSSQL is an excellent RDBMS, maybe you aren''t so bad off :) > >There are pros and cons, but I won''t go there :)>The adapter should map 0-scale numeric columns to Integer and the rest >to Float. Then you don''t need equality and rendering hacks. I assume >this column info may be queried. > >I''m not sure how to detect the scale in the adapter though. Also, regardless don''t you think 123 should equal 123.0 in RoR''s eyes? (The rendering fix should probably be left asis, and will be corrected by the equality fix).>In general, I''d like to see *all* the adapters map numeric columns to >BigDecimal rather than Float. SQL Numeric and Ruby BigDecimal let you >specify how many significant digits you want, avoiding round-off hell. >Spare a penny? > > http://www.ruby-doc.org/stdlib/libdoc/bigdecimal/rdoc/ > >Just to see how it worked, I implemented this real quick, and using the same method as the fix above, RoR will need to interpret BigDecimal types like 0.253E1. I''d be happy to implement this. Where are ID equality comparisons done in the Rails source? Britt
Hey guys and gals, This is my first message to the list, as I just started kicking around with Ruby and RoR development, so ... hey :) We''re (unfortunately) using MS SQLServer at work, so I''ve been working with that a lot recently. Under the abstract_adapter.rb, numeric datatypes are defined as floats. The problem this causes is RoR renders all numeric types then as 123.0 ... even if they have no scale defined (a scale of 0 essentially denotes an integer representation). This is of course a problem with an ID is of numeric type, because to RoR 123 !== 123.0, so it cannot find a record when doing something like /my_controller/show/123.0 As a temporary solution I''ve patched sqlserver_adapter to represent numerics as integer types. I guess 2 things should possibly be fixed: (1) When rendering floats, if there is no value past the decimal, it should not render the .0 (can this be specified somewhere in code already?) (2) Logically when computing IDs 123 should == 123.0 Thoughts? Britt