MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 6: Getting and Setting Data


 

Setting Data

To set data—for example, with IRowsetChange::SetData for rowset data or ICommand::Execute for input parameter data—the consumer must perform the following actions:

  1. Create an accessor to bind the columns or input parameters.

  2. Allocate a buffer to hold the data to pass to the provider.

  3. Place data in this buffer. (For more information, see the next procedure.)

  4. Call a method that sets data and passes the handle to the accessor and a pointer to the buffer.

For each column or input parameter specified in the accessor, the consumer performs the following actions. When passing key values to an index rowset, the consumer performs these actions only for the number of key columns specified in the cKeyValues argument in IRowsetIndex::Seek or in the cStartKeyValues or cEndKeyValues arguments in IRowsetIndex::SetRange.

Note   This procedure assumes that the consumer has bound the value, length, and status for each column or input parameter. If any of these are not bound, the actions to be performed are the same except that the consumer does not set the unbound part.

  1. If the data is NULL, the consumer sets the status to DBSTATUS_S_ISNULL and proceeds to the next column or input parameter.

    If the provider is to use the default as the input value for an input or input/output parameter in a procedure, or if the provider updates the column, the consumer sets the status to DBSTATUS_S_DEFAULT and proceeds to the next column or input parameter.

    If the provider is to ignore this column in performing an insert or update, the consumer sets the status to DBSTATUS_S_IGNORE.

    Otherwise, the consumer sets the status to DBSTATUS_S_OK.

    The address where the status value is stored is calculated from the buffer address passed to the method and the obStatus element of the binding.

  2. If wType is a variable-length data type, the consumer sets the length to the length of the data in bytes, not counting the null-termination character for strings.

    For all other data types, the provider ignores the length, so the consumer does not need to set it.

  3. The consumer sets the data value.

    The address where the data value is stored is calculated from the buffer address passed to the method and the obValue element of the binding. If wType is DBTYPE_BSTR or is combined with DBTYPE_BYREF, DBTYPE_VECTOR, or DBTYPE_ARRAY, the consumer stores the data in separately allocated memory and stores in its buffer a pointer to the data. For information about how this memory is allocated and freed, see "Responsibility for Freeing Memory," earlier in this chapter.

For each column or input parameter specified in the accessor, the provider performs the following actions. When passing key values to an index rowset, the provider performs this procedure only for the number of key columns specified in the cKeyValues argument in IRowsetIndex::Seek or in the cStartKeyValues or cEndKeyValues arguments in IRowsetIndex::SetRange. This procedure assumes that the consumer has bound the value, length, and status for each column or input parameter. If any of these are not bound, the procedure is the same except that the provider does not attempt to retrieve the unbound part from the consumer's buffer. For more information, see "Binding Data Values," earlier in this chapter.

  1. If it has not already done so, the provider validates the accessor against the metadata.

    The provider can validate the entire accessor before setting any data or on a binding-by-binding basis while setting data. If validation fails before the provider sets data, the provider produces the appropriate return code and does not set any data. If it fails when the provider is setting data, the provider sets the status to DBSTATUS_E_BADACCESSOR and proceeds to the next column or output parameter.

  2. The provider retrieves the status value from the consumer's buffer, depending on the status setting, as follows:

    If the status is any other value, the provider sets the status to DBSTATUS_E_BADSTATUS and proceeds to the next column or input parameter.

    The address from which the status value is retrieved is calculated from the buffer address passed to the method and the obStatus element of the binding.

  3. If wType is a variable-length data type, the provider retrieves the length from the consumer's buffer.

    For all other data types, the provider ignores the length. The address from which the length value is retrieved is calculated from the buffer address passed to the method and the obLength element of the binding.

  4. The provider retrieves the data value from the consumer's buffer. The address from which the data value is retrieved is calculated from the buffer address passed to the method and the obValue element of the binding.
  5. The provider converts the data from the type that is stored in the consumer's buffer, as specified by the wType element of the binding, to the type of the column or input parameter.

    If an error occurs while converting the data, the provider sets the status accordingly and proceeds to the next column or output parameter. For a list of status values that describe conversion errors, see "Status Values Used When Setting Data" in "Status," earlier in this chapter. For more information about converting data, see "Data Type Conversion Rules" in Appendix A, "Data Types."

If the provider encounters an error while retrieving a column or input parameter value, it sets the status value of that column or input parameter. Depending on the provider, it also does one of the following:

If the provider stops processing, it must set the status value to DBSTATUS_E_UNAVAILABLE for any column or input parameter that was not in error and was not successfully set. Thus, the consumer can determine which column or input parameter values were valid, which were invalid, and which were not validated.

When setting column data, except when searching for a key value or setting the index range, the provider then produces one of the following return codes:

When setting input parameter data, searching for a key value, or setting the index range, the provider then returns DB_E_ERRORSOCCURRED.