Compartir a través de


Using Type Indicators When Creating Tables

Consumers can create tables in two ways. One is to call ICommand::Execute on a command object containing an SQL CREATE TABLE statement as its command text. (For more information, see Commands.) The other is to call either ITableDefinition::CreateTable or ITableDefinitionWithConstraints::CreateTableWithConstraints. When creating a table by calling ITableDefinition or ITableDefinitionWithConstraints methods, the consumer creates a DBCOLUMNDESC structure whose elements specify the columns of the table. The wType and pwszTypeName elements of this structure correspond to the DATA_TYPE and TYPE_NAME column values from the PROVIDER_TYPES schema rowset. A consumer is guaranteed to always get a safe conversion when getting or setting values of the column by using the type indicator specified in wType.

For example, a provider built on top of an SQL-92?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.

For more information about the DBCOLUMNDESC structure, see ITableDefinition::CreateTable in the reference section.