Skip to content

Description is reused for all result sets #310

@MeinAccount

Description

@MeinAccount

Describe the bug

When running sql that produces multiple result sets, the Cursor.description is not updated when calling Cursor.nextset(). In particular, when the first result set doesn't produce rows (like an update without output clause), it is not possible to fetch rows of the 2nd result set.

curs.execute("""
update ... set ...;
update ... set ... output inserted.*;
""")
curs.nextset() # no rows from the first set
print(rows.fetchall()) # this will raise
Exception message: TypeError: 'NoneType' object is not iterable
Stack trace:
  File "/***/python3.12/site-packages/mssql_python/cursor.py", line 1821, in fetchall
    raise e
  File "/***/python3.12/site-packages/mssql_python/cursor.py", line 1818, in fetchall
    return [Row(self, self.description, row_data, column_map) for row_data in rows_data]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/***/python3.12/site-packages/mssql_python/row.py", line 45, in __init__
    for i, col_desc in enumerate(description):
                       ^^^^^^^^^^^^^^^^^^^^^^

The provided code works using PyODBC. For that particular case, it is of course possible to split into two Cursor.execute calls. This is a reduced test-case where SQL-table variables are used, which requires the single execute-Call.

Further technical details

Python version: 3.12 using mssql-python==0.13.1
SQL Server version: Azure SQL
Operating system: Ubuntu 24.04 on WSL2

Metadata

Metadata

Assignees

Labels

triage neededFor new issues, not triaged yet.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions