mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 562 forks source link

Expose sql_type information about columns in resultset #167

Open jstastny-cz opened 7 years ago

jstastny-cz commented 7 years ago

I am looking for an extension of metadata returned through Cursor. For every column in a result set I'd like to be able to get sql_type code of that column. Together with getTypeInfo method of cursor, user can get further information about the datatype.

findepi commented 6 years ago

Same here. https://github.com/mkleehammer/pyodbc/wiki/Cursor#description docs suggests that it returns just that:

  1. type code

but instead it returns Python type that values will be mapped to (e.g. str, int, datetime.time etc.)

@mkleehammer is there a way to get original (ODBC-level) type information?

jstastny-cz commented 6 years ago

@findepi Hello, there is a way. You can get it from the odbc driver. Actually, I've implemented the extension in my fork of this project, if you're interested.

findepi commented 6 years ago

@jstastny-cz , is it Cursor#colinfos (https://github.com/jstastny-cz/pyodbc/blob/c278e74e44341a4333dbd2b471758b651abc7558/src/cursor.h#L112)? Looks like that would be it! Are you planning on making a PR with this enhancement?

jstastny-cz commented 6 years ago

@findepi Not that one.

I exposed the information in an additional field 'coldescription': https://github.com/jstastny-cz/pyodbc/blob/2f703c07a98c70ac369e77603abd98e681204421/src/cursor.h#L117

and the PR is already in place (it never got into the project, as it is not project's priority I am afraid): https://github.com/mkleehammer/pyodbc/pull/168