Creates an accessor from a set of bindings.
HRESULT CreateAccessor ( DBACCESSORFLAGS dwAccessorFlags, DBCOUNTITEM cBindings, const DBBINDING rgBindings[], DBLENGTH cbRowSize, HACCESSOR *phAccessor, DBBINDSTATUS rgStatus[]);
Parameters
Value | Description |
---|---|
DBACCESSOR_INVALID | This flag is used by IAccessor::GetBindings to indicate that the method failed. |
DBACCESSOR_PASSBYREF | The accessor is a reference accessor.
The value passed in the consumer buffer is a pointer to the passer's internal buffer. This pointer need not point to the start of the internal buffer as long as the relative offsets of all elements of the buffer align with the offsets specified in the accessor. The passee must know the internal structure of the passer's buffer in order to read information from it. The passee must not free the buffer at the pointer nor may it write to this buffer. For row accessors, this buffer is the rowset's copy of the row. The consumer reads information directly from this copy of the row at a later point in time, so the provider must guarantee that the pointer remains valid. For parameter accessors, this buffer is the consumer's buffer. The provider reads data from this buffer only when ICommand::Execute is called, so the pointer is not required to remain valid after Execute returns. Support for this flag is optional. A consumer determines whether a provider supports this bit by calling IDBProperties::GetProperties for the DBPROP_BYREFACCESSORS property. When this flag is used, the dwMemOwner in the DBBINDING structure is ignored. If the accessor is used for row data, the accessor refers to the provider's memory; the consumer must not write to or free this memory. If the accessor is used for input parameters, the provider copies the row of data without assuming ownership. It is an error to specify an output or input/output parameter in a reference accessor. For more information, see "Reference Accessors" in Chapter 6: Getting and Setting Data. |
DBACCESSOR_ROWDATA | The accessor is a row accessor and describes bindings to columns in the rowset.
An accessor may be a row accessor, a parameter accessor, or both. |
DBACCESSOR_PARAMETERDATA | The accessor is a parameter accessor and describes bindings to parameters in the command text. In a parameter accessor, it is an error to bind an input or an input/output parameter more than once. |
DBACCESSOR_OPTIMIZED | The row accessor is to be optimized. This hint may affect how a provider structures its internal buffers. A particular column can be bound by only one optimized accessor. The column can also be bound by other, nonoptimized accessors, but the types specified in the nonoptimized accessors must be convertible from the type in the optimized accessor. All optimized accessors must be created before the first row is fetched with IRowset::GetNextRows, IRowsetLocate::GetRowsAt, IRowsetLocate::GetRowsByBookmark, or IRowsetScroll::GetRowsAtRatio.
This flag is ignored for parameter accessors and may be ignored by providers that do not provide further optimizations or restrictions based on its setting. Providers that enforce restrictions, such as limiting the number or types of columns bound in optimized accessors, must set this flag when IAccessor::GetBindings is called on an optimized accessor. Providers that do not impose any restrictions on optimized accessors or that ignore this flag entirely are not required to return this flag when IAccessor::GetBindings is called. |
DBACCESSOR_INHERITED | Indicates an accessor on a command should be inherited by a rowset when the rowset implementation is in a separate component from the command object. IAccessor::CreateAccessor is then used to pass an existing command accessor to the rowset implementation.
When DBACCESSOR_INHERITED is specified, phAccessor is used as an [in] argument and contains a pointer to the value of the existing accessor handle. The rowset component then creates an internal accessor according to the specified bindings for this handle value. |
If cBindings is zero, IAccessor::CreateAccessor creates a null accessor. Null accessors are used only by IRowsetChange::InsertRow to create a new row in which each column is set to its default value, NULL, or a status of DBSTATUS_E_UNAVAILABLE. Providers that support IRowsetChange::InsertRow must support the creation of null accessors. For more information, see InsertRow.
cbRowSize is used by ICommand::Execute to process multiple sets of parameters and by IViewFilter::GetFilter and IViewFilter::SetFilter to get and set multiple OR conditions in criteria. In either case, a single accessor may describe multiple sets of values. cbRowSize is generally the size of the structure that contains a single set of parameter or criteria values and is used as the offset to the start of the next set of values within the array of structures. For example, if cParamSets is greater than 1 in the DBPARAMS structure passed to ICommand::Execute, the provider assumes that the pData element of this structure points to an array of structures containing parameter values, each cbRowSize bytes in size. Similarly, if cRows is greater than 1 in IViewFilter::SetFilter, the provider assumes that the pCriteriaData argument points to an array of structures containing criteria values, each cbRowSize bytes in size.
cbRowSize must be large enough to contain the structure defined by the bindings in rgBindings. The provider is not required to verify this, although it may.
cbRowSize is not used when fetching rowset data.
Value | Description |
---|---|
DBBINDSTATUS_OK | No errors were found in the binding. Because accessor validation can be deferred, a status of DBBINDSTATUS_OK does not necessarily mean that the binding was successfully validated. |
DBBINDSTATUS_BADORDINAL | A parameter ordinal was zero in a parameter accessor.
If the accessor is validated against the metadata when IAccessor::CreateAccessor is called, DBBINDSTATUS_BADORDINAL can be returned for the following reasons:
These reasons cause a status value of DBSTATUS_E_BADACCESSOR to be returned if the accessor is validated when used. Some providers may support binding more parameters than the number of parameters in the command text, and such providers do not return DBBINDSTATUS_BADORDINAL in this case. |
DBBINDSTATUS_UNSUPPORTEDCONVERSION | If the accessor is validated against the metadata when IAccessor::CreateAccessor is called, DBBINDSTATUS_UNSUPPORTEDCONVERSION can be returned for the following reasons:
These reasons cause a status value of DBSTATUS_E_BADACCESSOR to be returned if the accessor is validated when used. |
DBBINDSTATUS_BADBINDINFO | dwPart in a binding was not a combination of two or more of the following:
DBPART_VALUE eParamIO in a binding in a parameter accessor was not one of the following: DBPARAMIO_INPUT A row accessor was optimized, and a column ordinal in a binding was already used in another optimized accessor. In a parameter accessor, two or more bindings contained the same ordinal for an input or input/output parameter. wType in a binding was DBTYPE_EMPTY or DBTYPE_NULL. wType in a binding was one of the following: DBTYPE_BYREF | DBTYPE _EMPTY, wType in a binding was used with more than one of the following mutually exclusive type indicators: DBTYPE_BYREF, DBTYPE_ARRAY, or DBTYPE_VECTOR. Provider-owned memory was specified for a nonpointer type in a nonreference row accessor. Provider-owned memory was specified for a column, and the provider does not support binding to provider-owned memory for this column. Provider-owned memory was specified for a column for which IColumnsInfo::GetColumnInfo returned DBCOLUMNFLAGS_ISLONG, and the provider does not support binding long data to provider owned memory. In a nonreference parameter accessor, a binding specified provider-owned memory. An output or input/output parameter was specified in a parameter reference accessor. dwFlags in a binding was set to DBBINDFLAG_HTML, and wType for the same binding was not a string value. The provider is an OLE DB 2.5 or later provider, and dwFlags was set to an unknown or invalid value. dwMemOwner was invalid. Providers are not required to return DBBINDSTATUS_BADBINDINFO. If they ignore an invalid value of dwMemOwner, they must default to DBMEMOWNER_CLIENTOWNED. If the accessor is validated against the metadata when IAccessor::CreateAccessor is called, DBBINDSTATUS_BADBINDINFO can be returned for the following reasons:
|
DBBINDSTATUS_BADSTORAGEFLAGS | dwFlags, in the DBOBJECT structure pointed to by a binding, specified invalid storage flags.
If the accessor is validated against the metadata when IAccessor::CreateAccessor is called, DBBINDSTATUS_BADSTORAGEFLAGS can be returned if dwFlags, in the DBOBJECT structure pointed to by a binding, specified a valid storage flag that was not supported by the object. This causes a status value of DBSTATUS_E_BADACCESSOR to be returned if the accessor is validated when used. |
DBBINDSTATUS_NOINTERFACE | If the accessor is validated against the metadata when IAccessor::CreateAccessor is called, DBBINDSTATUS_NOINTERFACE can be returned for the following reasons:
These reasons cause a status value of DBSTATUS_E_BADACCESSOR to be returned if the accessor is validated when used. |
Return Code
cBindings was not zero, and rgBindings was a null pointer.
The DBACCESSOR_PARAMETERDATA bit was set in dwAccessorFlags, and the provider does not support parameters.
Neither the DBACCESSOR_PARAMETERDATA bit nor the DBACCESSOR_ROWDATA bit was set in dwAccessorFlags.
A method that fetches rows (IRowset::GetNextRows, IRowsetLocate::GetRowsAt, IRowsetLocate::GetRowsByBookmark, or IRowsetScroll::GetRowsAtRatio) had already been called, and the DBACCESSOR_OPTIMIZED bit in dwAccessorFlags was set.
The DBACCESSOR_ PARAMETERDATA bit was set, and IAccessor::CreateAccessor was called on a rowset.
Consumers should always check to see whether the provider supports the property DBPROP_BYREFACCESSORS and call IAccessor::CreateAccessor with the DBACCESSOR_PASSBYREF flag only if the provider supports this property. For performance reasons, some service providers might be unable to detect whether the underlying data provider supports DBACCESSOR_PASSBYREF on the CreateAccessor call and might return DB_E_BYREFACCESSORNOTSUPPORTED.
Comments
For general information about accessors, see "Accessors" in Chapter 6: Getting and Setting Data.
IAccessor::CreateAccessor always checks all error conditions that do not require it to validate the accessor against the metadata. As a general rule, this means it checks the error conditions for all of the return codes except those that return DB_E_ERRORSOCCURRED. CreateAccessor may validate the accessor against the metadata for row accessors created on the rowset; it never validates the accessor against the metadata for row or parameter accessors created on the command. When CreateAccessor validates the accessor against the metadata, it validates each binding in the accessor, setting the appropriate DBBINDSTATUS values as it goes. If CreateAccessor fails in any way, it does not create the accessor and sets *phAccessor to a null handle.
If IAccessor::CreateAccessor does not validate the accessor against the metadata, the validation is said to be delayed. CreateAccessor simply creates the accessor and validation is done by the first method that uses the accessor. If the accessor is found to be invalid, it remains in existence and can be used again.
If accessor validation is delayed, the provider determines whether the method validating the accessor validates it against the metadata before or during data transfer. If the method validates the accessor before transferring any data, it can return any of the return codes listed below for this purpose. If the method validates the accessor while transferring the data, it sets the status value of any column or parameter for which the accessor is invalid (within the context of the method) to DBSTATUS_E_BADACCESSOR and returns DB_S_ERRORSOCCURRED or DB_E_ERRORSOCCURRED. Whether the method continues processing other columns or parameters depends on both the method and the provider.
The return codes listed in the following table are returned by methods that perform delayed accessor validation before transferring any data. The DBBINDSTATUS value to which each corresponds is also listed.
Return code | DBBINDSTATUS value |
---|---|
E_NOINTERFACE | DBBINDSTATUS_NOINTERFACE |
DB_E_BADBINDINFO | DBBINDSTATUS_BADBINDINFO |
DB_E_BADORDINAL | DBBINDSTATUS_BADORDINAL |
DB_E_BADSTORAGEFLAGS | DBBINDSTATUS_BADSTORAGEFLAGS |
DB_E_UNSUPPORTEDCONVERSION | DBBINDSTATUS_UNSUPPORTEDCONVERSION |
Providers that do not support conversion of BLOB or non-BLOB data to a data structured storage interface should fail the accessor creation method with DB_E_ERRORSOCCURRED and report DBBINDSTATUS_UNSUPPORTEDCONVERSION on the column specifying the incorrect binding.
IAccessor::GetBindings | IAccessor::ReleaseAccessor | IConvertType::CanConvert | IRowset::GetData | IRowsetChange::SetData