Windows API Reference

Database Services

ODBC (Open Database Connectivity)

ODBC is a standard application programming interface for accessing database management systems (DBMS). It allows applications to access data in different database systems without rewriting the code for each database.

Core Functions

Key Structures

  • SQLHANDLE: Handle to environment, connection, statement, or descriptor.
  • SQLSMALLINT, SQLINTEGER, SQLUINTEGER, etc.: Data types used in ODBC functions.

SQLAllocEnv

RETCODE SQLAllocEnv(HENV *Phenv)

Allocates an environment handle and returns a pointer to the handle.

[out] Phenv: HENV* - Pointer to the environment handle to be allocated.
Return Value:

SQL_SUCCESS, SQL_ERROR, SQL_INVALID_HANDLE.

Notes:

An application must call SQLAllocEnv before calling any other ODBC function except SQLAllocHandle.

SQLConnect

RETCODE SQLConnect(HDBC hDbc, SQLCHAR *szDSN, SQLSMALLINT cbDSN, SQLCHAR *szUID, SQLSMALLINT cbUID, SQLCHAR *szAuthStr, SQLSMALLINT cbAuthStr)

Establishes a connection to a data source using a Data Source Name (DSN).

[in] hDbc: HDBC - The connection handle.
[in] szDSN: SQLCHAR* - The DSN of the data source.
[in] cbDSN: SQLSMALLINT - Length of szDSN in bytes.
[in] szUID: SQLCHAR* - The user ID.
[in] cbUID: SQLSMALLINT - Length of szUID in bytes.
[in] szAuthStr: SQLCHAR* - The authentication string.
[in] cbAuthStr: SQLSMALLINT - Length of szAuthStr in bytes.
Return Value:

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, SQL_INVALID_HANDLE, SQL_NEED_DATA.

SQLExecDirect

RETCODE SQLExecDirect(HSTMT hStmt, SQLCHAR *szSqlStr, SQLINTEGER cbSqlStr)

Executes an SQL statement directly without needing to prepare it first.

[in] hStmt: HSTMT - The statement handle.
[in] szSqlStr: SQLCHAR* - The SQL statement string.
[in] cbSqlStr: SQLINTEGER - Length of the SQL string. Use SQL_NTS for null-terminated strings.
Return Value:

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, SQL_INVALID_HANDLE, SQL_NO_DATA, SQL_STILL_EXECUTING.

SQLFetch

RETCODE SQLFetch(HSTMT hStmt)

Fetches the next row of a result set into the application's bound columns.

[in] hStmt: HSTMT - The statement handle.
Return Value:

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, SQL_INVALID_HANDLE, SQL_NO_DATA, SQL_STILL_EXECUTING.

SQLDisconnect

RETCODE SQLDisconnect(HDBC hDbc)

Disassociates an application from a data source.

[in] hDbc: HDBC - The connection handle.
Return Value:

SQL_SUCCESS, SQL_ERROR, SQL_INVALID_HANDLE.

SQLFreeEnv

RETCODE SQLFreeEnv(HENV hEnv)

Frees an environment handle and releases all associated resources.

[in] hEnv: HENV - The environment handle to be freed.
Return Value:

SQL_SUCCESS, SQL_ERROR, SQL_INVALID_HANDLE.

OLE DB

OLE DB (Object Linking and Embedding Database) is a Microsoft data access technology for providing a consistent interface to a variety of information sources, including relational databases and spreadsheets.

Core Components

  • Providers: Implement OLE DB interfaces to expose data.
  • Consumers: Applications that use OLE DB providers to access data.
  • Rowsets: A collection of rows returned by a query.
  • Commands: Objects that execute SQL or other query languages.

Key Interfaces

  • IDBInitialize
  • ISessionProperties
  • IOpenRowset
  • ICommandText
  • IRowset

Extensible Storage Engine (ESE)

The Extensible Storage Engine (ESE), also known as Jet Blue, is an indexed, transactional database application programming interface (API) that provides high-performance access to data.

Common Uses

  • Windows Search Indexing
  • Exchange Server Mailboxes
  • Active Directory

Key Functions

  • JetCreateInstance
  • JetInit2
  • JetBeginTransaction
  • JetCommitTransaction
  • JetOpenDatabase
  • JetCloseDatabase