google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

iregex sql statement gets expanded incorrectly when there are low/high limits #133

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

This can probably be done via a iregex filter query.  I discovered the problem 
via a REST api using Django REST Framework.

1. define a REST api, set a column FOOBAR with an iregex lookup via a 
django_filters.FilterSet filter
2. call the api, with foobar=findme&page=2&start=100&limit=100 (second page or 
later)

Expected results: I should see results from 100 to 200.  Instead, I get this 
error message:

  'The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000'

The issue is that the SQL query should have:

   SELECT ... FROM tbl WHERE foobar LIKE %s, params = ('findme')

Instead, the query is

   SELECT ... FROM tbl WHERE foobar LIKE {}, params = ('findme')

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

   Using Django 1.6.4, django-pyodbc 0.2.5

Please provide any additional information below.

   Issue is that the compiler._alias_columns() is expanding the from_clause incorrectly.  In fact, I don't quite understand why the from_clause needs to be expanded at all.

-->      return ', '.join(outer), ', '.join(inner) + (from_clause % parens)
         #                                            ^^^^^^^^^^^^^^^^^^^^^
         # We can't use `format` here, because `format` uses `{}` as special 
         # characters, but those happen to also be the quoting tokens for IBM's

Original issue reported on code.google.com by albert.l...@gmail.com on 26 Sep 2014 at 7:26

GoogleCodeExporter commented 9 years ago
Suggested patch attached

Original comment by albert.l...@gmail.com on 28 Sep 2014 at 4:41

Attachments: