Share via


Use Rowset Binding (ODBC)

To use column-wise binding

  1. For each bound column, do the following:

    • Allocate an array of R (or more) column buffers to store data values, where R is number of rows in the rowset.

    • Optionally, allocate an array of R (or more) column buffers to store data lengths.

    • Call SQLBindCol to bind the column's data value and data length arrays to the column of the rowset.

  2. Call SQLSetStmtAttr to set the following attributes:

    • Set SQL_ATTR_ROW_ARRAY_SIZE to the number of rows in the rowset (R).

    • Set SQL_ATTR_ROW_BIND_TYPE to SQL_BIND_BY_COLUMN.

    • Set the SQL_ATTR_ROWS FETCHED_PTR attribute to point to a SQLUINTEGER variable to hold the number of rows fetched.

    • Set SQL_ATTR_ROW_STATUS_PTR to point to an array[R] of SQLUSSMALLINT variables to hold the row-status indicators.

  3. Execute the statement.

  4. Each call to SQLFetch or SQLFetchScroll retrieves R rows and transfers the data into the bound columns.

To use row-wise binding

  1. Allocate an array[R] of structures, where R is the number of rows in the rowset. The structure has one element for each column, and each element has two parts:

    • The first part is a variable of the appropriate data type to hold the column data.

    • The second part is a SQLINTEGER variable to hold the column status indicator.

  2. Call SQLSetStmtAttr to set the following attributes:

    • Set SQL_ATTR_ROW_ARRAY_SIZE to the number of rows in the rowset (R).

    • Set SQL_ATTR_ROW_BIND_TYPE to the size of the structure allocated in Step 1.

    • Set the SQL_ATTR_ROWS_FETCHED_PTR attribute to point to a SQLUINTEGER variable to hold the number of rows fetched.

    • Set SQL_ATTR_PARAMS_STATUS_PTR to point to an array[R] of SQLUSSMALLINT variables to hold the row-status indicators.

  3. For each column in the result set, call SQLBindCol to point the data value and data length pointer of the column to their variables in the first element of the array of structures allocated in Step 1.

  4. Execute the statement.

  5. Each call to SQLFetch or SQLFetchScroll retrieves R rows and transfers the data into the bound columns.

See Also

Using Cursors How-to Topics (ODBC)
How Cursors Are Implemented
Use Cursors (ODBC)