Bug #38144 SQLDescribeCol returns excessivly long column names
Submitted: 15 Jul 2008 16:28 Modified: 18 Jul 2008 9:19
Reporter: Anders Karlsson Email Updates:
Status: Verified Impact on me:
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.1, 3.51 OS:Microsoft Windows
Assigned to: Assigned Account CPU Architecture:Any
Triage: D3 (Medium)

[15 Jul 2008 16:28] Anders Karlsson
When computed column in a SELECT is described with SQLDescribeCol(), MyODBC will return the full computation formula as the column name, just like the MySQL server, this name can be any arbitray length, only limited by the length of the formula. On the other hand, SQLGetInfo() will report that the max length of a column is 64 bytes. Now, the ODBC spec says that SQLGetInfo() SQL_MAX_COLUMN_NAME_LEN applies to "identifiers", and with this is mind, then the length of a computed column might not be limited here. On the other hand, it is reasonable that it IS limited, and in most cases where a long formula is used, noone is really interested in a column name that is longer than 64 bytes anyway.

How to repeat:
Through the ODBC driver, issue a SELECT query with a long computed column, longer than 64 characters, and then do a SQLDescribeCol() on that column. The full length of the column will be returned, and if the column name buffer is less than the returned length, then SQL_SUCCESS_WITH_INFO will be returned.

Suggested fix:
Either we do a fix that is optional, in which case one has to turn on an option that will truncate the colummn name returned from SQLDescribeCol() to the same as what SQLGetInfo() for SQL_MAX_COLUMN_NAME_LEN returns, i.e. 64.

A smarter and easier solution, that will be reasonably compatible, is to return SQL_SUCCESS from SQLDescribeCol() even when the length of the returned column is longer than 64 bytes, assuming that the buffer is set to 64 bytes or more. I don't see this as causing any big issue, but if so, then lets make it optionally tuned off.
[18 Jul 2008 9:13] Tonci Grgin
Test case

Attachment: B38144.cpp (text/x-c++), 2.56 KiB.

[18 Jul 2008 9:19] Tonci Grgin
Hi Anders and thanks for your report.

I agree with you that we might need to fix this discrepancy. Interesting thing to see is how MSSQL behaves. Bogdan will check that now.

Test case result:
Connecting ...
GetInfo Col Name Length:64#

Col Name:1234567890+2234567890+3234567890+4234567890+5234567890+6234567890+7234

Col Name Length:76#
[18 Jul 2008 9:38] Bogdan Degtyariov
Test results for MS SQL SERVER:

Connecting ...
GetInfo Col Name Length:128#

Col Name:#

Col Name Length:0#