ibmdb / python-ibmdb-django

IBM DB2 Driver for the Django application Framework
Apache License 2.0
29 stars 42 forks source link

Django - AS400 Table Quoting Issue (maybe) #8

Closed kadler closed 6 years ago

kadler commented 7 years ago

From @GoogleCodeExporter on March 16, 2015 6:50

What steps will reproduce the problem?
1. Setup django database connection to AS400 iSeries
2. Create a database model
3. Query that model

What is the expected output? What do you see instead?

The output should be the returned queryset of the django model and I am getting 
an error that seems to be a table/file quoting issue. Here is the stacktrace of 
what I get:

Traceback (most recent call last):
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/core/management/base.py", line 255, in execute
    output = self.handle(*args, **options)
  File "/home/sherzberg/sai/ryko-customer-master/fstwo-backend/django/asf/management/commands/testing.py", line 13, in handle
    print Customer.objects.all()[:20]
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/models/query.py", line 93, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/models/query.py", line 108, in __len__
    self._result_cache.extend(self._iter)
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/models/query.py", line 317, in iterator
    for row in compiler.results_iter():
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 846, in execute_sql
    cursor.execute(sql, params)
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
    return self.cursor.execute(sql, params)
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/ibm_db_django/pybase.py", line 153, in execute
    six.reraise(utils.DatabaseError, utils.DatabaseError( *tuple( e ) ), sys.exc_info()[2])
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/ibm_db_django/pybase.py", line 144, in execute
    return super( DB2CursorWrapper, self ).execute( operation, parameters )
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/ibm_db_dbi.py", line 1331, in execute
    self._set_cursor_helper()
  File "/home/sherzberg/.virtualenvs/fstwo/local/lib/python2.7/site-packages/ibm_db_dbi.py", line 1214, in _set_cursor_helper
    raise self.messages[len(self.messages) - 1]
DatabaseError

Here is the logged sql that is generated: 

SELECT "Z.__db2_1" FROM ( SELECT "Z.__db2_1", ( ROW_NUMBER() OVER() ) AS 
"Z.__ROWNUM" FROM (  SELECT "DATABASE.TABLE"."C$NO" AS "Z.__db2_1" FROM 
"DATABASE.TABLE"  ) AS M ) Z WHERE "Z.__ROWNUM" <= 20

I tried modifying ibm_db_django/ibm_db_django/operations.py in the quote_name 
function to not put quotes around the table name and the query works just fine. 
However this is not an ideal solution.

Is this an issue with the library or an issue with my configuration?

What version of the product are you using? On what operating system?

Django is running on Ubuntu 12.04 linux. The db2 instance version is 9.1

Please provide any additional information below.

I am not a DB2 expert, just a guy trying to bootstrap a legacy system. Thanks 
in advance!

Original issue reported on code.google.com by spencer....@gmail.com on 14 Nov 2013 at 9:53

Copied from original issue: ibmdb/python-ibmdb#141

kadler commented 7 years ago

From @GoogleCodeExporter on March 16, 2015 6:50

We have not tested remote connection to AS400(iSeries) and currently it not 
supported from Django, So you might face some issues while using it with Django.

Since currently you have a workaround, I will look into this issue later.

Original comment by rahul.pr...@in.ibm.com on 20 Nov 2013 at 6:42

kadler commented 7 years ago

From @GoogleCodeExporter on March 16, 2015 6:50

Original comment by rahul.pr...@in.ibm.com on 20 Nov 2013 at 6:42

Vyshakh18 commented 6 years ago

Since workaround is available, closing this issue for now due to other priority items. Re-open when needed.