13

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?

рüффп
  • 5,172
  • 34
  • 67
  • 113
  • Why are you creating your own ODBC driver?! And what is the Data Source for which you're writing this driver? – MikeC Apr 03 '16 at 02:35
  • Thanks for responce @MikeC. I have my own thrift service. I want to connect and bind this thrift base data to MS-Excel or other tools... Similar to this [Hive-ODBC](https://cwiki.apache.org/confluence/display/Hive/HiveODBC). But I want to build this with visual studio. – ǨÅVËĔŊ RĀǞĴĄŅ Apr 04 '16 at 06:28
  • Have you considered using the SimbaEngine SDK (http://www.simba.com/drivers/simba-engine-sdk/) as a basis for your driver? All of the Simba drivers are based on this SDK and you should be able to have mostly complete and running within a week. – KylePorter Apr 13 '16 at 18:35
  • @KylePorter My requirement is to create the ODBC custom driver without using any third party software. – ǨÅVËĔŊ RĀǞĴĄŅ Apr 14 '16 at 05:05
  • I'm a bit confused here. Are you asking how to properly implement `SQLTables()` so it would return tables in a right form? – isapego Apr 15 '16 at 21:01

2 Answers2

0

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

Nat
  • 164
  • 1
  • 9
0

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.

Karthik Sridhar
  • 239
  • 1
  • 6