In pyodbc, for sql server, they have these types #define SQLSSVARIANT -150 // SQL Server…
- User
In pyodbc, for sql server, they have these types #define SQL_SS_VARIANT -150 // SQL Server 2008 SQL_VARIANT type #define SQL_SS_XML -152 // SQL Server 2005 XML type #define SQL_DB2_DECFLOAT -360 // IBM DB/2 DECFLOAT type #define SQL_DB2_XML -370 // IBM DB/2 XML type #define SQL_SS_TIME2 -154 // SQL Server 2008 time type but I can't find any documentation on the microsoft website, where these are specified, for example that SQL_XML is -152. I am looking for a list of all types and their values for sql server.
Assistant
- User
sorry but your suggestion did not help. I am trying to find info about the "-16" type.
Assistant
The value –16 is not one of the SQL-Server–specific constants such as
SQL_SS_XML (-152)orSQL_SS_TIME2 (-154).
It is a standard ODBC C-type identifier, defined in the ODBC header files (sql.h,sqlext.h) that come with the Microsoft ODBC SDK.In those headers you will find:
#define SQL_C_ULONG (-16)So –16 is the ODBC C type constant
SQL_C_ULONG, used when binding a column or parameter as an unsigned 32-bit integer (unsigned longin C).- User
If I cast the object it is fine, but if I query a sql_variant column then i get an HY106 error
Assistant
HY106is the ODBC diagnostic code forFetch type out of rangeand it is raised by the SQL Server driver when you try to use SQLGetData (or any SQLFetch/SQLFetchScroll operation that internally calls SQLGetData) on a column whose SQL type is SQL_SS_VARIANT (-150) and whose C type is SQL_C_ULONG (-16).
The driver simply does not implement the conversion path
SQL_SS_VARIANT → SQL_C_ULONGso the request is rejected with
HY106.Why it works when you CAST
When you CAST the column to, say,intorbigint, the driver no longer sees the column asSQL_SS_VARIANT; it sees the cast target type, and the conversion toSQL_C_ULONGis supported for those types.