Using Type Indicators When Creating Tables

OLE DB Programmer's Reference

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 Chapter 3: 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.

1998-2001 Microsoft Corporation. All rights reserved.



Microsoft Ole Db 2.0 Programmer's Reference and Data Access SDK
Microsoft OLE DB 2.0 Programmers Reference and Data Access SDK (Microsoft Professional Editions)
ISBN: 0735605904
EAN: 2147483647
Year: 1998
Pages: 1083

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net