Skip to content

Commit 22daac2

Browse files
authored
Support for Django 3.1 (#170)
* Support for Django 3.1 * django-viewflow creates malformed meta object on CompositeKey. Compensating for this. * IDENT_CURRENT for IBM DB2
1 parent 8e7a511 commit 22daac2

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Features
1414
--------
1515

1616
* [x] Alpha support for Django 2.0 via ``pip install django-pyodbc>=2.0.0a1``
17+
* [x] Alpha support for Django 3.1 via ``pip install django-pyodbc>=2.0.0a2``
1718
* [x] Support for Django 1.4-1.10.
1819
* [x] Support for SQL Server 2000, 2005, 2008, and 2012 (please let us know if you have success running this backend with another version of SQL Server)
1920
* [x] Support for Openedge 11.6

django_pyodbc/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484

8585
if DjangoVersion[:2] == (2, 0):
8686
_DJANGO_VERSION = 20
87+
elif DjangoVersion[:2] == (3, 1):
88+
_DJANGO_VERSION = 31
8789
else:
8890
if DjangoVersion[0] == 1:
8991
raise ImproperlyConfigured("Django %d.%d " % DjangoVersion[:2] +
@@ -439,7 +441,7 @@ def __init__(self, cursor, driver_supports_utf8, encoding="", db_wrpr=None):
439441
def close(self):
440442
try:
441443
self.cursor.close()
442-
except Database.ProgrammingError:
444+
except:
443445
pass
444446

445447
def format_sql(self, sql, n_params=None):

django_pyodbc/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171

7272
# new modules from Django1.5
7373
try:
74-
from django.utils.six import PY3
74+
from six import PY3
7575
_py3 = PY3
7676
except ImportError:
7777
_py3 = False
7878

7979
try:
80-
from django.utils.six import b, binary_type, string_types, text_type
80+
from six import b, binary_type, string_types, text_type
8181
except ImportError:
8282
b = lambda s: s
8383
binary_type = str

django_pyodbc/compiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def _fix_insert(self, sql, params):
510510
"""
511511
meta = self.query.get_meta()
512512

513-
if meta.has_auto_field:
513+
if getattr(meta, 'has_auto_field',False):
514514
if hasattr(self.query, 'fields'):
515515
# django 1.4 replaced columns with fields
516516
fields = self.query.fields
@@ -583,7 +583,7 @@ def as_sql_legacy(self):
583583
sql = ' '.join(result)
584584

585585
meta = self.query.get_meta()
586-
if meta.has_auto_field:
586+
if getattr(meta, 'has_auto_field',False):
587587
# db_column is None if not explicitly specified by model field
588588
auto_field_column = meta.auto_field.db_column or meta.auto_field.column
589589

@@ -651,7 +651,7 @@ def as_sql(self):
651651
# This section deals with specifically setting the primary key,
652652
# or using default values if necessary
653653
meta = self.query.get_meta()
654-
if meta.has_auto_field:
654+
if getattr(meta, 'has_auto_field',False):
655655
# db_column is None if not explicitly specified by model field
656656
auto_field_column = meta.auto_field.db_column or meta.auto_field.column
657657
out = []

django_pyodbc/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
__version__ = "2.0.0a1"
29+
__version__ = "2.0.0a2"
3030
__maintainer__ = "Dan Loewenherz"
3131
__maintainer_email__ = "[email protected]"
3232
__license__ = "BSD 3-Clause License"

django_pyodbc/operations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ def last_insert_id(self, cursor, table_name, pk_name):
261261
# @@IDENTITY is not limited to a specific scope.
262262

263263
table_name = self.quote_name(table_name)
264-
cursor.execute("SELECT CAST(IDENT_CURRENT(%s) as bigint)", [table_name])
264+
if self._is_db2:
265+
cursor.execute("SELECT CAST(IDENTITY_VAL_LOCAL() as bigint) from %s" % table_name)
266+
else:
267+
cursor.execute("SELECT py(IDENT_CURRENT(%s) as bigint)", [table_name])
265268
return cursor.fetchone()[0]
266269

267270
def fetch_returned_insert_id(self, cursor):

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"Operating System :: MacOS :: MacOS X",
5151
"Operating System :: OS Independent",
5252
"Operating System :: Unix",
53-
"Programming Language :: Python :: 2.7",
53+
"Programming Language :: Python :: 3.9",
5454
"Topic :: Software Development :: Libraries",
5555
]
5656

@@ -71,5 +71,6 @@
7171
],
7272
install_requires=[
7373
'pyodbc>=3.0.6,<4.1',
74+
'six>=1.15.0'
7475
]
7576
)

0 commit comments

Comments
 (0)