Skip to content

Commit 8b751a9

Browse files
committed
Switch column introspection to use sp_columns instead of cursor.columns
1 parent a902a95 commit 8b751a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sql_server/pyodbc/introspection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def get_table_description(self, cursor, table_name, identity_check=True):
9393
of SQL_BIGAUTOFIELD, which maps to the 'BigAutoField' value in the DATA_TYPES_REVERSE dict.
9494
"""
9595

96-
# map pyodbc's cursor.columns to db-api cursor description
97-
columns = [[c[3], c[4], None, c[6], c[6], c[8], c[10], c[12]] for c in cursor.columns(table=table_name)]
96+
# map T-SQL's `sp_columns` stored procedure to db-api cursor description
97+
# https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-columns-transact-sql
98+
columns = [[c[3], c[4], None, c[6], c[6], c[8], c[10], c[12]] for c in cursor.execute('exec sp_columns %s', [table_name]).fetchall()]
9899
items = []
99100
for column in columns:
100101
if identity_check and self._is_auto_field(cursor, table_name, column[0]):

0 commit comments

Comments
 (0)