Working around capitalization problems moving from MySQL to Oracle

50 views
Skip to first unread message

loctones

unread,
Mar 19, 2009, 7:50:48 PM3/19/09
to sqlalchemy
I'm moving the database which drives a program from MySQL to Oracle.
The original implementation of the database columns was in CamelCase.
My company dictates that all caps be used for column names.

In the sqlalchemy documentation, I found this quote:
Names which contain no upper case characters will be treated as case
insensitive names, and will not be quoted unless they are a reserved
word. Names with any number of upper case characters will be quoted
and sent exactly. Note that this behavior applies even for databases
which standardize upper case names as case insensitive such as Oracle.

When I reflect my tables from the Oracle database, I get column names
that are all lowercase. But the leftover CamelCase style causes the
operations to be case sensitive, and I get failures regarding missing
attributes, etc. Is there a simpler way around this problem than
converting all of the CamelCase stuff to lowercase?

thanks,
Tony

Michael Bayer

unread,
Mar 19, 2009, 8:13:19 PM3/19/09
to sqlal...@googlegroups.com

a search and replace of all your CamelCase names is definitely the
simplest way around this issue. Alternatively you would have to
forego the usage of reflection and rename your attributes using "key":

t = Table("mytable", metadata,
Column("somecolumn", Integer, key="SomeColumn")
)

or you can accomplish something similar with the ORM, if that's all
you needed:

mapper(MyClass, sometable, properties={
'SomeColumn':sometable.c.somecolumn
})


both of the above can be automated with custom code, and possibly even
can be built around the reflected tables. but you'd need some kind of
lowercase-to-CamelCase converter.

loct...@hotmail.com

unread,
Mar 20, 2009, 11:27:12 AM3/20/09
to sqlalchemy

> a search and replace of all your CamelCase names is definitely the  
> simplest way around this issue.   Alternatively you would have to  
> forego the usage of reflection and rename your attributes using "key":

Thanks, Michael. I will go with the search and replace method. The
mapper method was what I was hoping for, but I think that may cause
more confusion in the long run. It's a good technique, though, and
I'm happy to know how to use it if I need something similar in the
future.
Reply all
Reply to author
Forward
0 new messages