I''m working against a legacy (which means I can''t change the table or move to MySQL ;]) table in a SQL Server database that has column names with embedded spaces in them (see error messages below). When I go to delete one of these records I get messages like the ones below for every column with any embedded spaces. A quick googling reveals that these may just be warnings? Is that everyone else''s experience or will the presence of these columns actually cause problems when I do DB operations on these type of tables? Thanks, Wes ================ Exception occured during reader method compilation. Maybe Date Code 3 is not a valid Ruby identifier? (eval):1:in `evaluate_read_method'': compile error (eval):1: formal argument cannot be a constant def Date Code 3; raise NoMethodError, ''missing attribute: Date Code 3'', caller unless @attributes.has_key?(''Date Code 3''); @attributes[''Date Code 3'']; end ^ (eval):1: parse error, unexpected tINTEGER, expecting ''\n'' or '';'' def Date Code 3; raise NoMethodError, ''missing attribute: Date Code 3'', caller unless @attributes.has_key?(''Date Code 3''); @attributes[''Date Code 3'']; end ^ (eval):1: parse error, unexpected kEND, expecting $ def Date Code 3; raise NoMethodError, ''missing attribute: Date Code 3'', caller unless @attributes.has_key?(''Date Code 3''); @attributes[''Date Code 3'']; end ^ Exception occured during reader method compilation. Maybe Date Code 3 is not a valid Ruby identifier? (eval):1:in `evaluate_read_method'': compile error (eval):1: formal argument cannot be a constant def Date Code 3?; query_attribute(''Date Code 3''); end ^ (eval):1: parse error, unexpected tINTEGER, expecting ''\n'' or '';'' def Date Code 3?; query_attribute(''Date Code 3''); end ^ (eval):1: parse error, unexpected kEND, expecting $ def Date Code 3?; query_attribute(''Date Code 3''); end -- 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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Dec-06 16:40 UTC
Re: AR/SQLServer: Legacy column names with embedded spaces
This doesn''t appear to actually interfere with any DB operations, but I''d still like to hear about any adverse effects encountered in the field. WG -- 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 -~----------~----~----~----~------~----~------~--~---
On 06/12/06, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m working against a legacy (which means I can''t change the table or > move to MySQL ;]) table in a SQL Server database that has column names > with embedded spaces in them (see error messages below).> When I go to delete one of these records I get messages like the ones > below for every column with any embedded spaces.<snip>> Exception occured during reader method compilation. > Maybe Date Code 3 is not a valid Ruby identifier? > (eval):1:in `evaluate_read_method'': compile error > (eval):1: formal argument cannot be a constant> def Date Code 3; raise NoMethodError, ''missing attribute: Date Code 3'', > caller unless @attributes.has_key?(''Date Code 3''); @attributes[''Date > Code 3'']; endWes, These errors are thrown by ActiveRecord::Base when it tries to create attribute accessor methods. As you can see, it''s trying to define a method ''Date Code 3'' which is an invalid method name due to the spaces within the name. The fact that DB column names can map to object attribute names is a fundamental assumption of ActiveRecord, and hence not an easy thing to overcome. The best solution I can think is to develop a plugin to map attribute names used in your database to valid method names and patch your version of active record to use this mapping. Tom --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Dec-07 15:44 UTC
Re: AR/SQLServer: Legacy column names with embedded spaces
Tom Ward wrote:> Wes, > > These errors are thrown by ActiveRecord::Base when it tries to create > attribute accessor methods. As you can see, it''s trying to define a > method ''Date Code 3'' which is an invalid method name due to the spaces > within the name. The fact that DB column names can map to object > attribute names is a fundamental assumption of ActiveRecord, and hence > not an easy thing to overcome. The best solution I can think is to > develop a plugin to map attribute names used in your database to valid > method names and patch your version of active record to use this > mapping.Tom, Thanks. I wonder how many DBs beside SQL Server actually even allow column names to have embedded spaces. Even if it''s only SS, this feels like something that should be handled, if only to ease Rails adoption to work with legacy schemas. If I get some time, I will look into it. Wes -- 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 -~----------~----~----~----~------~----~------~--~---