Opened 12 years ago
Last modified 9 years ago
#20226 new Bug
Django problematic when Oracle when column/table names are mixed case — at Initial Version
Reported by: | calcium | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.5 |
Severity: | Normal | Keywords: | Oracle, ORM |
Cc: | shai@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | |
Needs tests: | Patch needs improvement: | ||
Easy pickings: | no | UI/UX: | no |
Description
In my Oracle DB, some of the tables have column names which are not uppercase only.
eg
column names are "FIRSTNAME", and "CallType".
When running a query against any table with such non-uppercase only columnnames, I get an error like
django.db.utils.DatabaseError: ORA-00904: "SOMETABLENAME"."CALLTYPE": invalid identifier.
I got around my problem by editing the compiler.py file.
/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py
The diff is as follows.
* ~/Exploded/Django-1.5.1/django/db/models/sql/compiler.py 2013-03-29 07:07:20.000000000 +1100
--- /usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py 2013-04-09 12:56:07.293736020 +1000
* class SQLCompiler(object):
* 296,302
--- 296,305 ----
col_aliases.add(c_alias)
aliases.add(c_alias)
else:
+ m = map(str.isupper, field.column)
r = '%s.%s' % (qn(alias), qn2(field.column))
+ if True in m: # if there is an uppercase, leave it.
+ r = '%s."%s"' % (qn(alias), field.column)
result.append(r)
aliases.add(r)
if with_aliases:
ie. I check if there is an uppercase in the column name, and if so,
I quote the column name, leaving the case as it is ie. mixed.
ie. the column names seem to come in as all lower case and then it
gets converted to uppercase.
I'm not sure what to do if the column names are really all lower case.
This was just a quick and dirty fix for my use.
I think maybe a more solid fix might be required but just raising it here in case anybody just wanted a quick fix.
A similar problem arises for mixed case table names.
I didnt do a fix for that, yet.