MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 4: Rowsets


 

Column IDs

Consumers use column IDs primarily when executing commands on data stores for which there are no stable column ordinals. Because column IDs are relatively slow to use on a repeated basis, consumers use column ordinals to identify columns in DBBINDING structures. (For more information about DBBINDING structures, see "DBBINDING Structures" in Chapter 6, "Getting and Setting Data.") 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 Meaning
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.

Consumers should treat table and column names within DBID structures as case-sensitive.

Column IDs must be unique within the data store.

OLE DB providers never return pGuid-style bindings. They are provided as a convenient shortcut for consumers supplying bindings all covered by the same GUID (for example, when creating bindings to access data).

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 schema 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.