summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/oracle/zxjdbc.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/oracle/zxjdbc.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/oracle/zxjdbc.py')
-rw-r--r--lib/sqlalchemy/dialects/oracle/zxjdbc.py102
1 files changed, 60 insertions, 42 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/zxjdbc.py b/lib/sqlalchemy/dialects/oracle/zxjdbc.py
index aa2562573..0a365f8b0 100644
--- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py
+++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py
@@ -21,9 +21,11 @@ import re
from sqlalchemy import sql, types as sqltypes, util
from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
-from sqlalchemy.dialects.oracle.base import (OracleCompiler,
- OracleDialect,
- OracleExecutionContext)
+from sqlalchemy.dialects.oracle.base import (
+ OracleCompiler,
+ OracleDialect,
+ OracleExecutionContext,
+)
from sqlalchemy.engine import result as _result
from sqlalchemy.sql import expression
import collections
@@ -32,92 +34,100 @@ SQLException = zxJDBC = None
class _ZxJDBCDate(sqltypes.Date):
-
def result_processor(self, dialect, coltype):
def process(value):
if value is None:
return None
else:
return value.date()
+
return process
class _ZxJDBCNumeric(sqltypes.Numeric):
-
def result_processor(self, dialect, coltype):
# XXX: does the dialect return Decimal or not???
# if it does (in all cases), we could use a None processor as well as
# the to_float generic processor
if self.asdecimal:
+
def process(value):
if isinstance(value, decimal.Decimal):
return value
else:
return decimal.Decimal(str(value))
+
else:
+
def process(value):
if isinstance(value, decimal.Decimal):
return float(value)
else:
return value
+
return process
class OracleCompiler_zxjdbc(OracleCompiler):
-
def returning_clause(self, stmt, returning_cols):
self.returning_cols = list(
- expression._select_iterables(returning_cols))
+ expression._select_iterables(returning_cols)
+ )
# within_columns_clause=False so that labels (foo AS bar) don't render
- columns = [self.process(c, within_columns_clause=False)
- for c in self.returning_cols]
+ columns = [
+ self.process(c, within_columns_clause=False)
+ for c in self.returning_cols
+ ]
- if not hasattr(self, 'returning_parameters'):
+ if not hasattr(self, "returning_parameters"):
self.returning_parameters = []
binds = []
for i, col in enumerate(self.returning_cols):
- dbtype = col.type.dialect_impl(
- self.dialect).get_dbapi_type(self.dialect.dbapi)
+ dbtype = col.type.dialect_impl(self.dialect).get_dbapi_type(
+ self.dialect.dbapi
+ )
self.returning_parameters.append((i + 1, dbtype))
bindparam = sql.bindparam(
- "ret_%d" % i, value=ReturningParam(dbtype))
+ "ret_%d" % i, value=ReturningParam(dbtype)
+ )
self.binds[bindparam.key] = bindparam
binds.append(
- self.bindparam_string(self._truncate_bindparam(bindparam)))
+ self.bindparam_string(self._truncate_bindparam(bindparam))
+ )
- return 'RETURNING ' + ', '.join(columns) + " INTO " + ", ".join(binds)
+ return "RETURNING " + ", ".join(columns) + " INTO " + ", ".join(binds)
class OracleExecutionContext_zxjdbc(OracleExecutionContext):
-
def pre_exec(self):
- if hasattr(self.compiled, 'returning_parameters'):
+ if hasattr(self.compiled, "returning_parameters"):
# prepare a zxJDBC statement so we can grab its underlying
# OraclePreparedStatement's getReturnResultSet later
self.statement = self.cursor.prepare(self.statement)
def get_result_proxy(self):
- if hasattr(self.compiled, 'returning_parameters'):
+ if hasattr(self.compiled, "returning_parameters"):
rrs = None
try:
try:
rrs = self.statement.__statement__.getReturnResultSet()
next(rrs)
except SQLException as sqle:
- msg = '%s [SQLCode: %d]' % (
- sqle.getMessage(), sqle.getErrorCode())
+ msg = "%s [SQLCode: %d]" % (
+ sqle.getMessage(),
+ sqle.getErrorCode(),
+ )
if sqle.getSQLState() is not None:
- msg += ' [SQLState: %s]' % sqle.getSQLState()
+ msg += " [SQLState: %s]" % sqle.getSQLState()
raise zxJDBC.Error(msg)
else:
row = tuple(
- self.cursor.datahandler.getPyObject(
- rrs, index, dbtype)
- for index, dbtype in
- self.compiled.returning_parameters)
+ self.cursor.datahandler.getPyObject(rrs, index, dbtype)
+ for index, dbtype in self.compiled.returning_parameters
+ )
return ReturningResultProxy(self, row)
finally:
if rrs is not None:
@@ -146,7 +156,7 @@ class ReturningResultProxy(_result.FullyBufferedResultProxy):
def _cursor_description(self):
ret = []
for c in self.context.compiled.returning_cols:
- if hasattr(c, 'name'):
+ if hasattr(c, "name"):
ret.append((c.name, c.type))
else:
ret.append((c.anon_label, c.type))
@@ -178,23 +188,24 @@ class ReturningParam(object):
def __repr__(self):
kls = self.__class__
- return '<%s.%s object at 0x%x type=%s>' % (
- kls.__module__, kls.__name__, id(self), self.type)
+ return "<%s.%s object at 0x%x type=%s>" % (
+ kls.__module__,
+ kls.__name__,
+ id(self),
+ self.type,
+ )
class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect):
- jdbc_db_name = 'oracle'
- jdbc_driver_name = 'oracle.jdbc.OracleDriver'
+ jdbc_db_name = "oracle"
+ jdbc_driver_name = "oracle.jdbc.OracleDriver"
statement_compiler = OracleCompiler_zxjdbc
execution_ctx_cls = OracleExecutionContext_zxjdbc
colspecs = util.update_copy(
OracleDialect.colspecs,
- {
- sqltypes.Date: _ZxJDBCDate,
- sqltypes.Numeric: _ZxJDBCNumeric
- }
+ {sqltypes.Date: _ZxJDBCDate, sqltypes.Numeric: _ZxJDBCNumeric},
)
def __init__(self, *args, **kwargs):
@@ -212,24 +223,31 @@ class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect):
statement.registerReturnParameter(index, object.type)
elif dbtype is None:
OracleDataHandler.setJDBCObject(
- self, statement, index, object)
+ self, statement, index, object
+ )
else:
OracleDataHandler.setJDBCObject(
- self, statement, index, object, dbtype)
+ self, statement, index, object, dbtype
+ )
+
self.DataHandler = OracleReturningDataHandler
def initialize(self, connection):
super(OracleDialect_zxjdbc, self).initialize(connection)
- self.implicit_returning = \
- connection.connection.driverversion >= '10.2'
+ self.implicit_returning = connection.connection.driverversion >= "10.2"
def _create_jdbc_url(self, url):
- return 'jdbc:oracle:thin:@%s:%s:%s' % (
- url.host, url.port or 1521, url.database)
+ return "jdbc:oracle:thin:@%s:%s:%s" % (
+ url.host,
+ url.port or 1521,
+ url.database,
+ )
def _get_server_version_info(self, connection):
version = re.search(
- r'Release ([\d\.]+)', connection.connection.dbversion).group(1)
- return tuple(int(x) for x in version.split('.'))
+ r"Release ([\d\.]+)", connection.connection.dbversion
+ ).group(1)
+ return tuple(int(x) for x in version.split("."))
+
dialect = OracleDialect_zxjdbc