diff options
author | Paul Johnston <paj@pajhome.org.uk> | 2007-11-25 17:40:49 +0000 |
---|---|---|
committer | Paul Johnston <paj@pajhome.org.uk> | 2007-11-25 17:40:49 +0000 |
commit | f5701297b119eb73287934e68ec6b1f9da3a6278 (patch) | |
tree | 0463ac3d7f6f9a19b2f394b672bc82d7ded7c806 /lib/sqlalchemy/databases/mssql.py | |
parent | 39b89bd05b95f69d01e309cd599ed70502605e39 (diff) | |
download | sqlalchemy-f5701297b119eb73287934e68ec6b1f9da3a6278.tar.gz |
Change to make PyODBC result fetching a bit more reliable
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index ba6bb7f0f..f8c7f23e5 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -799,14 +799,14 @@ class MSSQLDialect_pyodbc(MSSQLDialect): super(MSSQLDialect_pyodbc, self).do_execute(cursor, statement, parameters, context=context, **kwargs) if context and context.HASIDENT and (not context.IINSERT) and context.dialect.use_scope_identity: import pyodbc - # fetch the last inserted id from the manipulated statement (pre_exec). - try: - row = cursor.fetchone() - except pyodbc.Error, e: - # if nocount OFF fetchone throws an exception and we have to jump over - # the rowcount to the resultset - cursor.nextset() - row = cursor.fetchone() + # Fetch the last inserted id from the manipulated statement + # We may have to skip over a number of result sets with no data (due to triggers, etc.) + while True: + try: + row = cursor.fetchone() + break + except pyodbc.Error, e: + cursor.nextset() context._last_inserted_ids = [int(row[0])] class MSSQLDialect_adodbapi(MSSQLDialect): |