statement invalid ORA-00904 : non-quoting of mixed case table names

100 views
Skip to first unread message

Austin Che

unread,
Feb 27, 2010, 9:13:57 PM2/27/10
to Oracle enhanced adapter for ActiveRecord
I just started trying to use the Oracle enhanced adapter and it's
failing for me. It appears to be a problem with case sensitivity
of table names in Oracle and bad quoting somewhere.

Schema:
create_table "Bugs" do |t|
end

Models:
class Bug < ActiveRecord::Base
set_table_name "Bugs"
end

Bug.last gives the following error:
ActiveRecord::StatementInvalid: OCIError: ORA-00904: "BUGS"."ID":
invalid identifier: select * from (select raw_sql_.*, rownum raw_rnum_
from (SELECT * FROM "Bugs" ORDER BY Bugs.id DESC) raw_sql_ where
rownum <= 1) where raw_rnum_ > 0

It appears that the table name is not being quoted properly in
the ORDER BY clause. Bug.first doesn't give an error. It works
fine if the table name is "bugs" or "BUGS" instead.

Versions:
activerecord (2.3.5)
activerecord-oracle_enhanced-adapter (1.2.4)
ruby-oci8 (2.0.3)

Raimonds Simanovskis

unread,
Feb 28, 2010, 4:09:59 AM2/28/10
to Oracle enhanced adapter for ActiveRecord
Are you creating new table for Rails application or trying to access
some legacy table?
If you create new table then please always use lowercase version of
table name - handling of mixed case table names was added just to pass
some ActiveRecord tests and it seems that it is not working correctly
for order by clause :)

I think it will work correctly in Rails 3 as there SQL generation is
rewritten to use Arel gem and it will quote table names correctly in
all places.

Raimonds

Austin Che

unread,
Feb 28, 2010, 11:52:36 AM2/28/10
to Oracle enhanced adapter for ActiveRecord
I'm trying to access legacy tables and it would be nice to get it to
work on rails < 3.
Given that it already supports mixed case table names in some places,
is there an
easy workaround for the order by clause?

Thanks.

On Feb 28, 4:09 am, Raimonds Simanovskis

Raimonds Simanovskis

unread,
Feb 28, 2010, 2:57:44 PM2/28/10
to Oracle enhanced adapter for ActiveRecord
Probably the easiest workaround would be to define database synonym

CREATE OR REPLACE SYNONYM bugs FOR "Bugs"

or include in migration

add_synonym :bugs, "Bugs"

and then you can use "bugs" as table name for your model class.

Reply all
Reply to author
Forward
0 new messages