On Tuesday, March 5, 2013 2:14:04 PM UTC-7, Steven Githens wrote:
>
> Hello Django Users,
>
> I have an app that uses Oracle and cx_Oracle for the db, and I've made the 
> models from an existing schema with inspectdb.
>
> The database schema also contains a number of sub-schemas, so they must be 
> accessed with schema dot table name.  Looking at the SQL used for model 
> access, I believe Django's automatic quoting of table names in the SQL is 
> causing issues with table name lookup.
>
> I can verify using cursor.execute in the shell, that if I leave off the 
> quotes, the queries work fine.  Is there an easy way to disable table name 
> quoting? (or other facility that gets around this? )
>
>
There is a long-standing ticket to add explicit schema declarations to 
models -- see https://code.djangoproject.com/ticket/6148
Unfortunately the most recent patch is almost a year old at this point, so 
I have no idea how well it would work.

In the meanwhile, the commonly used workaround for this is to include the 
schema in the db_table declaration like so:

db_table = 'my_schema"."my_table'

Note that quotes are included at the end of the schema name and the start 
of the table name, but not at the extremities of the string, since they 
will be added by the backend.  A couple of warnings about this approach:

1) This will break syncdb.  If you're not using syncdb, then this probably 
doesn't matter to you.

2) The oracle backend performs automatic name mangling on table names 
longer than 30 characters.  Since it considers the above to be all one 
table name, this effectively reduces the allowed table name length before 
name manging is applied by the number of extra characters.



On Tuesday, March 5, 2013 3:45:36 PM UTC-7, Shawn Milochik wrote:On Tue, 
Mar 5, 2013 at 5:41 PM, Johan ter Beest <m...@terbeest.net> wrote: 
>> Not an Oracle expert at all but maybe this SO answer explains some 
things?: 
>> 
>> 
http://stackoverflow.com/questions/563090/oracle-what-exactly-do-quotation-marks-around-the-table-name-do
 
>> 
>
> So if it's down to case-sensitivity then everything should be fine, 
> because all the queries are generated by the ORM and aren't going to 
> mix case. 

It's not just about case sensitivity.  The quotes are also required for 
names that happen to be Oracle keywords.  If you're controlling all the 
names though, then this is fairly easy to avoid.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to