Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions ibm_db_sa/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
from sqlalchemy.sql import compiler
from sqlalchemy.sql import operators
from sqlalchemy.engine import default
from sqlalchemy import __version__ as SA_Version
from sqlalchemy import __version__ as SA_VERSION_STR
from . import reflection as ibm_reflection
from packaging import version

SQLALCHEMY_VERSION = version.parse(sqlalchemy.__version__)
m = re.match(r"^\s*(\d+)\.(\d+)", SA_VERSION_STR)
SA_VERSION_MM = (int(m.group(1)), int(m.group(2))) if m else (0, 0)

if SQLALCHEMY_VERSION >= version.parse("2.0"):
if SA_VERSION_MM >= (2, 0):
from sqlalchemy.sql.sqltypes import NullType, NULLTYPE, _Binary
from sqlalchemy.sql.sqltypes import (
ARRAY, BIGINT, BigInteger, BINARY, BLOB, BOOLEAN, Boolean,
Expand Down Expand Up @@ -68,8 +68,6 @@
UserDefinedType, Variant
)

SA_Version = [int(ver_token) for ver_token in SA_Version.split('.')[0:2]]

# as documented from:
# http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0001095.htm
RESERVED_WORDS = set(
Expand Down Expand Up @@ -373,7 +371,7 @@ def visit_large_binary(self, type_, **kw):


class DB2Compiler(compiler.SQLCompiler):
if SA_Version < [0, 9]:
if SA_VERSION_MM < (0, 9):
def visit_false(self, expr, **kw):
return '0'

Expand Down Expand Up @@ -550,7 +548,7 @@ def visit_function(self, func, result_map=None, **kwargs):
def visit_cast(self, cast, **kw):
type_ = cast.typeclause.type

if SQLALCHEMY_VERSION >= version.parse("2.0"):
if SA_VERSION_MM >= (2, 0):
valid_types = (
CHAR, VARCHAR, CLOB, String, Text, Unicode, UnicodeText,
BLOB, LargeBinary, VARBINARY,
Expand Down Expand Up @@ -718,7 +716,7 @@ def create_table_constraints(self, table, **kw):
return result

def visit_create_index(self, create, include_schema=True, include_table_schema=True, **kw):
if SA_Version < [0, 8]:
if SA_VERSION_MM < (0, 8):
sql = super(DB2DDLCompiler, self).visit_create_index(create, **kw)
else:
sql = super(DB2DDLCompiler, self).visit_create_index(create, include_schema, include_table_schema, **kw)
Expand Down Expand Up @@ -798,9 +796,9 @@ class DB2Dialect(default.DefaultDialect):
supports_char_length = False
supports_unicode_statements = False
supports_unicode_binds = False
if SA_Version < [1, 4]:
if SA_VERSION_MM < (1, 4):
returns_unicode_strings = False
elif SA_Version < [2, 0]:
elif SA_VERSION_MM < (2, 0):
returns_unicode_strings = sa_types.String.RETURNS_CONDITIONAL
else:
returns_unicode_strings = True
Expand Down
16 changes: 9 additions & 7 deletions ibm_db_sa/ibm_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
# | Contributors: Jaimy Azle, Mike Bayer,Hemlata Bhatt |
# +--------------------------------------------------------------------------+

from sqlalchemy import __version__ as SA_Version
SA_Version = [int(ver_token) for ver_token in SA_Version.split('.')[0:2]]
import re
from sqlalchemy import __version__ as SA_VERSION_STR
m = re.match(r"^\s*(\d+)\.(\d+)", SA_VERSION_STR)
SA_VERSION_MM = (int(m.group(1)), int(m.group(2))) if m else (0, 0)

from .base import DB2ExecutionContext, DB2Dialect

if SA_Version < [2,0]:
if SA_VERSION_MM < (2, 0):
from sqlalchemy import processors, types as sa_types, util
else:
from sqlalchemy import types as sa_types, util
Expand All @@ -36,7 +38,7 @@
SQL_TXN_SERIALIZABLE = 8
SQL_ATTR_TXN_ISOLATION = 108

if SA_Version < [0, 8]:
if SA_VERSION_MM < (0, 8):
from sqlalchemy.engine import base
else:
from sqlalchemy.engine import result as _result
Expand Down Expand Up @@ -76,7 +78,7 @@ def pre_exec(self):

def get_result_proxy(self):
if self._callproc_result and self._out_parameters:
if SA_Version < [0, 8]:
if SA_VERSION_MM < (0, 8):
result = base.ResultProxy(self)
else:
result = _result.ResultProxy(self)
Expand All @@ -89,7 +91,7 @@ def get_result_proxy(self):

return result
else:
if SA_Version < [0, 8]:
if SA_VERSION_MM < (0, 8):
result = base.ResultProxy(self)
else:
result = _result.ResultProxy(self)
Expand All @@ -115,7 +117,7 @@ class DB2Dialect_ibm_db(DB2Dialect):
}
)

if SA_Version < [2, 0]:
if SA_VERSION_MM < (2, 0):
@classmethod
def dbapi(cls):
""" Returns: the underlying DBAPI driver module
Expand Down
8 changes: 5 additions & 3 deletions ibm_db_sa/ibm_db_as400.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sqlalchemy import __version__ as SA_Version
SA_Version = [int(ver_token) for ver_token in SA_Version.split('.')[0:2]]
import re
from sqlalchemy import __version__ as SA_VERSION_STR
m = re.match(r"^\s*(\d+)\.(\d+)", SA_VERSION_STR)
SA_VERSION_MM = (int(m.group(1)), int(m.group(2))) if m else (0, 0)
from .base import DB2ExecutionContext, DB2Dialect
if SA_Version < [2,0]:
if SA_VERSION_MM < (2, 0):
from sqlalchemy import processors, types as sa_types, util
else:
from sqlalchemy import types as sa_types, util
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=42", "wheel", "packaging>=20.0"]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

readme = os.path.join(os.path.dirname(__file__), 'README.md')
if 'USE_PYODBC' in os.environ and os.environ['USE_PYODBC'] == '1':
require = ['sqlalchemy>=0.7.3', 'packaging>=20.0']
require = ['sqlalchemy>=0.7.3']
else:
require = ['sqlalchemy>=0.7.3','ibm_db>=2.0.0', 'packaging>=20.0']
require = ['sqlalchemy>=0.7.3','ibm_db>=2.0.0']


setup(
Expand Down