How to bind data to SQLBindCol using ODBC Driver API using C++

I'm trying to create a custom ODBC driver using C++ for a Windows environment (like PostgreSQL, Simba, Firebird, etc.) since the ODBC API has multiple ODBC API methods by default.

I established connections using DSN, and I'm able to execute the SQL query using the SQLExecuteDirect method.

However, while connecting Excel with our ODBC driver, I'm unable to bind the table list to the Microsoft query wizard. enter image description here

The SQLTables(), SQLBindColumn(), and SQLFetch() methods are used to retrieve the list of tablenames here. The data is bound using the SQLBindColumn method.

But I'm confused about how to retrieve the tablenames and bind them to Excel?

Upvotes: 13

Views: 1550

Answers (2)

Karthik Sridhar
Karthik Sridhar

Reputation: 259

Excel application will load all schema information before executing any query.

In this case SQLTables method will be called with the attributes like catalog, schema and table names. Based on the attribute called schema information has to be returned in SQLFetch method.

For reference: https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqltables-function

If SQLTables method has been called with catalog name attribute then catalog name has to be bind in SQLFetch method using the data address returned in SQLBindCol method.

Likewise schema and table names were also to be returned for SQLTables method.

For more information on how to bind column wise schema information please refer comments section under the above link.

Upvotes: 0

Nat
Nat

Reputation: 164

After you call SQLExecDirect() or SQLPrepare() you can call SQLDescribeCol(). SQLDescribeCol() will return all the column information you should need.

You can visit Microsoft's website for it here: https://learn.microsoft.com/en-gb/sql/odbc/reference/syntax/sqldescribecol-function

Though this is only usefull if you are doing a

select top 1 * from (table name **SQLTables** found)

Or if you want to find the column names from a generic SQL.


The other way you can go to find all columns is to use the SQLColumns() function. That is similar to SQLTables() (Same search priniciple) and returs a result set with the results. Found here: https://learn.microsoft.com/en-gb/sql/odbc/reference/syntax/sqlcolumns-function

Upvotes: 0

Related Questions