Databases Reference
In-Depth Information
The number of ODBC calls is reduced from 1,891 to 111 (20 calls to
SQLBindCol + 91 calls to SQLFetch ). In addition to reducing the number of calls
required, many drivers optimize how SQLBindCol is used by binding result infor-
mation directly from the database 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 requests that the information from the database be
placed directly into the user's buffer.
Using SQLExtendedFetch Instead of SQLFetch
Most ODBC drivers now support SQLExtendedFetch for forward-only cursors.
Yet, most ODBC applications continue to use SQLFetch to fetch data.
Performance Tip
Using the SQLExtendedFetch function instead of SQLFetch to fetch data
reduces the number of ODBC calls, and ultimately the number of net-
work round trips, and simplifies coding. Using SQLExtendedFetch results
in better performance and more maintainable code.
Again, consider the same example we used in the section, “Using Bound
Columns,” page 145, but using SQLExtendedFetch instead of SQLFetch :
rc = SQLSetStmtOption (hstmt, SQL_ROWSET_SIZE, 100);
// use arrays of 100 elements
rc = SQLExecDirect (hstmt, "SELECT <20 columns>" +
"FROM employees" +
"WHERE HireDate >= ?", SQL_NTS);
// call SQLBindCol 1 time specifying row-wise binding
do {
rc = SQLExtendedFetch (hstmt, SQL_FETCH_NEXT, 0,
&RowsFetched, RowStatus);
} while ((rc == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO));
The number of ODBC calls made by the application has been reduced from
1,891 to 4 (1 SQLSetStmtOption + 1 SQLExecDirect + 1 SQLBindCol + 1
SQLExtendedFetch ). Besides reducing the ODBC call load, some ODBC drivers
 
Search WWH ::




Custom Search