diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
| commit | 350aed3fdb9f1e73e69655e53f44ca6a91c196da (patch) | |
| tree | 3d2a128667b5f6ca6d0b4e1f4865fc98aac6b60b /lib/sqlalchemy/dialects/mssql | |
| parent | 71f92436bdc86f30e2c21d8f5244733601e8c39e (diff) | |
| download | sqlalchemy-350aed3fdb9f1e73e69655e53f44ca6a91c196da.tar.gz | |
- whitespace removal bonanza
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/adodbapi.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 104 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/information_schema.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/mxodbc.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/pymssql.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 38 |
6 files changed, 82 insertions, 82 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py index d18880931..355214d89 100644 --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py @@ -31,7 +31,7 @@ class MSDialect_adodbapi(MSDialect): supports_unicode = sys.maxunicode == 65535 supports_unicode_statements = True driver = 'adodbapi' - + @classmethod def import_dbapi(cls): import adodbapi as module diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index dda63080d..290cd1019 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -18,7 +18,7 @@ Auto Increment Behavior ``schema.Sequence()`` objects. In other words:: from sqlalchemy import Table, Integer, Sequence, Column - + Table('test', metadata, Column('id', Integer, Sequence('blah',100,10), primary_key=True), @@ -261,7 +261,7 @@ class SMALLDATETIME(_DateTimeBase, sqltypes.DateTime): class DATETIME2(_DateTimeBase, sqltypes.DateTime): __visit_name__ = 'DATETIME2' - + def __init__(self, precision=None, **kw): super(DATETIME2, self).__init__(**kw) self.precision = precision @@ -270,7 +270,7 @@ class DATETIME2(_DateTimeBase, sqltypes.DateTime): # TODO: is this not an Interval ? class DATETIMEOFFSET(sqltypes.TypeEngine): __visit_name__ = 'DATETIMEOFFSET' - + def __init__(self, precision=None, **kwargs): self.precision = precision @@ -298,7 +298,7 @@ class NTEXT(_StringType, sqltypes.UnicodeText): characters.""" __visit_name__ = 'NTEXT' - + def __init__(self, length=None, collation=None, **kw): """Construct a NTEXT. @@ -405,7 +405,7 @@ class IMAGE(sqltypes.LargeBinary): class BIT(sqltypes.TypeEngine): __visit_name__ = 'BIT' - + class MONEY(sqltypes.TypeEngine): __visit_name__ = 'MONEY' @@ -487,13 +487,13 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): collation = 'COLLATE %s' % type_.collation else: collation = None - + if not length: length = type_.length - + if length: spec = spec + "(%s)" % length - + return ' '.join([c for c in (spec, collation) if c is not None]) @@ -535,10 +535,10 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): def visit_unicode(self, type_): return self.visit_NVARCHAR(type_) - + def visit_unicode_text(self, type_): return self.visit_NTEXT(type_) - + def visit_NTEXT(self, type_): return self._extend("NTEXT", type_) @@ -570,7 +570,7 @@ class MSTypeCompiler(compiler.GenericTypeCompiler): return self.visit_DATETIME(type_) else: return self.visit_TIME(type_) - + def visit_large_binary(self, type_): return self.visit_IMAGE(type_) @@ -600,7 +600,7 @@ class MSExecutionContext(default.DefaultExecutionContext): _select_lastrowid = False _result_proxy = None _lastrowid = None - + def pre_exec(self): """Activate IDENTITY_INSERT if needed.""" @@ -608,25 +608,25 @@ class MSExecutionContext(default.DefaultExecutionContext): tbl = self.compiled.statement.table seq_column = tbl._autoincrement_column insert_has_sequence = seq_column is not None - + if insert_has_sequence: self._enable_identity_insert = \ seq_column.key in self.compiled_parameters[0] else: self._enable_identity_insert = False - + self._select_lastrowid = insert_has_sequence and \ not self.compiled.returning and \ not self._enable_identity_insert and \ not self.executemany - + if self._enable_identity_insert: self.cursor.execute("SET IDENTITY_INSERT %s ON" % self.dialect.identifier_preparer.format_table(tbl)) def post_exec(self): """Disable IDENTITY_INSERT if enabled.""" - + if self._select_lastrowid: if self.dialect.use_scope_identity: self.cursor.execute( @@ -640,17 +640,17 @@ class MSExecutionContext(default.DefaultExecutionContext): if (self.isinsert or self.isupdate or self.isdelete) and \ self.compiled.returning: self._result_proxy = base.FullyBufferedResultProxy(self) - + if self._enable_identity_insert: self.cursor.execute( - "SET IDENTITY_INSERT %s OFF" % + "SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer. format_table(self.compiled.statement.table) ) - + def get_lastrowid(self): return self._lastrowid - + def handle_dbapi_exception(self, e): if self._enable_identity_insert: try: @@ -670,7 +670,7 @@ class MSExecutionContext(default.DefaultExecutionContext): class MSSQLCompiler(compiler.SQLCompiler): returning_precedes_values = True - + extract_map = util.update_copy( compiler.SQLCompiler.extract_map, { @@ -686,31 +686,31 @@ class MSSQLCompiler(compiler.SQLCompiler): def visit_now_func(self, fn, **kw): return "CURRENT_TIMESTAMP" - + def visit_current_date_func(self, fn, **kw): return "GETDATE()" - + def visit_length_func(self, fn, **kw): return "LEN%s" % self.function_argspec(fn, **kw) - + def visit_char_length_func(self, fn, **kw): return "LEN%s" % self.function_argspec(fn, **kw) - + def visit_concat_op(self, binary, **kw): return "%s + %s" % \ (self.process(binary.left, **kw), self.process(binary.right, **kw)) - + def visit_match_op(self, binary, **kw): return "CONTAINS (%s, %s)" % ( self.process(binary.left, **kw), self.process(binary.right, **kw)) - + def get_select_precolumns(self, select): """ MS-SQL puts TOP, it's version of LIMIT here """ if select._distinct or select._limit: s = select._distinct and "DISTINCT " or "" - + # ODBC drivers and possibly others # don't support bind params in the SELECT clause on SQL Server. # so have to use literal here. @@ -743,7 +743,7 @@ class MSSQLCompiler(compiler.SQLCompiler): sql.literal_column("ROW_NUMBER() OVER (ORDER BY %s)" \ % orderby).label("mssql_rn") ).order_by(None).alias() - + mssql_rn = sql.column('mssql_rn') limitselect = sql.select([c for c in select.c if c.key!='mssql_rn']) @@ -853,7 +853,7 @@ class MSSQLCompiler(compiler.SQLCompiler): target = stmt.table.alias("inserted") else: target = stmt.table.alias("deleted") - + adapter = sql_util.ClauseAdapter(target) def col_label(col): adapted = adapter.traverse(col) @@ -861,7 +861,7 @@ class MSSQLCompiler(compiler.SQLCompiler): return adapted.label(c.key) else: return self.label_select_column(None, adapted, asfrom=False) - + columns = [ self.process( col_label(c), @@ -896,10 +896,10 @@ class MSSQLCompiler(compiler.SQLCompiler): class MSSQLStrictCompiler(MSSQLCompiler): """A subclass of MSSQLCompiler which disables the usage of bind parameters where not allowed natively by MS-SQL. - + A dialect may use this compiler on a platform where native binds are used. - + """ ansi_bind_rules = True @@ -927,9 +927,9 @@ class MSSQLStrictCompiler(MSSQLCompiler): format acceptable to MSSQL. That seems to be the so-called ODBC canonical date format which looks like this: - + yyyy-mm-dd hh:mi:ss.mmm(24h) - + For other data types, call the base class implementation. """ # datetime and date are both subclasses of datetime.date @@ -950,12 +950,12 @@ class MSDDLCompiler(compiler.DDLCompiler): colspec += " NOT NULL" else: colspec += " NULL" - + if column.table is None: raise exc.InvalidRequestError( "mssql requires Table-bound columns " "in order to generate DDL") - + seq_col = column.table._autoincrement_column # install a IDENTITY Sequence if we have an implicit IDENTITY column @@ -1015,13 +1015,13 @@ class MSDialect(default.DefaultDialect): } ischema_names = ischema_names - + supports_native_boolean = False supports_unicode_binds = True postfetch_lastrowid = True - + server_version_info = () - + statement_compiler = MSSQLCompiler ddl_compiler = MSDDLCompiler type_compiler = MSTypeCompiler @@ -1039,7 +1039,7 @@ class MSDialect(default.DefaultDialect): self.max_identifier_length = int(max_identifier_length or 0) or \ self.max_identifier_length super(MSDialect, self).__init__(**opts) - + def do_savepoint(self, connection, name): util.warn("Savepoint support in mssql is experimental and " "may lead to data loss.") @@ -1048,7 +1048,7 @@ class MSDialect(default.DefaultDialect): def do_release_savepoint(self, connection, name): pass - + def initialize(self, connection): super(MSDialect, self).initialize(connection) if self.server_version_info[0] not in range(8, 17): @@ -1064,7 +1064,7 @@ class MSDialect(default.DefaultDialect): if self.server_version_info >= MS_2005_VERSION and \ 'implicit_returning' not in self.__dict__: self.implicit_returning = True - + def _get_default_schema_name(self, connection): user_name = connection.scalar("SELECT user_name() as user_name;") if user_name is not None: @@ -1138,7 +1138,7 @@ class MSDialect(default.DefaultDialect): # below MS 2005 if self.server_version_info < MS_2005_VERSION: return [] - + current_schema = schema or self.default_schema_name full_tname = "%s.%s" % (current_schema, tablename) @@ -1186,7 +1186,7 @@ class MSDialect(default.DefaultDialect): for row in rp: if row['index_id'] in indexes: indexes[row['index_id']]['column_names'].append(row['name']) - + return indexes.values() @reflection.cache @@ -1315,7 +1315,7 @@ class MSDialect(default.DefaultDialect): # the constrained column C = ischema.key_constraints.alias('C') # information_schema.constraint_column_usage: - # the referenced column + # the referenced column R = ischema.key_constraints.alias('R') # Primary key constraints @@ -1337,7 +1337,7 @@ class MSDialect(default.DefaultDialect): #information_schema.referential_constraints RR = ischema.ref_constraints # information_schema.table_constraints - TC = ischema.constraints + TC = ischema.constraints # information_schema.constraint_column_usage: # the constrained column C = ischema.key_constraints.alias('C') @@ -1361,12 +1361,12 @@ class MSDialect(default.DefaultDialect): order_by = [ RR.c.constraint_name, R.c.ordinal_position]) - + # group rows by constraint ID, to handle multi-column FKs fkeys = [] fknm, scols, rcols = (None, [], []) - + def fkey_rec(): return { 'name' : None, @@ -1377,7 +1377,7 @@ class MSDialect(default.DefaultDialect): } fkeys = util.defaultdict(fkey_rec) - + for r in connection.execute(s).fetchall(): scol, rschema, rtbl, rcol, rfknm, fkmatch, fkuprule, fkdelrule = r @@ -1388,11 +1388,11 @@ class MSDialect(default.DefaultDialect): if schema is not None or current_schema != rschema: rec['referred_schema'] = rschema - + local_cols, remote_cols = \ rec['constrained_columns'],\ rec['referred_columns'] - + local_cols.append(scol) remote_cols.append(rcol) diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index 5806ebfa8..87dd0a167 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -13,12 +13,12 @@ ischema = MetaData() class CoerceUnicode(TypeDecorator): impl = Unicode - + def process_bind_param(self, value, dialect): if isinstance(value, str): value = value.decode(dialect.encoding) return value - + schemata = Table("SCHEMATA", ischema, Column("CATALOG_NAME", CoerceUnicode, key="catalog_name"), Column("SCHEMA_NAME", CoerceUnicode, key="schema_name"), @@ -74,8 +74,8 @@ ref_constraints = Table("REFERENTIAL_CONSTRAINTS", ischema, Column("CONSTRAINT_NAME", CoerceUnicode, key="constraint_name"), # TODO: is CATLOG misspelled ? Column("UNIQUE_CONSTRAINT_CATLOG", CoerceUnicode, - key="unique_constraint_catalog"), - + key="unique_constraint_catalog"), + Column("UNIQUE_CONSTRAINT_SCHEMA", CoerceUnicode, key="unique_constraint_schema"), Column("UNIQUE_CONSTRAINT_NAME", CoerceUnicode, diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py index ba695ef08..6a830509a 100644 --- a/lib/sqlalchemy/dialects/mssql/mxodbc.py +++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py @@ -20,7 +20,7 @@ Connecting Connection is via DSN:: mssql+mxodbc://<username>:<password>@<dsnname> - + Execution Modes ~~~~~~~~~~~~~~~ @@ -72,7 +72,7 @@ class MSExecutionContext_mxodbc(MSExecutionContext_pyodbc): # won't work. class MSDialect_mxodbc(MxODBCConnector, MSDialect): - + # TODO: may want to use this only if FreeTDS is not in use, # since FreeTDS doesn't seem to use native binds. statement_compiler = MSSQLStrictCompiler diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py index aa3bf45d2..192e63366 100644 --- a/lib/sqlalchemy/dialects/mssql/pymssql.py +++ b/lib/sqlalchemy/dialects/mssql/pymssql.py @@ -12,10 +12,10 @@ This dialect supports pymssql 1.0 and greater. pymssql is available at: http://pymssql.sourceforge.net/ - + Connecting ^^^^^^^^^^ - + Sample connect string:: mssql+pymssql://<username>:<password>@<freetds_name> @@ -53,7 +53,7 @@ class MSDialect_pymssql(MSDialect): supports_sane_rowcount = False max_identifier_length = 30 driver = 'pymssql' - + colspecs = util.update_copy( MSDialect.colspecs, { @@ -67,7 +67,7 @@ class MSDialect_pymssql(MSDialect): # pymmsql doesn't have a Binary method. we use string # TODO: monkeypatching here is less than ideal module.Binary = str - + client_ver = tuple(int(x) for x in module.__version__.split(".")) if client_ver < (1, ): util.warn("The pymssql dialect expects at least " diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index 90a43889e..9b88dce2a 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -86,15 +86,15 @@ import decimal class _MSNumeric_pyodbc(sqltypes.Numeric): """Turns Decimals with adjusted() < 0 or > 7 into strings. - + This is the only method that is proven to work with Pyodbc+MSSQL without crashing (floats can be used but seem to cause sporadic crashes). - + """ def bind_processor(self, dialect): - + super_process = super(_MSNumeric_pyodbc, self).\ bind_processor(dialect) @@ -104,7 +104,7 @@ class _MSNumeric_pyodbc(sqltypes.Numeric): def process(value): if self.asdecimal and \ isinstance(value, decimal.Decimal): - + adjusted = value.adjusted() if adjusted < 0: return self._small_dec_to_string(value) @@ -116,10 +116,10 @@ class _MSNumeric_pyodbc(sqltypes.Numeric): else: return value return process - + # these routines needed for older versions of pyodbc. # as of 2.1.8 this logic is integrated. - + def _small_dec_to_string(self, value): return "%s0.%s%s" % ( (value < 0 and '-' or ''), @@ -147,24 +147,24 @@ class _MSNumeric_pyodbc(sqltypes.Numeric): "".join( [str(s) for s in _int][0:value.adjusted() + 1])) return result - - + + class MSExecutionContext_pyodbc(MSExecutionContext): _embedded_scope_identity = False - + def pre_exec(self): """where appropriate, issue "select scope_identity()" in the same statement. - + Background on why "scope_identity()" is preferable to "@@identity": http://msdn.microsoft.com/en-us/library/ms190315.aspx - + Background on why we attempt to embed "scope_identity()" into the same statement as the INSERT: http://code.google.com/p/pyodbc/wiki/FAQs#How_do_I_retrieve_autogenerated/identity_values? - + """ - + super(MSExecutionContext_pyodbc, self).pre_exec() # don't embed the scope_identity select into an @@ -173,7 +173,7 @@ class MSExecutionContext_pyodbc(MSExecutionContext): self.dialect.use_scope_identity and \ len(self.parameters[0]): self._embedded_scope_identity = True - + self.statement += "; select scope_identity()" def post_exec(self): @@ -185,13 +185,13 @@ class MSExecutionContext_pyodbc(MSExecutionContext): try: # fetchall() ensures the cursor is consumed # without closing it (FreeTDS particularly) - row = self.cursor.fetchall()[0] + row = self.cursor.fetchall()[0] break except self.dialect.dbapi.Error, e: # no way around this - nextset() consumes the previous set # so we need to just keep flipping self.cursor.nextset() - + self._lastrowid = int(row[0]) else: super(MSExecutionContext_pyodbc, self).post_exec() @@ -202,14 +202,14 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect): execution_ctx_cls = MSExecutionContext_pyodbc pyodbc_driver_name = 'SQL Server' - + colspecs = util.update_copy( MSDialect.colspecs, { sqltypes.Numeric:_MSNumeric_pyodbc } ) - + def __init__(self, description_encoding='latin-1', **params): super(MSDialect_pyodbc, self).__init__(**params) self.description_encoding = description_encoding @@ -217,5 +217,5 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect): hasattr(self.dbapi.Cursor, 'nextset') self._need_decimal_fix = self.dbapi and \ tuple(self.dbapi.version.split(".")) < (2, 1, 8) - + dialect = MSDialect_pyodbc |
