skip to main content
Reference : Designing ODBC Applications for Performance Optimization : Retrieving Data : Using Bound Columns
  

Try DataDirect Drivers Now
Using Bound Columns
Retrieving data through bound columns (SQLBindCol) instead of using SQLGetData reduces the ODBC call load and improves performance.
Consider the following code fragment:
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, 1891 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 1891 to 111 (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 into the user’s buffer. That is, instead of the driver retrieving information into a container and then 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.