hdbc / hdbc-odbc

ODBC driver for HDBC
BSD 3-Clause "New" or "Revised" License
26 stars 34 forks source link

OBDC Driver 11 for SQL Server query fails #30

Open Profpatsch opened 7 years ago

Profpatsch commented 7 years ago

I can create a connection without problem. I have at small test table

id: bigint
name: nvarchar(max)

And when I try

> quickQuery c "select id from test" []
[[SqlInt64 123]]
> quickQuery c "select * from test" []
*** Exception: SqlError {seState = "[\"07009\"]", seNativeError = -1, seErrorMsg = "sqlGetData: [\"0: [Microsoft][ODBC Driver 13 for SQL Server]Invalid Descriptor Index\"]"}

Same error for select name and select id,name.

StackOverflow has some ideas, but it doesn’t seem to fit this problem.

Profpatsch commented 7 years ago

Same error with Driver versions 11 and 13.1 (all three official Microsoft drivers on Windows).

Profpatsch commented 7 years ago

https://social.technet.microsoft.com/Forums/sqlserver/en-US/8db96b6b-4d79-4a69-a4d9-2f1d992db478/invalid-descriptor-index-calling-sqlgetdata?forum=sqldataaccess

This is the documented behavior for SQL Native Client. Columns must be retrieved in increasing ordinal order. This part of the documentation was the same for SQL Server 7, so SQL Native Client has not introduced new behavior here. Otherdrivers may support fetching columns in random order. Applications can determine the behavior of a driver by calling SQLGetInfo for SQL_GETDATA_EXTENSIONS and using the bitmas SQL_GD_ANY_ORDER. By enforcing sequential order, the ODBC driver avoids having to have an intermediate row buffer, so there is a gain in efficiency and memory utilization.

I assume HDBC doesn’t fetch them necessarily in increasing order?

Profpatsch commented 7 years ago

Also note that these are 1-indexed. (from another thread)