IDataConvert::DataConvert

Converts the data from the source type to the destination type.

HRESULT DataConvert (
   DBTYPE             wSrcType,
   DBTYPE             wDstType,
   ULONG              cbSrcLength,
   ULONG *            pcbDstLength,
   void *             pSrc,
   void *             pDst,
   ULONG              cbDstMaxLength,
   DBSTATUS           dbsSrcStatus,
   DBSTATUS *         pdbsStatus,
   BYTE               bPrecision,
   BYTE               bScale,
   DBDATACONVERT      dwFlags);

Parameters

wSrcType

[in]
The source type of the data to be converted.

wDstType

[in]
The destination type of the data to be converted.

cbSrcLength

[in]
The length of the source data in bytes.

pcbDstLength

[out]
A pointer to memory in which to return the length in bytes of the output data after conversion.

pSrc

[in]
A pointer to the source data. Note that this is a pointer to the underlying data type, based upon the value of wSrcType. For example, this would be the address of the BSTR pointer if wSrcType is DBTYPE_BSTR, not the BSTR pointer itself.

pDst

[out]
A pointer to memory in which to return the destination data. As in the case of pSrc, this is a pointer to the underlying data type, based upon the value of wDstType.

cbDstMaxLength

[in]
The maximum allowable length of the destination data in bytes. This is used only for variable length destination data types.

dbsSrcStatus

[in]
The status value for the source data.

pdbsStatus

[out]
A pointer to the status for the conversion.

bPrecision

[in]
The precision of the output data in bytes, if applicable. This argument is used when converting to DBTYPE_NUMERIC data only.

bScale

[in]
The scale of the output data in bytes, if applicable. This argument is used when converting to DBTYPE_NUMERIC data only.

dwFlags

[in]
The data-conversion flag indicating the requested conversion behavior. These flags can be combined.

The following flags are available:

typedef DWORD DBDATACONVERT;
enum DBDATACONVERTENUM{
 DBDATACONVERT_DEFAULT           = 0,
 DBDATACONVERT_SETDATABEHAVIOR   = 1,
 DBDATACONVERT_LENGTHFROMNTS     = 2
};

The DBDATACONVERT_SETDATABEHAVIOR flag indicates that data truncation is an error and that the memory pointed to by pDst will not be changed if any error occurs.

The DBDATACONVERT_LENGTHFROMNTS flag indicates that the data conversion library should calculate cbSrcLength for string (DBTYPE_STR, DBTYPE_WSTR) source data.

Return Code

S_OK
The conversion succeeded.

E_FAIL
pSrc was a null pointer.

E_OUTOFMEMORY
The data conversion object was unable to allocate memory.

DB_E_BADBINDINFO
The source or destination data type was invalid.

DB_E_DATAOVERFLOW
The requested conversion resulted in an overflow.

DB_E_ERRORSOCCURRED
Errors occurred while converting data. The requested conversion can fail for a number of reasons, including:

DB_E_UNSUPPORTEDCONVERSION
The requested conversion was not supported.