Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenEdge support not working in master. Some basic fixes here #139

Open
2 tasks
AkshayGuleria opened this issue Mar 9, 2017 · 0 comments
Open
2 tasks

Comments

@AkshayGuleria
Copy link

AkshayGuleria commented Mar 9, 2017

Some details before we start:

  • Django App name: sports_demo_odbc
  • CLASSPATH is set correctly. Tested using python shell and pyodbc connection.
  • Settings
DATABASES = {
    'default': {
        'ENGINE': "django_pyodbc",
        'HOST': "localhost,11001",
        'USER': "akguleri",
        'PASSWORD': "notAdmin",
        'NAME': "sports_demo",
        'OPTIONS': {
           'host_is_server': True,
           'dsn': 'dsn_sports_demo',
           'openedge': True
        },
    }   
} 
  • Django version = 1.10.6

I hope you have tried checking if the OpenEdge is supported as the documentation says. I tried this but didn't work. The connection establishment works fine (using python manage.py runserver) but the queries made to OpenEdge database are not correct. I fixed most of them by hand and reached to the point where at least the server was started without any errors.
Below are the errors that I got (in the same order) and fixed them by hand to make it work.

  1. Error on fetching TABLES from OpenEdge DB:
    Query:
File "/usr/local/lib/python2.7/dist-packages/django_pyodbc-1.1.0-py2.7.egg/django_pyodbc/introspection.py", line 95, in get_table_list
    cursor.execute("SELECT TABLE_NAME, 't' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'")

Error:

File "/usr/local/lib/python2.7/dist-packages/django_pyodbc-1.1.0-py2.7.egg/django_pyodbc/base.py", line 495, in execute
    raise utils.DatabaseError(*e.args)
django.db.utils.DatabaseError: ('HY000', '[HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Table/view/synonynm "INFORMATION_SCHEMA.TABLES" cannot be found. (15814) (-210083) (SQLExecDirectW)')

Correct Query should be:

if <is_opendge>:
       cursor.execute("SELECT TBL, 't' FROM SYSPROGRESS.SYSTABLES WHERE TBLTYPE = 'T'")
  1. SchemaEditorClass attribute:
    Error:
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 604, in schema_editor
    'The SchemaEditorClass attribute of this database wrapper is still None')
NotImplementedError: The SchemaEditorClass attribute of this database wrapper is still None

I commented the call to schema_editor (in recorder.py) since it tries to create tables using create_model. There should be some way to control this. I don't want to create/change my OpenEdge schema over this API. Perhaps I'm too new to this area that I don't know how to control this behaviour. It would be nice if you can guide me on this.

This can be controlled by disabling self.check_migrations for OpenEdge connections but that has to be done in django's runserver.py file. So this error does not concern this adapter.

  1. AttributeError:
    Error:
File "/usr/local/lib/python2.7/dist-packages/django_pyodbc-1.1.0-py2.7.egg/django_pyodbc/compiler.py", line 204, in as_sql
    self._fix_aggregates()
  File "/usr/local/lib/python2.7/dist-packages/django_pyodbc-1.1.0-py2.7.egg/django_pyodbc/compiler.py", line 180, in _fix_aggregates
    for alias, aggregate in self.query.aggregate_select.items():
AttributeError: 'Query' object has no attribute 'aggregate_select'

The _fix_aggregates function perhaps is meant to counter some MSSQL behaviour as the comment says in the code. I'm not 100% sure though. Again I used self.connection.ops.is_openedge and prevent the execution of that function.

  1. Migration problem again:
    Error:
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute  return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django_pyodbc-1.1.0-py2.7.egg/django_pyodbc/base.py", line 496, in execute  raise utils.DatabaseError(*e.args)
django.db.utils.DatabaseError: ('HY000', '[HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Table/view/synonynm "AKGULERI.django_migrations" cannot be found. (15814) (-210083) (SQLExecDirectW)')

This might be Django framework itself but it tries get something Djnago specific which is not available in OpenEdge DB. Here too I made a dirty fix and avoided execution of such query by replacing it with simple query i.e. SELECT TOP 1 * FROM SYSPROGRESS.SYSTABLES. Any guidance on this would be helpful as well.

This can be controlled by disabling self.check_migrations for OpenEdge connections but that has to be done in django's runserver.py file. So this error does not concern this adapter.

  1. Query quotes: After all this the server started I created a simple model for Customer table (having Meta class db_table = 'PUB.CUSTOMER') of the connected OpenEdge DB. Then using shell I created a instance of Customer and tried to fetch some data using customer.objects.get(pk=1) but was returned the below with an error on the shell. The query it formed was something like this
    SELECT "PUB.CUSTOMER"."custnum", "PUB.CUSTOMER"."name", "PUB.CUSTOMER"."city" FROM "PUB.CUSTOMER" WHERE "PUB.CUSTOMER"."custnum" = ?
    This query did not yield any result until the quotes were. So I change the function quote_name in operations.py to return unquoted name variable if self.is_openedge. Progress does support querying with quotes but this was perhaps an odd occasion where this query was not formed correctly.

Now (finally :)) the query customer.objects.get(pk=1) gets me results from the DB. But perhaps these fixes should be done properly into the django-pyodbc code.

@AkshayGuleria AkshayGuleria changed the title Does OpenEdge support work? OpenEdge support not working in master. Some basic fixes here May 23, 2017
@dlo dlo added the help wanted label Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants