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

django-pyodbc query with OFFSET+LIMIT issue #157

Open
CrVik opened this issue Mar 6, 2018 · 0 comments
Open

django-pyodbc query with OFFSET+LIMIT issue #157

CrVik opened this issue Mar 6, 2018 · 0 comments

Comments

@CrVik
Copy link

CrVik commented Mar 6, 2018

Hello!
I have issue after try get the query with OFFSET+LIMIT
if i try to get with offset = 0 and limit=3 then i get normal queryset and in this queryset values in their places, i.e. field.id=id, field.name=name
But if i try get queryset with offset more then zero + limit, i get the the queryset with additional field ROW_Number(i check it in sql server profiler) and i find it ({row_num_col}) in the compiler.py code:

sql = "SELECT {row_num_col}, {outer} FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY {order}) as {row_num_col}, {inner}) as QQQ where {where}".format(
                outer=outer_fields,
                order=order,
                inner=inner_select,
                where=where_row_num,
                row_num_col=row_num_col
            )

and this filed gives the offset for get values in qeuryset.
Because if i try to get value from ID field i get value of ROW_Number, and if i try to get value from field NAME i get value ID field.

example on the picture:
photo_2018-03-07_00-37-12

I try to remove in compiler.py filed {row_num_col} from query, after that works fine, but I'm afraid of doing this, all of a sudden it can affect something else.

Help please!

MS SQL server 2014 (firstly tested on MS SQL server 2005)
pyodbc version 1.1.3
settings:

DATABASES = {
    'default': {
        'ENGINE': 'django_pyodbc',
        'HOST': '10.8.0.201\DATABASES',
        'PORT': '1433',
        'USER': 'sa',
        'PASSWORD': '123321',
        'NAME': 'test_db',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
            'host_is_server': True,
            'autocommit': True,
            'unicode_results': True,
        },
    }
}
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