DBBINDING Structures
A binding associates a single column or parameter to the consumer's buffer and contains information about the buffer.
The DBBINDING structure describes a single binding:
typedef struct tagDBBINDING {
DBORDINAL iOrdinal;
DBBYTEOFFSET obValue;
DBBYTEOFFSET obLength;
DBBYTEOFFSET obStatus;
ITypeInfo *pTypeInfo;
DBOBJECT *pObject;
DBBINDEXT *pBindExt;
DBPART dwPart;
DBMEMOWNER dwMemOwner;
DBPARAMIO eParamIO;
DBLENGTH cbMaxLen;
DWORD dwFlags;
DBTYPE wType;
BYTE bPrecision;
BYTE bScale;
} DBBINDING;
Remarks
The elements of this structure are used as described in the following table.
Element |
Description |
---|---|
iOrdinal |
The ordinal of the column or parameter to which the binding applies. Column ordinals are fixed for the lifetime of the rowset. The self bookmark column is column 0, and other columns have values greater than or equal to 1. Rowset column ordinals start at 1 and are numbered sequentially in increasing order (for example, 1, 2, 3, and so on). When a row object is derived from a rowset, the row-specific column ordinals must come after the rowset column ordinals. To retrieve column ordinals, consumers call IColumnsInfo::GetColumnInfo, IColumnsRowset::GetColumnsRowset, or IColumnsInfo::MapColumnIDs. If the rowset is generated from a command, the column ordinals returned by GetColumnInfo or GetColumnsRowset on the rowset must match the column ordinals returned by the same methods on the command. To retrieve parameter ordinals, consumers call ICommandWithParameters::GetParameterInfo on the command object. |
obValue |
The offset in bytes in the consumer's buffer to the value part. The value of obValue is ignored unless the DBPART_VALUE bit is set in dwPart. For more information about the value part, see Value. This offset must be properly aligned for the processor architecture of the consumer's machine. If data is improperly aligned, consumers can expect alignment faults to occur when getting and setting data values. Consumers should use addresses that are multiples of the size of the data type. For example, if wType is DBTYPE_I4, the value part should be LONG aligned. |
obLength |
The offset in bytes in the consumer's buffer to the length part. The value of obLength is ignored unless the DBPART_LENGTH bit is set in dwPart. For more information about the length part, see Length. The length itself is a DBLENGTH. This offset must be properly aligned for the processor architecture of the consumer's machine. That is, it should be a multiple of sizeof(DBLENGTH). If it is improperly aligned, consumers can expect alignment faults when getting and setting length values. |
obStatus |
The offset in bytes in the consumer's buffer to the status part. The value of obStatus is ignored unless the DBPART_STATUS bit is set in dwPart. For more information about the status part, see Status. The status part itself is a DBSTATUS value, which is a DWORD. This offset must be properly aligned for the processor architecture of the consumer's machine. That is, it should be a multiple of sizeof(DWORD). If it is improperly aligned, consumers can expect alignment faults when getting and setting status values. |
pTypeInfo |
Reserved for future use. Consumers should set pTypeInfo to a null pointer. |
pObject |
Pointer to a DBOBJECT structure. For columns or parameters that can hold BLOBs or COM objects, this structure gives information needed to access the object:
The elements of this structure are used as follows:
The storage mode flags apply only to IRowset::GetData; IRowsetChange::SetData ignores dwFlags. The storage mode flags are defined by the Structured Storage model in COM. They are as follows:
To open a new, empty stream over the contents of the column, specify the STGM_CREATE flag. When the new stream is opened, the seek pointer is positioned at the beginning of the stream.
Note
If STGM_CREATE or STGM_WRITE is specified when opening a stream over a null column, the provider always returns an empty stream, as opposed to returning a null pointer or setting the DBSTATUS_S_ISNULL flag.
The value of pObject is ignored unless the DBPART_VALUE bit is set in dwPart and wType is DBTYPE_IUNKNOWN. If neither of these conditions is true, pObject should be set to a null pointer. A null value of pObject implies that both of the following statements are true:
Note
Consumers should not set wType to DBTYPE_IUNKNOWN and the DBPART_VALUE bit in dwPart without specifying a non-null value for pObject. However, providers can assume in this case that the interface to be bound is IID_IUnknown. If wType is DBTYPE_IUNKNOWN, the DBPART_VALUE bit in dwPart is set, and pObject is NULL, providers may assume when setting data or inserting rows that the consumer buffer contains a pointer to an object that supports at least IUnknown. Providers can then call IUnknown::QueryInterface for any interfaces they are interested in. If the call to QueryInterface succeeds, the provider uses the returned interface pointers to set the data for this column. If the object does not support one of these interfaces, the provider should return DBSTATUS_E_CANTCREATE.
|
pBindExt |
The DBBINDEXT structure can be used for future extensions to the binding structure. The pBindExt value is reserved for future use, and consumers should set it to a null pointer:
|
dwPart |
Specifies which buffer parts are to be bound to the column or parameter. It is one or more DBPARTENUM values combined. These values have the following meaning:
|
dwMemOwner |
For bindings in row accessors, specifies memory allocated by the provider for a column and for which a pointer is returned to the consumer. For example, when wType is DBTYPE_BYREF | DBTYPE_STR, the provider allocates memory for the string and returns a pointer to the string to the consumer. The dwMemOwner value specifies whether the consumer or provider is responsible for freeing this memory. The provider ignores this when the consumer sets rowset data. The following is a description of each of these values:
Pointer returned byMight be invalidated by
GetDataDeleteRows [1] RefreshVisibleDataSetDataUpdateUndo
GetLastVisibleDataGetLastVisibleData
GetOriginalDataRefreshVisibleDataSetDataUpdate
Although the consumer must not write to provider-owned memory, it can pass pointers to provider-owned memory when setting data. For example, suppose that the consumer wants to copy data efficiently from row A to row B. The consumer creates an accessor to the columns in row A in which wType is X | DBTYPE_BYREF and sets dwMemOwner to DBMEMOWNER_PROVIDEROWNED. When the consumer calls IRowset::GetData, the provider returns pointers to its copy of row A. The consumer then calls IRowsetChange::SetData for row B with the same accessor and a pointer to the memory passed to IRowset::GetData. The provider dereferences the pointers and copies the data from the rowset's copy of row A to the rowset's copy of row B. For bindings in row accessors, consumer-owned memory must be used unless wType is DBTYPE_BSTR, X | DBTYPE_BYREF, X | DBTYPE_ARRAY, or X | DBTYPE_VECTOR, in which cases either consumer-owned or provider-owned memory can be used. However, the provider might not support using provider-owned memory to retrieve columns for which IColumnsInfo::GetColumnInfo returns DBCOLUMNFLAGS_ISLONG for the column. Consumers can mix bindings for provider-owned and consumer-owned memory in the same accessor. For bindings in parameter accessors, consumer-owned memory must always be used. The value of dwMemOwner is ignored in reference accessors. All providers must support binding to client-owned memory. Providers support provider-owned memory only if they can efficiently return a pointer to a cached value. Providers are not required to support binding deferred columns to provider-owned memory. |
eParamIO |
For parameter accessors, eParamIO specifies whether the parameter with which the binding is associated is an input, input/output, or output parameter. Providers support only those parameter I/O types that are supported by their underlying data store. The value of eParamIO is one or more DBPARAMIOENUM values combined. These values have the following meaning:
For row accessors, the value of eParamIO is ignored. |
cbMaxLen |
The length in bytes of the consumer's data structure allocated for the data value. That is, it is the number of bytes allocated at offset obValue for the data value. The value of cbMaxLen is ignored unless the DBPART_VALUE bit is set in dwPart and the data value stored at that location is variable-length. For information about variable-length data types, see Fixed-Length and Variable-Length Data Types. The value of cbMaxLen is used as follows:
|
dwFlags |
The consumer can set dwFlags to specify information about how returned data is to be formatted. The following flags are recognized:
The provider should format the returned data in HTML. If the provider does not support HTML formatting, the bit is ignored and regular text is returned. DBBINDFLAG_OBJECT The provider should format the returned data as a COM object.
Note
These two dwFlags values cannot be combined.
|
wType |
The indicator of the data type of the value part of the buffer. For more information about type indicators, see Type Indicators in Appendix A: Data Types. This type forms an implied conversion between the buffer type and the type of the column or parameter. For information about conversions that providers are required to support, see Data Type Conversion. |
bPrecision |
The maximum precision to use when getting data and wType is DBTYPE_NUMERIC or DBTYPE_VARNUMERIC. This is ignored in three cases: when setting data; when wType is not DBTYPE_NUMERIC or DBTYPE_VARNUMERIC; and when the DBPART_VALUE bit is not set in dwPart. For more information, see Conversions Involving DBTYPE_NUMERIC or DBTYPE_DECIMAL in Appendix A: Data Types. |
bScale |
The scale to use when getting data and wType is DBTYPE_NUMERIC, DBTYPE_VARNUMERIC, or DBTYPE_DECIMAL. This is ignored in three cases: when setting data; when wType is not DBTYPE_NUMERIC, DBTYPE_VARNUMERIC, or DBTYPE_DECIMAL; and when the DBPART_VALUE bit is not set in dwPart. For more information, see Conversions Involving DBTYPE_NUMERIC or DBTYPE_DECIMAL in Appendix A: Data Types. |
[1] Immediate update mode.
Note
The offsets specified in obValue, obLength, and obStatus must not point to overlapping areas of memory. The provider is not required to check for the occurrence of this condition. Consumers must be careful to avoid this condition when constructing bindings.
Note
The memory of a dbBindings structure should be initialized prior to setting any values. Use the syntax memset(rgBindings, 0, cColumns * sizeof(DBBINDING));, to perform this action. The syntax usage is shown in the example Binding and Accessor Example
This topic is a part of: