#20226: Django problematic when Oracle when column/table names are mixed case
-------------------------------------+-------------------------------------
Reporter: calcium | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Oracle, ORM | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by timgraham:
Old 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.
New 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, str(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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/20226#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.8ad1cc96ae8cdb3bb9c740eda771523e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.