Forum: Ruby on Rails ActiveRecord: table name with spaces?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Michael T. (Guest)
on 2006-01-16 19:04
(Received via mailing list)

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
    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
lserver_adapter.rb:467:in `select'
d/connection_adapters/sqlserver_adapter.rb:227:in `select_all'
d/base.rb:431:in `find_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.
Alan G. (Guest)
on 2006-01-16 20:59
(Received via mailing list)
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
Michael T. (Guest)
on 2006-01-17 03:01
(Received via mailing list)
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 topic is locked and can not be replied to.