Code ODBC functions for efficient data retrieval

You can retrieve data more efficiently by following several guidelines.

Two actions make your application retrieve data sets more efficiently:

  • Define the pcbValue and rgbValue arguments of SQLBindCol() or SQLGetData() contiguously in memory. (This allows Db2 ODBC to fetch both values with one copy operation.)
    To define the pcbValue and rgbValue arguments contiguously in memory, create a structure that contains both values. For example, the following code creates such a structure:
    struct {  SQLINTEGER  pcbValue;
              SQLCHAR     rgbValue[MAX_BUFFER];
           } column;
  • Choose an appropriate function with which to retrieve results. Generally the most efficient approach is to bind application variables to result sets with SQLBindCol(). However, in some cases calling SQLGetData() to retrieve results is more efficient. When the data value is large and is variable-length, use SQLGetData() for the following situations:
    • You must retrieve the data in pieces.
    • You might not need to retrieve the data. (That is, retrieval is dependent on another application action.)