Specifies the native data type of each parameter.
This method does not set type information for any parameter if it does not successfully set type information for every parameter. Otherwise, this method sets information for all parameters.
Providers generally derive parameter type information from the data store and return it to the consumer through ICommandWithParameters::GetParameterInfo. Consumers then use this information to build parameter accessors for use with ICommand::Execute.
Some providers — notably many SQL database providers — cannot derive parameter type information from the data store. For these providers, the consumer must supply the native parameter type information through ICommandWithParameters::SetParameterInfo. The provider uses the type information specified by ICommandWithParameters::SetParameterInfo to determine how to convert parameter data from the type supplied by the consumer (as indicated by the wType value in the binding structure) to the native type used by the data store. When the consumer specifies a data type with known precision, scale, and size values, any information supplied by the consumer for precision, scale, or size should be ignored by the provider.
The information that the consumer supplies must be correct and must be supplied for all parameters. Providers that cannot derive parameter type information cannot verify the supplied information against the parameter metadata, although they can determine that the specified values are legal values for the provider. Such providers sometimes cannot even determine the number of parameters in the command. The result of executing a command using incorrect parameter information or passing parameter information for the wrong number of parameters is undefined. For example, if the parameter type is LONG and the consumer specifies a type indicator of DBTYPE_STR in ICommandWithParameters::SetParameterInfo, the provider converts the data to a string before sending it to the data store. Because the data store is expecting a LONG, this will likely result in an error.
When the consumer calls ICommandWithParameters::SetParameterInfo, it specifies a provider-specific data type name (as derived from the PROVIDER_TYPES schema rowset) or a standard type name. If the consumer passes a standard type name, the provider maps it to a provider-specific type name. For example, a provider for an SQL DBMS might map "DBTYPE_I2" to "SMALLINT".
When the consumer specifies a storage object of type DBTYPE_IUNKNOWN for a parameter, the consumer should call ICommandWithParameters::SetParameterInfo to designate a standard type name for the parameter that corresponds to the contents of the storage object (for example, "DBTYPE_WCHAR" for a Unicode stream). This standard type name must match the parameter type expected by the data store; the consumer should not specify a standard type name different from the data store type and expect the provider to perform a conversion. For maximum interoperability, providers are encouraged to accept the OLE DB DBTYPEs as synonyms for the standard type names.
The following is a list of standard type names and their associated type indicators. This list contains many commonly known types. Individual providers may allow other, provider-specific, names as well.
|
Standard type name
|
Type indicator
|
|---|
|
"DBTYPE_I1"
|
DBTYPE_I1
|
|
"D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YPE_BYTES
|
|
"DBTYPE_LONGVARBINARY"
|
DBTYPE_BYTES
|
|
"DBTYPE_FILETIME"
|
DBTYPE_FILETIME
|
|
"DBTYPE_VARNUMERIC"
|
DBTYPE_VARNUMERIC
|
|
"DBTYPE_PROPVARIANT"
|
DBTYPE_PROPVARIANT
|
After the consumer calls ICommandWithParameters::SetParameterInfo to specify the parameter type information, it can call ICommandWithParameters::GetParameterInfo to retrieve the type indicator for each parameter. These values — which are based on the information specified in ICommandWithParameters::SetParameterInfo — represent the best fit of OLE DB types to the native parameter types. The provider guarantees that if the consumer uses these types in a parameter accessor, it will be able to convert the data from the OLE DB type to the native parameter type.
If the provider can derive parameter type information and the consumer calls ICommandWithParameters::SetParameterInfo, SetParameterInfo uses the specified type information and returns DB_S_TYPEINFOOVERRIDDEN. Because deriving type information can be an expensive operation, this may result in more efficient code.
Calling SetParameterInfo with (0, NULL, NULL) discards existing parameter information and should return S_OK. However, if DB_S_TYPEINFOOVERRIDDEN is returned instead, consumers should query for verification that the method succeeded.