MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 6: Getting and Setting Data
To get data—for example, by using IRowset::GetData for rowset data or ICommand::Execute for output parameter data—the consumer must perform the following actions:
For each column or output parameter specified in the accessor, the provider performs the actions in the following procedure. This procedure assumes that the consumer has bound the value, length, and status for each column or output parameter. If any of these are not bound, the procedure is the same except that the provider does not return the unbound part.
Note If the accessor is a reference accessor, the provider does not follow this procedure but returns a pointer to the provider's memory that contains the data. For more information, see "Reference Accessors," earlier in this chapter.
The provider can validate the entire accessor before returning any data or on a binding-by-binding basis while returning data. If validation fails in the former case, the provider produces the appropriate return code and does not return any data. If it fails in the latter case, the provider sets the status of the column or output parameter to DBSTATUS_E_BADACCESSOR and proceeds to the next column or output parameter.
If it is, either the provider sets the status to DBSTATUS_S_ISNULL and ignores the value and length or the provider sets the status to DBSTATUS_S_OK and sets the value to VT_EMPTY. The provider then proceeds to the next column or output parameter. The address where the status value is placed is calculated from the buffer address passed to the method and the obStatus element of the binding. A variant whose type is VT_NULL is different from a column status of DBSTATUS_S_ISNULL. Providers supporting variants, as well as consumers binding to variants, must be prepared to handle either type of NULL. However, if DBSTATUS_S_ISNULL is specified in the status binding, the contents of the value binding, regardless of type, are undefined.
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 Getting Data" in "Status," earlier in this chapter. For more information about converting data, see "Data Type Conversion Rules" in Appendix A, "Data Types."
The address where the length value is placed is calculated from the buffer address passed to the method and the obLength element of the binding as follows:
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 as follows:
If the type indicator is DBTYPE_IUNKNOWN or DBTYPE_IDISPATCH, the data value is a pointer to an interface on the COM object, not the object itself. For more information, see Chapter 7, "BLOBs and COM Objects."
If the type indicator is DBTYPE_BSTR, the provider places the converted data in a BSTR and places the BSTR in the consumer's buffer. The provider ignores cbMaxLen. It does not truncate the data before placing it in the consumer's buffer. For information about how the BSTR is allocated and freed, see "Responsibility for Freeing Memory," earlier in this chapter.
If the provider encounters an error while returning a column or output parameter value, it sets the status value of that column or output parameter. The provider then continues to process the remaining columns or output parameters. After it has processed all columns or output parameters, if one or more errors have occurred, the provider produces one of the following return codes:
The consumer checks the status values to determine the columns or output parameters for which data was successfully returned. If the consumer did not bind a status value for a column or output parameter and a method returns DB_S_ERRORSOCCURRED or DB_E_ERRORSOCCURRED, the consumer must assume that all column or output parameter values were not successfully returned.
The provider frees any memory it allocated for return to the consumer but did not return to the consumer due to an error. If the method fails completely, the contents of the consumer's buffer are undefined.