Sunday, February 19, 2012

A problem with SQLColumns call

Hello,
let us consider the following problem with SQLColumns call. Fist of all here goes a small quote from MSDN on SQLColumns input string parameters:

CatalogName [Input]
Catalog name. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have catalogs.

I read it as I can call SQLColumns the following ways:
SQLColumns(hstmt_, (SQLCHAR *)"",SQL_NTS, ...
or
SQLColumns(hstmt_, (SQLCHAR *)"",0, ...

but none of this calls works. The only working way is

SQLColumns(hstmt_, 0,0, ...

Please, note that all calls work for non-Microsoft ODBC drivers I have tried.

So, I believe there is a bug either in MS ODBC driver implementation or in MSDN.

--
Michael Kochetkov

Unfortunately, some implementation details are driver-specific. For the Microsoft ODBC drivers, when you specify the name as "", SQLColumns looks for all tables with that name. Since no tables have a name of "", it returns no results.

If you specify 'NULL' for a table name, it will look for ALL tables.

You may need to wrap your queries based on Driver Name, such as

if(<< MS Driver >>)

SQLColumns(hstmt, NULL, 0, ...)

else

SQLColumns(hstmt, "", SQL_NTS, ...)

|||

> Unfortunately, some implementation details are driver-specific.
I have just wanted to point out that there is a bug: either in MS implementation or MSDN. Let us get back to the CatalogName parameter description. I believe the following statement "an empty string ("") denotes those tables that do not have catalogs." shall be replaced with something like this: as far as MS ODBC driver does distinguish between SQL Nulls and empty strings ("") you cannot use empty string to denote that tables do not have catalogs and are to use 0 that stands for SQL Null value inside.

--
Michael Kochetkov

P.S. Edited: tables have --> tables do not have

No comments:

Post a Comment