Database Functions
This section details the Windows API functions related to database operations and data access.
SQLAllocHandle SQLRETURN SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandlePtr);
Allocates a handle for a specified handle type.
Parameters
HandleType: The type of handle to allocate (e.g.,SQL_HANDLE_ENV,SQL_HANDLE_DBC,SQL_HANDLE_STMT,SQL_HANDLE_DESC).InputHandle: An environment handle or connection handle, depending onHandleType.OutputHandlePtr: A pointer to the buffer that will receive the allocated handle.
Return Value
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Remarks
This function is fundamental to establishing and managing connections and statements in ODBC (Open Database Connectivity).
See Also
SQLFreeHandleSQLAllocConnect(deprecated)
SQLConnect SQLRETURN SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1, SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication, SQLSMALLINT NameLength3);
Establishes a connection to a data source.
Parameters
ConnectionHandle: The connection handle.ServerName: The name of the server or data source.NameLength1: The length ofServerName.UserName: The user ID.NameLength2: The length ofUserName.Authentication: The password.NameLength3: The length ofAuthentication.
Return Value
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA_ALL_SUCCESS, SQL_ERROR, or SQL_INVALID_HANDLE.
Remarks
Used to connect to a specific data source. Often superseded by connection string methods in newer ODBC drivers.
See Also
SQLDisconnectSQLDriverConnect
SQLExecDirect SQLRETURN SQLExecDirect(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength);
Executes a directly passed SQL statement.
Parameters
StatementHandle: The statement handle.StatementText: A pointer to the SQL statement to execute.TextLength: The length of theStatementText.
Return Value
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, SQL_INVALID_HANDLE, or SQL_STILL_EXECUTING.
Remarks
Allows for immediate execution of SQL statements without prior preparation. Suitable for dynamic SQL.
See Also
SQLExecuteSQLPrepare
SQLFetch SQLRETURN SQLFetch(SQLHSTMT StatementHandle);
Fetches the next row of a result set.
Parameters
StatementHandle: The statement handle.
Return Value
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA, SQL_ERROR, or SQL_INVALID_HANDLE.
Remarks
Used to retrieve data from a result set row by row after a query has been executed.
See Also
SQLFetchScrollSQLGetData
SQLDisconnect SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle);
Disconnects an application from a data source.
Parameters
ConnectionHandle: The connection handle.
Return Value
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Remarks
Releases resources associated with the connection. Any outstanding transactions are rolled back.
See Also
SQLConnectSQLDriverConnect