Sets data values in one or more columns in a row.
HRESULT SetData ( HROW hRow, HACCESSOR hAccessor, void *pData);
Parameters
Return Code
This return code takes precedence over DB_S_ERRORSOCCURRED. That is, if the conditions described here and in those described in DB_S_ERRORSOCCURRED both occur, the provider returns this code. When the consumer receives this return code, it should also check for the conditions described in DB_S_ERRORSOCCURRED.
Note The spec, as of 2.1, does not require this return code if the corresponding bit is not set.
Comments
If this method performs deferred accessor validation and that validation takes place before any data is transferred, it can also return any of the following return codes for the applicable reasons listed in the corresponding DBBINDSTATUS values in IAccessor::CreateAccessor:
E_NOINTERFACE
DB_E_BADBINDINFO
DB_E_BADORDINAL
DB_E_BADSTORAGEFLAGS
DB_E_UNSUPPORTEDCONVERSION
IRowsetChange::SetData sets data values in one or more columns in a row. For a complete description of how SetData sets data, see "Setting Data" in Chapter 6: Getting and Setting Data.
In delayed update mode, these changes are buffered locally in the rowset and are transmitted to the data store only when IRowsetUpdate::Update is called. In immediate update mode, the changes are immediately transmitted to the data store. For more information, see "Changing Data" in Chapter 5; Updating Data in Rowsets.
If a computed column depends on a column that is changed with IRowsetChange::SetData, the provider is not required to compute the new value of the computed column. If the provider computes the new value, it sends a notification to the consumer. If the provider does not compute the new value but lets the data store do so, the computed value is not available until after the change is transmitted to the data store—that is, after IRowsetChange::SetData is called in immediate update mode or after IRowsetUpdate::Update if SetData is called in delayed update mode. Whenever the provider detects that the data store has computed a new column value, it is required to send a COLUMN_RECALCULATED notification to the consumer. To retrieve the computed value in this case, the consumer calls RefreshVisibleData or GetLastVisibleData in IRowsetRefresh. Bookmark columns are often computed—for example, when the bookmark is the primary key or is a ROWID assigned by the data store.
If IRowsetChange::SetData changes a column that is used to order the rowset, the DBPROP_IMMOBILEROWS property describes whether the row is moved based on its new value. If this property is VARIANT_TRUE, the row is not moved. If this property is VARIANT_FALSE, the row is moved. If the rowset is not ordered, the position of updated rows is not changed. If the rowset is built on a set of key columns (typically a rowset for which DBPROP_OTHERUPDATEDELETE is VARIANT_TRUE but DBPROP_OTHERINSERT is VARIANT_FALSE), changing the value of key column is generally equivalent to deleting the current row and inserting a new one. Therefore, the row may appear to move or even disappear from the rowset (if DBPROP_OWNINSERT is VARIANT_FALSE), even though the DBPROP_IMMOBILEROWS property is VARIANT_TRUE.
When the consumer passes a pointer to a storage object to IRowsetChange::SetData, SetData replaces the data in the column with the data in the new storage object. If the consumer wants only to delete the data in the column, it sets the column status to DBSTATUS_S_OK and passes a null pointer instead of a pointer to a storage object. For more information, see "Getting and Setting BLOB Data with Storage Objects" in Chapter 7: BLOBs and COM Objects. If the rowset is in immediate update mode, storage object data is always transmitted immediately to the data store. If it is in delayed update mode, whether it is transmitted immediately or delayed depends on the DBPROP_DELAYSTORAGEOBJECTS property.
When setting rowset column data values from a consumer's storage object, the provider is responsible for releasing the storage object. When the provider has finished using the consumer's storage object, it calls IUnknown::Release to release the pointer. If the consumer wants to ensure access to its storage object after IRowsetChange::SetData returns, it must call IUnknown::AddRef on the pointer before calling IRowsetChange::SetData.
It is the consumer's responsibility to release VARIANTs stored in *pData. The consumer should call the COM method VariantClear when a VARIANT is no longer needed.
Although IRowsetChange::SetData can detect domain constraint and some table constraint schema violations, it is not required to do so. Such validation can be delayed until the changes are transmitted to the data store with IRowsetUpdate::Update or the transaction is committed with ITransaction::Commit. This delay is often necessary because of dependencies on values in other columns or tables.
IRowsetChange::SetData cannot be called for rows with pending or transmitted deletes.
The DBPROP_COLUMNRESTRICT and DBPROP_ROWRESTRICT properties affect how security is enforced and how security errors are returned. If DBPROP_COLUMNRESTRICT is VARIANT_TRUE, the consumer will not have write permission on at least one column. If the consumer attempts to write to these columns, IRowsetChange::SetData returns a column status of DBSTATUS_E_PERMISSIONDENIED and a return code of DB_S_ERRORSOCCURRED. If the DBPROP_ROWRESTRICT property is VARIANT_TRUE, the consumer might not have permission to update some rows. If the consumer attempts to update one of
these rows, IRowsetChange::SetData returns a code of DB_SEC_E_PERMISSIONDENIED and no data is set.
If any consumer of the rowset is using notifications, the provider sends notifications. These notifications can be vetoed, in which case the provider sends the DBEVENTPHASE_FAILEDTODO phase of the notification. When the consumer then calls IRowsetUpdate::Update, if the update is in delayed mode, the provider does not send additional DBREASON_COLUMN_SET notifications for the rows. However, if IRowsetUpdate::Update computes the value of computed columns, it sends DBREASON_COLUMN_RECALCULATED notifications. In this case, the provider must either be prepared to undo all pending changes for the row, and return DBREASON_ROW_UNDOCHANGE, or set the fCantDeny flag to TRUE.
The following sequence of notifications occurs for a rowset operating in delayed update mode:
IRowset::GetData | IRowsetChange::InsertRow | IRowsetUpdate::Undo | IRowsetUpdate::Update