BigDecimal still does not behave 100% correctly, My relevant model fragment looks like this: t.column :lat, :decimal, :precision => 20, :scale => 15, :null => false t.column :lng, :decimal, :precision => 20, :scale => 15, :null => false The controller calls a finder find_by_lat_and_lng(@lat, @lng) which produces a log line: SELECT * FROM geo_locations WHERE (geo_locations.`lng` ''-70.85366249084473'' AND geo_locations.`lat` = ''42.66684871528651'') LIMIT 1 This select returns nothing if ran manually but there is a record in the table corresponding to the lng and lat criteria. If I remove quites around lat and lng values then it works and returns one record (as it should be), like this: SELECT * FROM geo_locations WHERE (geo_locations.`lng` -70.85366249084473 AND geo_locations.`lat` = 42.66684871528651) LIMIT 1 Is there a way to tell rails to send decimal values without quites (I''m assuming that quoted values are treated as strings and that''s why they don''t match). Any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When the finder parameters converted to float like this find_by_lat_and_lng(@lat.to_f, @lng.to_f) then it does send the parameters into the query non quoted. The problem is that the float does not have enough precision (at least not in my case) and the finder still does not return the value. When the decimal values are used in the finder like this find_by_lat_and_lng(BigDecimal.new(@lat), BigDecimal.new(@lng)) the query does quote the parameters. So, my question is: shouldn''t BigDecimal behave similar to Float in this regard, after all they both numbers. Seems like a bug to me. If anyone has any advise how to deal with this situation, would be highly appreciated. thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The question is if LongDecimal (gem-name: long-decimal) would not be the better match for database fields than BigDecimal, which is more or less a Float with the capability to have more digits. Best regards, Karl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Karl Brodowsky wrote:> The question is if LongDecimal (gem-name: long-decimal) would not be the > better match for database fields than > BigDecimal, which is more or less a Float with the capability to have > more digits. > > Best regards, > > KarlKarl, thank you for you reply, the precision is not really a problem for me -- the BigDecimal fits my needs just fine. The problem is in active record that does not handle numbers other then Floats correctly when constructing select queries -- it puts the parameters in quotes which it should not do. I''m afraid that LongDecimal would not be any different in this regard for active record (correct me if I''m wrong) thus switching to it would not really help me much, thank you, let me know if you have any other suggestions... Dmitry -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---