Search code examples
pythonsql-serverpython-2.7sqldatatypespymssql

accessing column_types in pymssql connection class


I am using the pymssql module. And I am trying to extract the datatypes of my columns. According to the github code it should be possible to access it by connection.column_types But I get the following error:

AttributeError: '_mssql.MSSQLConnection' object has no attribute 'column_types'

I don't understand what I am doing wrong. I have the right object, I am creating my connection with the _mssql.connect() method:

pymssql._mssql.connect(server=HOST, port=PORT, user=USR, password=PWD, **KWARGS)

(But even when I am using the DBAPI connect() method pymssql.connect():

pymssql.connect(host=HOST, port=PORT, user=USR, password=PWD, **KWARGS)

And then I try to access the underlying connection class cursor._source._conn.column_types it also fails for the same reason:

AttributeError: '_mssql.MSSQLConnection' object has no attribute 'column_types'

How can I get the data types?


Solution

  • I opened a ticket on the github, and it got an answer. Posting here for posterity and completeness.

    column_types is cdef so only accessible from C code, not Python.

    It's not what I was hoping for, but alas, it is the answer.