Share via


IDataConvert::DataConvert

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

Syntax

HRESULT DataConvert (
   DBTYPE          wSrcType,
   DBTYPE          wDstType,
   DBLENGTH        cbSrcLength,
   DBLENGTH *      pcbDstLength,
   void *          pSrc,
   void *          pDst,
   DBLENGTH        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.

    DataConvert function does properly apply the scale input parameter when the destination data type is DB_TYPE_NUMERIC. There is a new DBDATACONVERT flag, DBDATACONVERT_DECIMALSCALE that instructs DataConvert to scale on conversion to DB_TYPE_NUMERIC.

  • 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. This is a pointer to the underlying data type, based on 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 on 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 = 0x1,
      DBDATACONVERT_LENGTHFROMNTS = 0x2,
      DBDATACONVERT_DSTISFIXEDLENGTH = 0x4,
      DBDATACONVERT_DECIMALSCALE = 0x8
    } ;
    

    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 the following:

    • The source data was unavailable.

    • Data truncation occurred.

    • The precision and scale arguments did not make sense for the data type.

    • There was an invalid character or second decimal point in the source data.

  • DB_E_UNSUPPORTEDCONVERSION
    The requested conversion was not supported.