Lydon Ch
Lydon Ch

Reputation: 8815

ODBC: SQLDescribeCol always return columnNameLength of 0

For some reason, ODBC SQLDescribeCol() always returns columnNameLength of 0, which screws up the logic of the code.

Running in Windows Server 2012 and SQLServer 2014 Developer.

Any idea why is it always returning columnNameLength of 0?

The code is here.

debugging

Upvotes: 0

Views: 294

Answers (2)

Lydon Ch
Lydon Ch

Reputation: 8815

This turned out to be an issue for x64 build, where the parameters' sizes was incorrectly coded (it should be SQLULEN instead of SQLUINTEGER)

https://github.com/szekerest/mapserver/commit/6eb767fcaecd03960940343f9acef2ce296caf70

fix

Upvotes: 0

Michael Koenig
Michael Koenig

Reputation: 364

Two things:

  • ODBC might not be at fault, but the ODBC driver you are using. Might be a bug or one of those "features" which are "optional".
  • Even if the driver returns 0 for the length, columnName still contains a null-terminated string. Don't know much about C#, but I bet there is a way to create a string object from that. Or you could count try to find the null termination character yourself. In any case, since your external buffer needs to be large enough to hold the largest supported column name, copying the entire columnName buffer should be ok either way.

That being said, I think if you improved your function to just return a string object, you would be much better off. Less (pointer) parameters, a meaningful return value, and error handling with exceptions. Just a suggestion, though.

Upvotes: 1

Related Questions