Hello. I have a table like this : id : primary key (numeric(9,0) identity for me) name : string value : string rank : integer Now I insert this record : name = "dummy" val = "12345" rank = 34 I can insert, update and delete it. If I want to search based on value, I would like to use the so-easy-and-cute find_all_by_val method as in : find_all_by_val("12345") But this gives me a SQL request invalid : SELECT * FROM dummy_table WHERE val = 12345 Numbers in string are quoted as integer If I change quote method, I could have SELECT * FROM dummy_table WHERE val = "12345" But now, I have the same problem with rank : find_all_by_rank("12345") gives me SELECT * FROM dummy_table WHERE rank = "12345" Is there a magic implementation of the quote method in the adapter that could deal with integer and string in the right way ? Tony PS : I''m using a Sybase ASE server. I can''t put number between quotes like in MySQL requests. -- 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 -~----------~----~----~----~------~----~------~--~---
Anybody has the same problem ? It''s a pitty to have find(id.to_i) rather than just find(id) ... -- 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 -~----------~----~----~----~------~----~------~--~---
eize.sus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-21 09:33 UTC
Re: AR: quoting integer in string : how to fix ?
Tony wrote:> Hello. > > I have a table like this : > > id : primary key (numeric(9,0) identity for me) > name : string > value : string > rank : integer > > Now I insert this record : > name = "dummy" > val = "12345" > rank = 34 > > I can insert, update and delete it. > > If I want to search based on value, I would like to use the > so-easy-and-cute > find_all_by_val method as in : > > find_all_by_val("12345") > > But this gives me a SQL request invalid : > SELECT * FROM dummy_table WHERE val = 12345 > > Numbers in string are quoted as integer > If I change quote method, I could have > SELECT * FROM dummy_table WHERE val = "12345" > > But now, I have the same problem with rank : > > find_all_by_rank("12345") > > gives me SELECT * FROM dummy_table WHERE rank = "12345" > > Is there a magic implementation of the quote method in the adapter that > could deal with integer and string in the right way ? > > Tony > > PS : I''m using a Sybase ASE server. I can''t put number between quotes > like in MySQL requests. > > -- > Posted via http://www.ruby-forum.com/.Hi Tony, Try using find(:all, :conditions => "rank = ?", intString) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
eize.sus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Try using find(:all, :conditions => "rank = ?", intString)Hi Eize ! Thanks for comming ;) What is intString ? You mean a string containing an integer like "1234" ? If this is what you mean, it does not work either. The find_all_by_rank generate the same find(:all,...) that you write. For insert or update, rails use a hash with the fields names and types, and pass to the quote method the value and the type of the field. But for select, the field type is not searched. So quote is called only with the value ... And I could not guess when to return integer and when to return string. From now, I change all my find method having integer with a call to String.to_i and my Adapter always return quoted string. Not really easy to use at all. Tony -- 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 -~----------~----~----~----~------~----~------~--~---