ActiveRecord: table name with spaces?


I’m trying to work with a legacy SQL Server database where some of the
table names have spaces in them.

I’ve done set_table_name “tablename with spaces”, but I can’t get
find(:all) to work. I get the following error (because apparently
it’s not putting [ ] around the name as is required for SQL Server for
names with spaces.

adapters/abstract_adapter.rb:88:in log': DBI::DatabaseError: Execute (ActiveRec ord::StatementInvalid) OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server Incorrect syntax near the keyword 'all'. HRESULT error code:0x80020009 Exception occurred.: SELECT * FROM all wells with apis from c:/ruby/lib /ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/sq lserver_adapter.rb:467:inselect’
d/connection_adapters/sqlserver_adapter.rb:227:in select_all' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_recor d/base.rb:431:infind_by_sql’

I see from the exception method that it hasn’t delimited the table
name. There may be more than one way to do this in T-SQL, but what
I’m familiar with is putting [ ] around the table name.

If I do my own manual find_by_sql and put “select * from [all wells
with apis]” it works fine.

Thanks for any suggestions.

Michael T. wrote:

If I do my own manual find_by_sql and put “select * from [all wells
with apis]” it works fine.

Could you just create a view on the table without spaces in the name and
select off of that? “SELECT * FROM all_wells_with_apis_view;”

Alan G.
Cronosys, LLC
Phone: 216-221-4600 ext 308

Ok, without other suggestions that’s what I’ll do (and thanks for that

But I am curious what one would do if modifying the DB were not an
option? Are we reduced to doing all _by_sql() calls?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs