Begin detailed description.

This figure is a flowchart that compares the process that retrieves a result set one row at a time to the process that retrieves a result set directly into an array. This description presents these two processes separately.

The following table describes the process in which you call functions to retrieve a result set one row at a time. Each row in this table represents a required function call, an optional function call, or a choice between function calls in this process. The functions are presented in the order in which you call them in your application.
Function call Usage Description
SQLAllocHandle() Required Allocates a statement handle.
SQLPrepare() and SQLExecute(), or SQLExecDirect() Required choice Prepares and executes an SQL query that returns a result set of n rows and m columns.
SQLBindCol() Required Binds each column of the result set to an application variable. For m columns you call this functionm times.
SQLFetch() Required Fetches the current row into the bound application variables. For n rows you must call this function n times.
SQLFreeHandle() Optional Frees the statement handle.
The following table describes the process in which you call functions to retrieve a result set directly into an array. Each row in this table represents a required function call, an optional function call, or a choice between function calls in this process. The functions are presented in the order in which you call them in your application.
Function call Usage Description
SQLAllocHandle() Required Allocates a statement handle.
SQLSetStmtAttr() Required Specifies if you will bind the result set column-wise or row-wise.
If you are going to bind the result set column-wise, call SQLSetStmtAttr() to set the following attributes:
  • Set SQL_ATTR_BIND_TYPE to SQL_BIND_BY_COLUMN.
  • Set SQL_ATTR_ROWSET_SIZE to the number of rows in the result set.
If you are going to bind the result set row-wise, call SQLSetStmtAttr() to set the following attributes:
  • Set SQL_ATTR_BIND_TYPE to sizeof (struct StructName).
  • Set SQL_ATTR_ROWSET_SIZE to the number of rows in the result set.
SQLPrepare() and SQLExecute(), or SQLExecDirect() Required choice Prepares and executes an SQL query that returns a result set that consists of n rows and m columns.
SQLBindCol() Required Binds a column of the result set to an array (when the SQL_ATTR_BIND_TYPE attribute is set to SQL_BIND_BY_COLUMN) or binds a column to a component of a structure (when the SQL_ATTR_BIND_TYPE attribute is set to sizeof(struct StructName)). For m columns you call this function m times.
SQLExtendedFetch() Required Fetches the entire result set into the bound arrays or the bound structure.
SQLFreeHandle() Optional Frees the statement handle.

End detailed description.