summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mssql/pyodbc.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /lib/sqlalchemy/dialects/mssql/pyodbc.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/pyodbc.py')
-rw-r--r--lib/sqlalchemy/dialects/mssql/pyodbc.py102
1 files changed, 61 insertions, 41 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py
index 34f81d6e8..db5573c2c 100644
--- a/lib/sqlalchemy/dialects/mssql/pyodbc.py
+++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py
@@ -132,15 +132,13 @@ class _ms_numeric_pyodbc(object):
def bind_processor(self, dialect):
- super_process = super(_ms_numeric_pyodbc, self).\
- bind_processor(dialect)
+ super_process = super(_ms_numeric_pyodbc, self).bind_processor(dialect)
if not dialect._need_decimal_fix:
return super_process
def process(value):
- if self.asdecimal and \
- isinstance(value, decimal.Decimal):
+ if self.asdecimal and isinstance(value, decimal.Decimal):
adjusted = value.adjusted()
if adjusted < 0:
return self._small_dec_to_string(value)
@@ -151,6 +149,7 @@ class _ms_numeric_pyodbc(object):
return super_process(value)
else:
return value
+
return process
# these routines needed for older versions of pyodbc.
@@ -158,30 +157,31 @@ class _ms_numeric_pyodbc(object):
def _small_dec_to_string(self, value):
return "%s0.%s%s" % (
- (value < 0 and '-' or ''),
- '0' * (abs(value.adjusted()) - 1),
- "".join([str(nint) for nint in value.as_tuple()[1]]))
+ (value < 0 and "-" or ""),
+ "0" * (abs(value.adjusted()) - 1),
+ "".join([str(nint) for nint in value.as_tuple()[1]]),
+ )
def _large_dec_to_string(self, value):
_int = value.as_tuple()[1]
- if 'E' in str(value):
+ if "E" in str(value):
result = "%s%s%s" % (
- (value < 0 and '-' or ''),
+ (value < 0 and "-" or ""),
"".join([str(s) for s in _int]),
- "0" * (value.adjusted() - (len(_int) - 1)))
+ "0" * (value.adjusted() - (len(_int) - 1)),
+ )
else:
if (len(_int) - 1) > value.adjusted():
result = "%s%s.%s" % (
- (value < 0 and '-' or ''),
- "".join(
- [str(s) for s in _int][0:value.adjusted() + 1]),
- "".join(
- [str(s) for s in _int][value.adjusted() + 1:]))
+ (value < 0 and "-" or ""),
+ "".join([str(s) for s in _int][0 : value.adjusted() + 1]),
+ "".join([str(s) for s in _int][value.adjusted() + 1 :]),
+ )
else:
result = "%s%s" % (
- (value < 0 and '-' or ''),
- "".join(
- [str(s) for s in _int][0:value.adjusted() + 1]))
+ (value < 0 and "-" or ""),
+ "".join([str(s) for s in _int][0 : value.adjusted() + 1]),
+ )
return result
@@ -212,6 +212,7 @@ class _ms_binary_pyodbc(object):
else:
# pyodbc-specific
return dialect.dbapi.BinaryNull
+
return process
@@ -243,9 +244,11 @@ class MSExecutionContext_pyodbc(MSExecutionContext):
# don't embed the scope_identity select into an
# "INSERT .. DEFAULT VALUES"
- if self._select_lastrowid and \
- self.dialect.use_scope_identity and \
- len(self.parameters[0]):
+ if (
+ self._select_lastrowid
+ and self.dialect.use_scope_identity
+ and len(self.parameters[0])
+ ):
self._embedded_scope_identity = True
self.statement += "; select scope_identity()"
@@ -281,26 +284,31 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
sqltypes.Numeric: _MSNumeric_pyodbc,
sqltypes.Float: _MSFloat_pyodbc,
BINARY: _BINARY_pyodbc,
-
# SQL Server dialect has a VARBINARY that is just to support
# "deprecate_large_types" w/ VARBINARY(max), but also we must
# handle the usual SQL standard VARBINARY
VARBINARY: _VARBINARY_pyodbc,
sqltypes.VARBINARY: _VARBINARY_pyodbc,
sqltypes.LargeBinary: _VARBINARY_pyodbc,
- }
+ },
)
- def __init__(self, description_encoding=None, fast_executemany=False,
- **params):
- if 'description_encoding' in params:
- self.description_encoding = params.pop('description_encoding')
+ def __init__(
+ self, description_encoding=None, fast_executemany=False, **params
+ ):
+ if "description_encoding" in params:
+ self.description_encoding = params.pop("description_encoding")
super(MSDialect_pyodbc, self).__init__(**params)
- self.use_scope_identity = self.use_scope_identity and \
- self.dbapi and \
- hasattr(self.dbapi.Cursor, 'nextset')
- self._need_decimal_fix = self.dbapi and \
- self._dbapi_version() < (2, 1, 8)
+ self.use_scope_identity = (
+ self.use_scope_identity
+ and self.dbapi
+ and hasattr(self.dbapi.Cursor, "nextset")
+ )
+ self._need_decimal_fix = self.dbapi and self._dbapi_version() < (
+ 2,
+ 1,
+ 8,
+ )
self.fast_executemany = fast_executemany
def _get_server_version_info(self, connection):
@@ -308,16 +316,18 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
# "Version of the instance of SQL Server, in the form
# of 'major.minor.build.revision'"
raw = connection.scalar(
- "SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)")
+ "SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)"
+ )
except exc.DBAPIError:
# SQL Server docs indicate this function isn't present prior to
# 2008. Before we had the VARCHAR cast above, pyodbc would also
# fail on this query.
- return super(MSDialect_pyodbc, self).\
- _get_server_version_info(connection, allow_chars=False)
+ return super(MSDialect_pyodbc, self)._get_server_version_info(
+ connection, allow_chars=False
+ )
else:
version = []
- r = re.compile(r'[.\-]')
+ r = re.compile(r"[.\-]")
for n in r.split(raw):
try:
version.append(int(n))
@@ -329,17 +339,27 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
if self.fast_executemany:
cursor.fast_executemany = True
super(MSDialect_pyodbc, self).do_executemany(
- cursor, statement, parameters, context=context)
+ cursor, statement, parameters, context=context
+ )
def is_disconnect(self, e, connection, cursor):
if isinstance(e, self.dbapi.Error):
for code in (
- '08S01', '01002', '08003', '08007',
- '08S02', '08001', 'HYT00', 'HY010',
- '10054'):
+ "08S01",
+ "01002",
+ "08003",
+ "08007",
+ "08S02",
+ "08001",
+ "HYT00",
+ "HY010",
+ "10054",
+ ):
if code in str(e):
return True
return super(MSDialect_pyodbc, self).is_disconnect(
- e, connection, cursor)
+ e, connection, cursor
+ )
+
dialect = MSDialect_pyodbc