Share via


ODBC: Calling ODBC API Functions Directly

OverviewHow Do IFAQSampleODBC Driver List

The database classes provide a simpler interface to a data source than does ODBC. As a result, the classes don’t encapsulate all of the ODBC API. For any functionality that falls outside the abilities of the classes, you must call ODBC API functions directly. For example, you must call the ODBC catalog functions (::SQLColumns, ::SQLProcedures, ::SQLTables, and others) directly. Samples of direct ODBC function calls used with the classes are in the MFC Database sample .

****Note   ****ODBC data sources are accessible through the MFC ODBC classes, as described in this article, or through the MFC Data Access Object (DAO) classes. For information about the DAO classes, see the article DAO and MFC.

To call an ODBC API function directly, you must take the same steps you’d take if you were making the calls without the framework. They are:

  • Allocate storage for any results the call returns.

  • Pass an ODBC HDBC or HSTMT handle, depending on the parameter signature of the function.

    Member variables CDatabase::m_hdbc and CRecordset::m_hstmt are available so that you do not need to allocate and initialize these yourself.

  • Perhaps call additional ODBC functions to prepare for or follow up the main call.

  • Deallocate storage when you finish.

For more information about these steps, see the ODBC SDK Programmer’s Reference on the MSDN Library CD.

In addition to these steps, you need to take extra steps to check function return values, assure that your program isn’t waiting for an asynchronous call to finish, and so on. You can simplify these last steps by using the AFX_SQL_ASYNC and AFX_SQL_SYNC macros. See in the Class Library Reference for information.

See Also   ODBC