Partager via


Fixed-Length and Variable-Length Data Types

The provider determines how much memory to allocate for each data value based on its data type indicator. For fixed-length data types, such as Booleans and integers, the provider simply allocates enough space to hold one item of that type. For variable-length data types, the provider must rely on the consumer to specify how much memory must be allocated for the data. The consumer does this by setting the value of cbMaxLen appropriately.

When the length part of a binding is applied to a column, the length includes all bytes of the value. It should be the same as the length passed to IMalloc to allocate a buffer big enough to hold the data value. For strings, this length must include space for a null-termination character. If the value is to be converted, the length should be the length in bytes that the value has after it is converted into the type specified by the consumer.

If a variable-length string value is copied into a buffer that is too small to hold it, the string is truncated abruptly to fit the buffer. No attempt is made to trailing-align or trim the value, although strings are null-terminated. The returned length is the length in bytes of the untruncated value, which the consumer can compare to cbMaxLen to determine how many bytes were lost when the string was truncated.

Note

Variable-length numeric data values are not truncated. Attempting to copy a variable-length numeric value into a buffer that is too small to hold the entire value is a programming error.

DBTYPE_BYREF, DBTYPE_ARRAY, and DBTYPE_VECTOR are modifiers of data types and do not affect whether a data type is fixed-length or variable-length. However, these modifiers do affect how data is stored and how cbMaxLen is used in the DBBINDING structure.

For a complete list of fixed-length and variable-length data types, see Fixed-Length Data Types and Variable-Length Data Types in Appendix A: Data Types.