|
29 | 29 | from sqlalchemy.sql import compiler |
30 | 30 | from sqlalchemy.sql import operators |
31 | 31 | from sqlalchemy.engine import default |
32 | | -from sqlalchemy import __version__ as SA_Version |
| 32 | +from sqlalchemy import __version__ as SA_VERSION_STR |
33 | 33 | from . import reflection as ibm_reflection |
34 | | -from packaging import version |
35 | 34 |
|
36 | | -SQLALCHEMY_VERSION = version.parse(sqlalchemy.__version__) |
| 35 | +m = re.match(r"^\s*(\d+)\.(\d+)", SA_VERSION_STR) |
| 36 | +SA_VERSION_MM = (int(m.group(1)), int(m.group(2))) if m else (0, 0) |
37 | 37 |
|
38 | | -if SQLALCHEMY_VERSION >= version.parse("2.0"): |
| 38 | +if SA_VERSION_MM >= (2, 0): |
39 | 39 | from sqlalchemy.sql.sqltypes import NullType, NULLTYPE, _Binary |
40 | 40 | from sqlalchemy.sql.sqltypes import ( |
41 | 41 | ARRAY, BIGINT, BigInteger, BINARY, BLOB, BOOLEAN, Boolean, |
|
68 | 68 | UserDefinedType, Variant |
69 | 69 | ) |
70 | 70 |
|
71 | | -SA_Version = [int(ver_token) for ver_token in SA_Version.split('.')[0:2]] |
72 | | - |
73 | 71 | # as documented from: |
74 | 72 | # http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0001095.htm |
75 | 73 | RESERVED_WORDS = set( |
@@ -373,7 +371,7 @@ def visit_large_binary(self, type_, **kw): |
373 | 371 |
|
374 | 372 |
|
375 | 373 | class DB2Compiler(compiler.SQLCompiler): |
376 | | - if SA_Version < [0, 9]: |
| 374 | + if SA_VERSION_MM < (0, 9): |
377 | 375 | def visit_false(self, expr, **kw): |
378 | 376 | return '0' |
379 | 377 |
|
@@ -550,7 +548,7 @@ def visit_function(self, func, result_map=None, **kwargs): |
550 | 548 | def visit_cast(self, cast, **kw): |
551 | 549 | type_ = cast.typeclause.type |
552 | 550 |
|
553 | | - if SQLALCHEMY_VERSION >= version.parse("2.0"): |
| 551 | + if SA_VERSION_MM >= (2, 0): |
554 | 552 | valid_types = ( |
555 | 553 | CHAR, VARCHAR, CLOB, String, Text, Unicode, UnicodeText, |
556 | 554 | BLOB, LargeBinary, VARBINARY, |
@@ -718,7 +716,7 @@ def create_table_constraints(self, table, **kw): |
718 | 716 | return result |
719 | 717 |
|
720 | 718 | def visit_create_index(self, create, include_schema=True, include_table_schema=True, **kw): |
721 | | - if SA_Version < [0, 8]: |
| 719 | + if SA_VERSION_MM < (0, 8): |
722 | 720 | sql = super(DB2DDLCompiler, self).visit_create_index(create, **kw) |
723 | 721 | else: |
724 | 722 | sql = super(DB2DDLCompiler, self).visit_create_index(create, include_schema, include_table_schema, **kw) |
@@ -798,9 +796,9 @@ class DB2Dialect(default.DefaultDialect): |
798 | 796 | supports_char_length = False |
799 | 797 | supports_unicode_statements = False |
800 | 798 | supports_unicode_binds = False |
801 | | - if SA_Version < [1, 4]: |
| 799 | + if SA_VERSION_MM < (1, 4): |
802 | 800 | returns_unicode_strings = False |
803 | | - elif SA_Version < [2, 0]: |
| 801 | + elif SA_VERSION_MM < (2, 0): |
804 | 802 | returns_unicode_strings = sa_types.String.RETURNS_CONDITIONAL |
805 | 803 | else: |
806 | 804 | returns_unicode_strings = True |
|
0 commit comments