skip to main content
Developing ODBC Applications : Developing Performance-Optimized ODBC Applications : Retrieving Data : Using Bound Columns
 

Using Bound Columns

Retrieving data using bound columns (SQLBindCol), instead of SQLGetData, reduces the ODBC call load and improves performance.
Consider the following example:
rc = SQLExecDirect (hstmt, "SELECT <20 columns> FROM Employees
WHERE HireDate >= ?", SQL_NTS);
do {
rc = SQLFetch (hstmt);
// call SQLGetData 20 times
} while ((rc == SQL_SUCCESS) || (rc==SQL_SUCCESS_WITH_INFO));
Suppose the query returns 90 result rows. In this case, more than 1890 ODBC calls are made (20 calls to SQLGetData x 90 result rows + 91 calls to SQLFetch).
Consider the same scenario that uses SQLBindCol, instead of SQLGetData:
rc = SQLExecDirect (hstmt, "SELECT <20 columns> FROM Employees
WHERE HireDate >= ?", SQL_NTS);
// call SQLBindCol 20 times
do {
rc = SQLFetch (hstmt);
} while ((rc == SQL_SUCCESS) || (rc==SQL_SUCCESS_WITH_INFO));
The number of ODBC calls made is reduced from more than 1890 to about 110 (20 calls to SQLBindCol + 91 calls to SQLFetch). In addition to reducing the call load, many drivers optimize how SQLBindCol is used by binding result information directly from the database server to the user’s buffer. That is, instead of the driver retrieving information into a container and copying that information to the user’s buffer, the driver simply requests the information from the server be placed directly into the user’s buffer.