Column IDs

Consumers use column IDs to identify columns, primarily in commands where there are no stable ordinals. Because column IDs are relatively slow to use, consumers use column ordinals to identify columns in bindings. A consumer calls IColumnsInfo::MapColumnIDs to retrieve a column ordinal from a column ID:

typedef struct  tagDBID {
 union {
  GUID guid;
  GUID * pguid;
 } uGuid;
 DBKIND eKind;
 union {
  LPOLESTR pwszName;
  ULONG  ulPropid;
 } uName;
} DBID;

The values of DBKIND are described in the following table.

Value Description
DBKIND_GUID_NAME Use the guid and pwszName elements.
DBKIND_GUID_PROPID Use the guid and ulPropid elements.
DBKIND_NAME Use only the pwszName element; ignore the uGuid element.
DBKIND_PGUID_NAME Use the pGuid and pwszName elements.
DBKIND_PGUID_PROPID Use the pGuid and ulPropid elements.
DBKIND_PROPID Use only the ulPropid element; ignore the uGuid element.
DBKIND_GUID Use only the guid element; ignore the uName element.

The members of a DBID are represented in schema rowset columns as follows.

DBID eKind Schema columns
DBKIND_GUID_NAME _GUID and _NAME column values must be provided.
DBKIND_GUID_PROPID _GUID and _PROPID column values must be provided.
DBKIND_NAME _NAME column value must be provided.
DBKIND_PGUID_NAME _GUID and _NAME column values must be provided.
DBKIND_PGUID_PROPID _GUID and _PROPID column values must be provided.
DBKIND_PROPID _PROPID column value must be provided.
DBKIND_GUID _GUID column value must be provided.

OLE DB providers never return pGuid-style bindings (for example, when the consumer inquires about the bindings for an accessor). They are provided as a convenient shortcut for consumers supplying bindings all covered by the same GUID, which is expected to be common.

The value DB_NULLID is defined as the DBID structure containing all zeroes. Because pwszName is a null pointer for DB_NULLID, you should not attempt to free this string.

When constructing DBIDs to identify tables, indexes, or columns, consumers use the non-null columns in the appropriate schema rowset to determine the DBKIND value of the DBID. For example, when specifying a table ID, a consumer would call IDBSchemaRowset::GetRowset and examine the TABLES rowset. On discovering that TABLE_NAME has a value and TABLE_GUID is NULL, the consumer specifies DBKIND_NAME for the table ID. In methods that take column DBIDs as parameters, the validation of the DBID should include a check on the validity of the DBID's eKind.