diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/pyodbc.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 38 |
1 files changed, 19 insertions, 19 deletions
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 |
