diff options
author | Diana Clarke <diana.joan.clarke@gmail.com> | 2012-11-20 00:47:31 -0500 |
---|---|---|
committer | Diana Clarke <diana.joan.clarke@gmail.com> | 2012-11-20 00:47:31 -0500 |
commit | ead37e4ec0dd5750769226befea043d9527f869e (patch) | |
tree | 4edd39d12a4b8d1825ed3e1f4764941dcd813ef1 | |
parent | 63a953e59dbd3389f96c2ab39aa149dc0ba063e4 (diff) | |
download | sqlalchemy-ead37e4ec0dd5750769226befea043d9527f869e.tar.gz |
kill me now, pep8 pass, so close
19 files changed, 175 insertions, 168 deletions
diff --git a/lib/sqlalchemy/dialects/__init__.py b/lib/sqlalchemy/dialects/__init__.py index af0dc37ea..61cb4e1a1 100644 --- a/lib/sqlalchemy/dialects/__init__.py +++ b/lib/sqlalchemy/dialects/__init__.py @@ -43,4 +43,4 @@ def _auto_fn(name): else: return None -registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn)
\ No newline at end of file +registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn) diff --git a/lib/sqlalchemy/dialects/firebird/__init__.py b/lib/sqlalchemy/dialects/firebird/__init__.py index f79588d24..6b2c6878d 100644 --- a/lib/sqlalchemy/dialects/firebird/__init__.py +++ b/lib/sqlalchemy/dialects/firebird/__init__.py @@ -18,5 +18,3 @@ __all__ = ( 'TEXT', 'NUMERIC', 'FLOAT', 'TIMESTAMP', 'VARCHAR', 'CHAR', 'BLOB', 'dialect' ) - - diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index d9cdf72db..9a8e8044a 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -69,7 +69,7 @@ the SQLAlchemy ``returning()`` method, such as:: """ -import datetime, re +import datetime from sqlalchemy import schema as sa_schema from sqlalchemy import exc, types as sqltypes, sql, util diff --git a/lib/sqlalchemy/dialects/firebird/fdb.py b/lib/sqlalchemy/dialects/firebird/fdb.py index ce872d562..b9356b3a3 100644 --- a/lib/sqlalchemy/dialects/firebird/fdb.py +++ b/lib/sqlalchemy/dialects/firebird/fdb.py @@ -64,4 +64,4 @@ class FBDialect_fdb(FBDialect_kinterbasdb): return self._parse_version_info(version) -dialect = FBDialect_fdb
\ No newline at end of file +dialect = FBDialect_fdb diff --git a/lib/sqlalchemy/dialects/informix/__init__.py b/lib/sqlalchemy/dialects/informix/__init__.py index e500bea55..798ae94a6 100644 --- a/lib/sqlalchemy/dialects/informix/__init__.py +++ b/lib/sqlalchemy/dialects/informix/__init__.py @@ -6,4 +6,4 @@ from sqlalchemy.dialects.informix import base, informixdb -base.dialect = informixdb.dialect
\ No newline at end of file +base.dialect = informixdb.dialect diff --git a/lib/sqlalchemy/dialects/informix/base.py b/lib/sqlalchemy/dialects/informix/base.py index 0b82519a6..c3fbccb11 100644 --- a/lib/sqlalchemy/dialects/informix/base.py +++ b/lib/sqlalchemy/dialects/informix/base.py @@ -175,7 +175,7 @@ class InfoTime(sqltypes.Time): return process colspecs = { - sqltypes.DateTime : InfoDateTime, + sqltypes.DateTime: InfoDateTime, sqltypes.TIMESTAMP: InfoDateTime, sqltypes.Time: InfoTime, } @@ -352,7 +352,7 @@ class InformixIdentifierPreparer(compiler.IdentifierPreparer): class InformixDialect(default.DefaultDialect): name = 'informix' - max_identifier_length = 128 # adjusts at runtime based on server version + max_identifier_length = 128 # adjusts at runtime based on server version type_compiler = InfoTypeCompiler statement_compiler = InfoSQLCompiler @@ -445,14 +445,14 @@ class InformixDialect(default.DefaultDialect): if coltype not in (0, 13) and default: default = default.split()[-1] - if coltype == 6: # Serial, mark as autoincrement + if coltype == 6: # Serial, mark as autoincrement autoincrement = True - if coltype == 0 or coltype == 13: # char, varchar + if coltype == 0 or coltype == 13: # char, varchar coltype = ischema_names[coltype](collength) if default: default = "'%s'" % default - elif coltype == 5: # decimal + elif coltype == 5: # decimal precision, scale = (collength & 0xFF00) >> 8, collength & 0xFF if scale == 255: scale = 0 @@ -496,11 +496,11 @@ class InformixDialect(default.DefaultDialect): def fkey_rec(): return { - 'name' : None, - 'constrained_columns' : [], - 'referred_schema' : None, - 'referred_table' : None, - 'referred_columns' : [] + 'name': None, + 'constrained_columns': [], + 'referred_schema': None, + 'referred_table': None, + 'referred_columns': [] } fkeys = util.defaultdict(fkey_rec) diff --git a/lib/sqlalchemy/dialects/mssql/__init__.py b/lib/sqlalchemy/dialects/mssql/__init__.py index e262d208b..bad9b72c8 100644 --- a/lib/sqlalchemy/dialects/mssql/__init__.py +++ b/lib/sqlalchemy/dialects/mssql/__init__.py @@ -23,4 +23,4 @@ __all__ = ( 'DATETIME2', 'DATETIMEOFFSET', 'DATE', 'TIME', 'SMALLDATETIME', 'BINARY', 'VARBINARY', 'BIT', 'REAL', 'IMAGE', 'TIMESTAMP', 'MONEY', 'SMALLMONEY', 'UNIQUEIDENTIFIER', 'SQL_VARIANT', 'dialect' -)
\ No newline at end of file +) diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py index 294402c06..2b864db96 100644 --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py @@ -59,18 +59,18 @@ class MSDialect_adodbapi(MSDialect): connectors = ["Provider=SQLOLEDB"] if 'port' in keys: - connectors.append ("Data Source=%s, %s" % + connectors.append("Data Source=%s, %s" % (keys.get("host"), keys.get("port"))) else: - connectors.append ("Data Source=%s" % keys.get("host")) - connectors.append ("Initial Catalog=%s" % keys.get("database")) + connectors.append("Data Source=%s" % keys.get("host")) + connectors.append("Initial Catalog=%s" % keys.get("database")) user = keys.get("user") if user: connectors.append("User Id=%s" % user) connectors.append("Password=%s" % keys.get("password", "")) else: connectors.append("Integrated Security=SSPI") - return [[";".join (connectors)], {}] + return [[";".join(connectors)], {}] def is_disconnect(self, e, connection, cursor): return isinstance(e, self.dbapi.adodbapi.DatabaseError) and \ diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 10878c0f5..f55ae4644 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -245,6 +245,7 @@ class _MSDate(sqltypes.Date): return process _reg = re.compile(r"(\d+)-(\d+)-(\d+)") + def result_processor(self, dialect, coltype): def process(value): if isinstance(value, datetime.datetime): @@ -277,6 +278,7 @@ class TIME(sqltypes.TIME): return process _reg = re.compile(r"(\d+):(\d+):(\d+)(?:\.(\d{0,6}))?") + def result_processor(self, dialect, coltype): def process(value): if isinstance(value, datetime.datetime): @@ -505,30 +507,30 @@ MSUniqueIdentifier = UNIQUEIDENTIFIER MSVariant = SQL_VARIANT ischema_names = { - 'int' : INTEGER, + 'int': INTEGER, 'bigint': BIGINT, - 'smallint' : SMALLINT, - 'tinyint' : TINYINT, - 'varchar' : VARCHAR, - 'nvarchar' : NVARCHAR, - 'char' : CHAR, - 'nchar' : NCHAR, - 'text' : TEXT, - 'ntext' : NTEXT, - 'decimal' : DECIMAL, - 'numeric' : NUMERIC, - 'float' : FLOAT, - 'datetime' : DATETIME, - 'datetime2' : DATETIME2, - 'datetimeoffset' : DATETIMEOFFSET, + 'smallint': SMALLINT, + 'tinyint': TINYINT, + 'varchar': VARCHAR, + 'nvarchar': NVARCHAR, + 'char': CHAR, + 'nchar': NCHAR, + 'text': TEXT, + 'ntext': NTEXT, + 'decimal': DECIMAL, + 'numeric': NUMERIC, + 'float': FLOAT, + 'datetime': DATETIME, + 'datetime2': DATETIME2, + 'datetimeoffset': DATETIMEOFFSET, 'date': DATE, 'time': TIME, - 'smalldatetime' : SMALLDATETIME, - 'binary' : BINARY, - 'varbinary' : VARBINARY, + 'smalldatetime': SMALLDATETIME, + 'binary': BINARY, + 'varbinary': VARBINARY, 'bit': BIT, - 'real' : REAL, - 'image' : IMAGE, + 'real': REAL, + 'image': IMAGE, 'timestamp': TIMESTAMP, 'money': MONEY, 'smallmoney': SMALLMONEY, @@ -604,8 +606,7 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): return self._extend("TEXT", type_) def visit_VARCHAR(self, type_): - return self._extend("VARCHAR", type_, - length = type_.length or 'max') + return self._extend("VARCHAR", type_, length=type_.length or 'max') def visit_CHAR(self, type_): return self._extend("CHAR", type_) @@ -614,8 +615,7 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): return self._extend("NCHAR", type_) def visit_NVARCHAR(self, type_): - return self._extend("NVARCHAR", type_, - length = type_.length or 'max') + return self._extend("NVARCHAR", type_, length=type_.length or 'max') def visit_date(self, type_): if self.dialect.server_version_info < MS_2008_VERSION: @@ -1118,9 +1118,9 @@ class MSDialect(default.DefaultDialect): schema_name = "dbo" colspecs = { - sqltypes.DateTime : _MSDateTime, - sqltypes.Date : _MSDate, - sqltypes.Time : TIME, + sqltypes.DateTime: _MSDateTime, + sqltypes.Date: _MSDate, + sqltypes.Time: TIME, } ischema_names = ischema_names @@ -1169,7 +1169,7 @@ class MSDialect(default.DefaultDialect): "behaviors may not function properly. If using ODBC " "with FreeTDS, ensure server version 7.0 or 8.0, not 4.2, " "is configured in the FreeTDS configuration." % - ".".join(str(x) for x in self.server_version_info) ) + ".".join(str(x) for x in self.server_version_info)) if self.server_version_info >= MS_2005_VERSION and \ 'implicit_returning' not in self.__dict__: self.implicit_returning = True @@ -1268,7 +1268,7 @@ class MSDialect(default.DefaultDialect): sql.bindparam('schname', owner, sqltypes.String(convert_unicode=True)) ], - typemap = { + typemap={ 'name': sqltypes.Unicode() } ) @@ -1297,9 +1297,7 @@ class MSDialect(default.DefaultDialect): sql.bindparam('schname', owner, sqltypes.String(convert_unicode=True)) ], - typemap = { - 'name': sqltypes.Unicode() - } + typemap={'name': sqltypes.Unicode()} ), ) for row in rp: @@ -1389,10 +1387,10 @@ class MSDialect(default.DefaultDialect): coltype = coltype(**kwargs) cdict = { - 'name' : name, - 'type' : coltype, - 'nullable' : nullable, - 'default' : default, + 'name': name, + 'type': coltype, + 'nullable': nullable, + 'default': default, 'autoincrement': False, } cols.append(cdict) @@ -1476,9 +1474,8 @@ class MSDialect(default.DefaultDialect): RR.c.unique_constraint_name, C.c.ordinal_position == R.c.ordinal_position ), - order_by= [ - RR.c.constraint_name, - R.c.ordinal_position]) + order_by=[RR.c.constraint_name, R.c.ordinal_position] + ) # group rows by constraint ID, to handle multi-column FKs fkeys = [] @@ -1515,4 +1512,3 @@ class MSDialect(default.DefaultDialect): remote_cols.append(rcol) return fkeys.values() - diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index bd88a67d8..85d9e501d 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -94,4 +94,3 @@ views = Table("VIEWS", ischema, Column("CHECK_OPTION", String, key="check_option"), Column("IS_UPDATABLE", String, key="is_updatable"), schema="INFORMATION_SCHEMA") - diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py index 3c8bb307d..e210d97de 100644 --- a/lib/sqlalchemy/dialects/mssql/mxodbc.py +++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py @@ -98,10 +98,10 @@ class MSDialect_mxodbc(MxODBCConnector, MSDialect): _need_decimal_fix = True colspecs = { - sqltypes.Numeric : _MSNumeric_mxodbc, - sqltypes.DateTime : _MSDateTime, - sqltypes.Date : _MSDate_mxodbc, - sqltypes.Time : _MSTime_mxodbc, + sqltypes.Numeric: _MSNumeric_mxodbc, + sqltypes.DateTime: _MSDateTime, + sqltypes.Date: _MSDate_mxodbc, + sqltypes.Time: _MSTime_mxodbc, } def __init__(self, description_encoding=None, **params): @@ -109,4 +109,3 @@ class MSDialect_mxodbc(MxODBCConnector, MSDialect): self.description_encoding = description_encoding dialect = MSDialect_mxodbc - diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py index 71aa7c188..eb795200d 100644 --- a/lib/sqlalchemy/dialects/mssql/pymssql.py +++ b/lib/sqlalchemy/dialects/mssql/pymssql.py @@ -48,6 +48,7 @@ class MSDialect_pymssql(MSDialect): sqltypes.Float: sqltypes.Float, } ) + @classmethod def dbapi(cls): module = __import__('pymssql') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index f8981fc96..dc2ae7515 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -339,10 +339,10 @@ RESERVED_WORDS = set( 'union', 'unique', 'unlock', 'unsigned', 'update', 'usage', 'use', 'using', 'utc_date', 'utc_time', 'utc_timestamp', 'values', 'varbinary', 'varchar', 'varcharacter', 'varying', 'when', 'where', 'while', 'with', - 'write', 'x509', 'xor', 'year_month', 'zerofill', # 5.0 - 'columns', 'fields', 'privileges', 'soname', 'tables', # 4.1 + 'write', 'x509', 'xor', 'year_month', 'zerofill', # 5.0 + 'columns', 'fields', 'privileges', 'soname', 'tables', # 4.1 'accessible', 'linear', 'master_ssl_verify_server_cert', 'range', - 'read_only', 'read_write', # 5.1 + 'read_only', 'read_write', # 5.1 ]) AUTOCOMMIT_RE = re.compile( @@ -708,6 +708,7 @@ class TIME(sqltypes.TIME): def result_processor(self, dialect, coltype): time = datetime.time + def process(value): # convert from a timedelta value if value is not None: @@ -1093,6 +1094,7 @@ class ENUM(sqltypes.Enum, _StringType): def bind_processor(self, dialect): super_convert = super(ENUM, self).bind_processor(dialect) + def process(value): if self.strict and value is not None and value not in self.enums: raise exc.InvalidRequestError('"%s" not a valid value for ' @@ -1180,6 +1182,7 @@ class SET(_StringType): def bind_processor(self, dialect): super_convert = super(SET, self).bind_processor(dialect) + def process(value): if value is None or isinstance(value, (int, long, basestring)): pass @@ -1285,9 +1288,7 @@ class MySQLCompiler(compiler.SQLCompiler): """Overridden from base SQLCompiler value""" extract_map = compiler.SQLCompiler.extract_map.copy() - extract_map.update ({ - 'milliseconds': 'millisecond', - }) + extract_map.update({'milliseconds': 'millisecond'}) def visit_random_func(self, fn, **kw): return "rand%s" % self.function_argspec(fn) @@ -1650,7 +1651,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler): else: return self._extend_numeric(type_, "NUMERIC(%(precision)s, %(scale)s)" % - {'precision': type_.precision, 'scale' : type_.scale}) + {'precision': type_.precision, 'scale': type_.scale}) def visit_DECIMAL(self, type_): if type_.precision is None: @@ -1662,13 +1663,13 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler): else: return self._extend_numeric(type_, "DECIMAL(%(precision)s, %(scale)s)" % - {'precision': type_.precision, 'scale' : type_.scale}) + {'precision': type_.precision, 'scale': type_.scale}) def visit_DOUBLE(self, type_): if type_.precision is not None and type_.scale is not None: return self._extend_numeric(type_, "DOUBLE(%(precision)s, %(scale)s)" % {'precision': type_.precision, - 'scale' : type_.scale}) + 'scale': type_.scale}) else: return self._extend_numeric(type_, 'DOUBLE') @@ -1676,7 +1677,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler): if type_.precision is not None and type_.scale is not None: return self._extend_numeric(type_, "REAL(%(precision)s, %(scale)s)" % {'precision': type_.precision, - 'scale' : type_.scale}) + 'scale': type_.scale}) else: return self._extend_numeric(type_, 'REAL') @@ -2150,12 +2151,12 @@ class MySQLDialect(default.DefaultDialect): con_kw[opt] = spec[opt] fkey_d = { - 'name' : spec['name'], - 'constrained_columns' : loc_names, - 'referred_schema' : ref_schema, - 'referred_table' : ref_name, - 'referred_columns' : ref_names, - 'options' : con_kw + 'name': spec['name'], + 'constrained_columns': loc_names, + 'referred_schema': ref_schema, + 'referred_table': ref_name, + 'referred_columns': ref_names, + 'options': con_kw } fkeys.append(fkey_d) return fkeys @@ -2818,4 +2819,3 @@ def _re_compile(regex): """Compile a string to regex, I and UNICODE.""" return re.compile(regex, re.I | re.UNICODE) - diff --git a/lib/sqlalchemy/dialects/mysql/gaerdbms.py b/lib/sqlalchemy/dialects/mysql/gaerdbms.py index 66180e233..25201fee6 100644 --- a/lib/sqlalchemy/dialects/mysql/gaerdbms.py +++ b/lib/sqlalchemy/dialects/mysql/gaerdbms.py @@ -52,4 +52,4 @@ class MySQLDialect_gaerdbms(MySQLDialect_mysqldb): if code: return int(code) -dialect = MySQLDialect_gaerdbms
\ No newline at end of file +dialect = MySQLDialect_gaerdbms diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py index 8e4fe2383..ca4986d62 100644 --- a/lib/sqlalchemy/dialects/mysql/oursql.py +++ b/lib/sqlalchemy/dialects/mysql/oursql.py @@ -126,63 +126,67 @@ class MySQLDialect_oursql(MySQLDialect): # Q: why didn't we need all these "plain_query" overrides earlier ? # am i on a newer/older version of OurSQL ? def has_table(self, connection, table_name, schema=None): - return MySQLDialect.has_table(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - table_name, schema) + return MySQLDialect.has_table( + self, + connection.connect().execution_options(_oursql_plain_query=True), + table_name, + schema + ) def get_table_options(self, connection, table_name, schema=None, **kw): - return MySQLDialect.get_table_options(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - table_name, - schema = schema, - **kw + return MySQLDialect.get_table_options( + self, + connection.connect().execution_options(_oursql_plain_query=True), + table_name, + schema=schema, + **kw ) def get_columns(self, connection, table_name, schema=None, **kw): - return MySQLDialect.get_columns(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - table_name, - schema=schema, - **kw + return MySQLDialect.get_columns( + self, + connection.connect().execution_options(_oursql_plain_query=True), + table_name, + schema=schema, + **kw ) def get_view_names(self, connection, schema=None, **kw): - return MySQLDialect.get_view_names(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - schema=schema, - **kw + return MySQLDialect.get_view_names( + self, + connection.connect().execution_options(_oursql_plain_query=True), + schema=schema, + **kw ) def get_table_names(self, connection, schema=None, **kw): - return MySQLDialect.get_table_names(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - schema + return MySQLDialect.get_table_names( + self, + connection.connect().execution_options(_oursql_plain_query=True), + schema ) def get_schema_names(self, connection, **kw): - return MySQLDialect.get_schema_names(self, - connection.connect().\ - execution_options(_oursql_plain_query=True), - **kw + return MySQLDialect.get_schema_names( + self, + connection.connect().execution_options(_oursql_plain_query=True), + **kw ) def initialize(self, connection): return MySQLDialect.initialize( - self, - connection.execution_options(_oursql_plain_query=True) - ) + self, + connection.execution_options(_oursql_plain_query=True) + ) def _show_create_table(self, connection, table, charset=None, full_name=None): - return MySQLDialect._show_create_table(self, - connection.contextual_connect(close_with_result=True). - execution_options(_oursql_plain_query=True), - table, charset, full_name) + return MySQLDialect._show_create_table( + self, + connection.contextual_connect(close_with_result=True). + execution_options(_oursql_plain_query=True), + table, charset, full_name + ) def is_disconnect(self, e, connection, cursor): if isinstance(e, self.dbapi.ProgrammingError): diff --git a/lib/sqlalchemy/dialects/mysql/pymysql.py b/lib/sqlalchemy/dialects/mysql/pymysql.py index 818bb7e3b..3989d037c 100644 --- a/lib/sqlalchemy/dialects/mysql/pymysql.py +++ b/lib/sqlalchemy/dialects/mysql/pymysql.py @@ -28,8 +28,9 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb): driver = 'pymysql' description_encoding = None + @classmethod def dbapi(cls): return __import__('pymysql') -dialect = MySQLDialect_pymysql
\ No newline at end of file +dialect = MySQLDialect_pymysql diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 1daea3cef..baea4815b 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -139,10 +139,9 @@ is not in use this flag should be left off. """ -import random, re +import re -from sqlalchemy import schema as sa_schema -from sqlalchemy import util, sql, log +from sqlalchemy import util, sql from sqlalchemy.engine import default, base, reflection from sqlalchemy.sql import compiler, visitors, expression from sqlalchemy.sql import operators as sql_operators, functions as sql_functions @@ -205,6 +204,7 @@ class NUMBER(sqltypes.Numeric, sqltypes.Integer): class DOUBLE_PRECISION(sqltypes.Numeric): __visit_name__ = 'DOUBLE_PRECISION' + def __init__(self, precision=None, scale=None, asdecimal=None): if asdecimal is None: asdecimal = False @@ -265,27 +265,27 @@ class _OracleBoolean(sqltypes.Boolean): return dbapi.NUMBER colspecs = { - sqltypes.Boolean : _OracleBoolean, - sqltypes.Interval : INTERVAL, + sqltypes.Boolean: _OracleBoolean, + sqltypes.Interval: INTERVAL, } ischema_names = { - 'VARCHAR2' : VARCHAR, - 'NVARCHAR2' : NVARCHAR, - 'CHAR' : CHAR, - 'DATE' : DATE, - 'NUMBER' : NUMBER, - 'BLOB' : BLOB, - 'BFILE' : BFILE, - 'CLOB' : CLOB, - 'NCLOB' : NCLOB, - 'TIMESTAMP' : TIMESTAMP, - 'TIMESTAMP WITH TIME ZONE' : TIMESTAMP, - 'INTERVAL DAY TO SECOND' : INTERVAL, - 'RAW' : RAW, - 'FLOAT' : FLOAT, - 'DOUBLE PRECISION' : DOUBLE_PRECISION, - 'LONG' : LONG, + 'VARCHAR2': VARCHAR, + 'NVARCHAR2': NVARCHAR, + 'CHAR': CHAR, + 'DATE': DATE, + 'NUMBER': NUMBER, + 'BLOB': BLOB, + 'BFILE': BFILE, + 'CLOB': CLOB, + 'NCLOB': NCLOB, + 'TIMESTAMP': TIMESTAMP, + 'TIMESTAMP WITH TIME ZONE': TIMESTAMP, + 'INTERVAL DAY TO SECOND': INTERVAL, + 'RAW': RAW, + 'FLOAT': FLOAT, + 'DOUBLE PRECISION': DOUBLE_PRECISION, + 'LONG': LONG, } @@ -389,7 +389,7 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler): def visit_RAW(self, type_): if type_.length: - return "RAW(%(length)s)" % {'length' : type_.length} + return "RAW(%(length)s)" % {'length': type_.length} else: return "RAW" @@ -910,7 +910,7 @@ class OracleDialect(default.DefaultDialect): (colname, orig_colname, coltype, length, precision, scale, nullable, default) = \ (self.normalize_name(row[0]), row[0], row[1], row[2], row[3], row[4], row[5] == 'Y', row[6]) - if coltype == 'NUMBER' : + if coltype == 'NUMBER': coltype = NUMBER(precision, scale) elif coltype in ('VARCHAR2', 'NVARCHAR2', 'CHAR'): coltype = self.ischema_names.get(coltype)(length) @@ -1066,7 +1066,7 @@ class OracleDialect(default.DefaultDialect): """ - requested_schema = schema # to check later on + requested_schema = schema # to check later on resolve_synonyms = kw.get('oracle_resolve_synonyms', False) dblink = kw.get('dblink', '') info_cache = kw.get('info_cache') @@ -1082,11 +1082,11 @@ class OracleDialect(default.DefaultDialect): def fkey_rec(): return { - 'name' : None, - 'constrained_columns' : [], - 'referred_schema' : None, - 'referred_table' : None, - 'referred_columns' : [] + 'name': None, + 'constrained_columns': [], + 'referred_schema': None, + 'referred_table': None, + 'referred_columns': [] } fkeys = util.defaultdict(fkey_rec) diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index e7b182c66..bee730800 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -182,6 +182,7 @@ class _OracleNumeric(sqltypes.Numeric): fstring = "%.10f" else: fstring = "%%.%df" % self.scale + def to_decimal(value): if value is None: return None @@ -189,6 +190,7 @@ class _OracleNumeric(sqltypes.Numeric): return value else: return decimal.Decimal(fstring % value) + return to_decimal else: if self.precision is None and self.scale is None: @@ -486,21 +488,24 @@ class OracleDialect_cx_oracle(OracleDialect): colspecs = colspecs = { sqltypes.Numeric: _OracleNumeric, - sqltypes.Date : _OracleDate, # generic type, assume datetime.date is desired + sqltypes.Date: _OracleDate, # generic type, assume datetime.date is desired oracle.DATE: oracle.DATE, # non generic type - passthru - sqltypes.LargeBinary : _OracleBinary, - sqltypes.Boolean : oracle._OracleBoolean, - sqltypes.Interval : _OracleInterval, - oracle.INTERVAL : _OracleInterval, - sqltypes.Text : _OracleText, - sqltypes.String : _OracleString, - sqltypes.UnicodeText : _OracleUnicodeText, - sqltypes.CHAR : _OracleChar, - sqltypes.Integer : _OracleInteger, # this is only needed for OUT parameters. - # it would be nice if we could not use it otherwise. + sqltypes.LargeBinary: _OracleBinary, + sqltypes.Boolean: oracle._OracleBoolean, + sqltypes.Interval: _OracleInterval, + oracle.INTERVAL: _OracleInterval, + sqltypes.Text: _OracleText, + sqltypes.String: _OracleString, + sqltypes.UnicodeText: _OracleUnicodeText, + sqltypes.CHAR: _OracleChar, + + # this is only needed for OUT parameters. + # it would be nice if we could not use it otherwise. + sqltypes.Integer: _OracleInteger, + oracle.RAW: _OracleRaw, sqltypes.Unicode: _OracleNVarChar, - sqltypes.NVARCHAR : _OracleNVarChar, + sqltypes.NVARCHAR: _OracleNVarChar, oracle.ROWID: _OracleRowid, } @@ -588,6 +593,7 @@ class OracleDialect_cx_oracle(OracleDialect): self.dbapi.BLOB: oracle.BLOB(), self.dbapi.BINARY: oracle.RAW(), } + @classmethod def dbapi(cls): import cx_Oracle @@ -653,6 +659,7 @@ class OracleDialect_cx_oracle(OracleDialect): return cx_Oracle = self.dbapi + def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal diff --git a/lib/sqlalchemy/dialects/oracle/zxjdbc.py b/lib/sqlalchemy/dialects/oracle/zxjdbc.py index 7c828331b..94d8f8219 100644 --- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py +++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py @@ -78,7 +78,7 @@ class OracleCompiler_zxjdbc(OracleCompiler): self.binds[bindparam.key] = bindparam binds.append(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): @@ -178,7 +178,7 @@ class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect): colspecs = util.update_copy( OracleDialect.colspecs, { - sqltypes.Date : _ZxJDBCDate, + sqltypes.Date: _ZxJDBCDate, sqltypes.Numeric: _ZxJDBCNumeric } ) @@ -189,17 +189,19 @@ class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect): from java.sql import SQLException from com.ziclix.python.sql import zxJDBC from com.ziclix.python.sql.handler import OracleDataHandler - class OracleReturningDataHandler(OracleDataHandler): + class OracleReturningDataHandler(OracleDataHandler): """zxJDBC DataHandler that specially handles ReturningParam.""" def setJDBCObject(self, statement, index, object, dbtype=None): if type(object) is ReturningParam: statement.registerReturnParameter(index, object.type) elif dbtype is None: - OracleDataHandler.setJDBCObject(self, statement, index, object) + OracleDataHandler.setJDBCObject( + self, statement, index, object) else: - OracleDataHandler.setJDBCObject(self, statement, index, object, dbtype) + OracleDataHandler.setJDBCObject( + self, statement, index, object, dbtype) self.DataHandler = OracleReturningDataHandler def initialize(self, connection): |