Using Type Indicators When Creating Tables

A consumer can create a table through ICommandText or ITableDefinition. If a provider supports ICommandText, then a consumer builds a text command to create a table, such as an SQL CREATE TABLE statement, using the value of the TYPE_NAME column in the PROVIDER_TYPES schema rowset. OLE DB does not define standard type names, which saves providers from having to parse such text commands and replace standardized names with provider-specific names. No type indicators are involved in this process.

If the provider supports ITableDefinition, then columns are described using the DBCOLUMNDESC structure. The wType and pwszTypeName elements of this structure correspond to the DATA_TYPE and TYPE_NAME column values from the PROVIDER_TYPES schema rowset. In most cases, there is no reason for a consumer to specify values for wType and pwszTypeName that are different than the values listed in the PROVIDER_TYPES schema rowset. A consumer is guaranteed to always get a safe conversion when getting or setting values of the column using the type indicator specified in wType.

For example, a provider built on top of an ANSI SQL92–compliant DBMS might contain the following rows in the PROVIDER_TYPES schema rowset.


TYPE_NAME

DATA_TYPE
COLUMN_
SIZE
MINIMUM_
SCALE
MAXIMUM_
SCALE
"CHAR" DBTYPE_STR 32000 NULL NULL
"VARCHAR" DBTYPE_STR 32000 NULL NULL

For the CHAR type, COLUMN_SIZE indicates the maximum length in characters of a value of that type supported by this provider. When defining a column of this type, the consumer is free to assign any value between 1 and 32000 to the ulColumnSize element of the DBCOLUMNDESC structure associated with the column. Internally, the provider may choose any representation for values of the type, provided that it always returns data to the consumer as a null-terminated string.