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:inevaluate_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
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.
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
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.