home *** CD-ROM | disk | FTP | other *** search
- // Xform.cpp : Implementation of CXform
- #include "stdafx.h"
- #include "dtsxform.h"
- #define DBINITCONSTANTS
- #include "Xform.h"
-
- //utility functions
-
- //Do SetErrorInfo with proper error string
- HRESULT ReportErrorInfo(USHORT wCode, HRESULT hr, UINT idsError, const IID& iid)
- {
- USES_CONVERSION;
-
- //Modify this function to also to help context and helpfiles if needed.
- TCHAR szTemp[256];
-
- if (NOERROR == hr && 0 == wCode)
- return NOERROR; //No exceptions
-
- if (NOERROR == hr)
- hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, wCode);
-
- if (LoadString(_Module.GetResourceInstance(), idsError, szTemp, 256))
- {
- LPOLESTR szError;
- #ifndef _UNICODE
- szError = A2W(szTemp);
- #else
- szError = szTemp;
- #endif
- if (szError)
- {
- //
- AtlSetErrorInfo(CLSID_DTSStrCatXform, szError, 0, NULL, iid, hr, NULL);
- }
- }
- return hr;
- }
-
- //Utility macros
- #define ErrorOut(err) {return ReportErrorInfo(DTSXform_Error_##err, 0, IDS_ERROR_##err, IID_IDTSDataPumpTransform);}
- #define ErrorOut2(err) {return ReportErrorInfo(DTSXform_Error_##err, 0, IDS_ERROR_##err, IID_IDTSStrCatXform);}
- #define ErrorOutHr(hres, err) {return ReportErrorInfo(0, hres, IDS_ERROR_##err, IID_IDTSDataPumpTransform);}
- #define ErrorOutHr2(hres, err) {return ReportErrorInfo(0, hres, IDS_ERROR_##err, IID_IDTSStrCatXform);}
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CXform
-
- // IDTSStrCatXform
-
-
- STDMETHODIMP CXform::get_RemoveSpace(
- /* [retval][out] */ VARIANT_BOOL __RPC_FAR *pRetVal)
- {
- if (!pRetVal)
- return E_POINTER;
- *pRetVal = m_bRemoveSpace;
- return NOERROR;
- }
-
- STDMETHODIMP CXform::put_RemoveSpace(
- /* [in] */ VARIANT_BOOL NewValue)
- {
- m_bRemoveSpace = NewValue;
- return NOERROR;
- }
-
- //*** IDTSDataPumpTransform members
- STDMETHODIMP CXform::Initialize(
- DP_IN LPCOLESTR pwzName, // Transform name
- VARIANT ServerParameters, // Parameters to server for this transform
- LPBYTE *ppvTransformServerData // Transform server state data.
- )
- {
- //Nothing to do here
- return NOERROR;
- }
-
- STDMETHODIMP CXform::ValidateSchema(
- LPBYTE pvTransformServerData, // Transform server state data.
- LPCDTSTransformColumnInfo pSrcColumnInfo, // Source columns and rowdata
- LPCDTSTransformColumnInfo pDestColumnInfo, // Dest columns and rowdata
- IDTSDataConvert *pIDTSDataConvert, // Pointer to the data conversion interface
- DTSTransformFlags eTransformFlags // Input Flags for Transformation validation and execution
- )
- {
- //*************************************************************************************
- //NOTE: this sample transformation does not check the tranform flags to properly handle
- //truncation, type conversion etc.
- //*************************************************************************************
-
- if (pDestColumnInfo->cColumns != 1) //You can use custom error codes
- ErrorOut(NUMDESTCOLS);
-
- //More validation should be done here to check to see source and dest are strings and
- //they are all strings of same type (ansi/unicode match etc.)
-
- //destination - the sample only does ANSI strings
- // sample Destination table -- one column only
- const DBCOLUMNINFO* pDestDBColumnInfo = pDestColumnInfo->rgColumnData[0].pDBColumnInfo;
- WORD wDestType = (pDestDBColumnInfo->wType & (~DBTYPE_BYREF));
-
- if (!(wDestType & DBTYPE_STR))
- ErrorOut(ONLYSTRINGCOLS);
-
- for (UINT i = 0; i < pSrcColumnInfo->cColumns; i++)
- {
- const DBCOLUMNINFO* pSrcDBColumnInfo = pSrcColumnInfo->rgColumnData[i].pDBColumnInfo;
- WORD wSourceType = (pSrcDBColumnInfo->wType & (~DBTYPE_BYREF));
-
- if (!(wSourceType & DBTYPE_STR))
- ErrorOut(ONLYSTRINGCOLS);
- }
-
- return NOERROR;
- }
-
-
- STDMETHODIMP CXform::AddVariable(
- LPBYTE pvTransformServerData, // Transform server state data.
- LPCOLESTR pwzName, // Variable name
- BOOL bGlobal, // For ActiveX scripts, indicates whether this variable's
- // methods must be qualified by the object name.
- VARIANT Variable // Variable value; passed to and updatable by Transform
- )
- {
- return NOERROR;
- }
-
-
- STDMETHODIMP CXform::Execute(
- LPBYTE pvTransformServerData, // Transform server state data.
- LPCDTSTransformColumnInfo pSrcColumnInfo, // Source columns and rowdata
- LPDTSTransformColumnInfo pDestColumnInfo, // Dest columns and rowdata
- IDTSDataConvert *pIDTSDataConvert, // Pointer to the data conversion interface
- LPDTSTransformStatus pTransformStatus // Result of transform
- )
- {
- //*************************************************************************************
- //NOTE: this sample transformation does not check the tranform flags to properly handle
- //truncation, type conversion etc.
- //*************************************************************************************
- DTSColumnData& rDTSDestColumnData = pDestColumnInfo->rgColumnData[0];
- const DBCOLUMNINFO& rDBDestColumnInfo = *rDTSDestColumnData.pDBColumnInfo;
-
- const DBBINDING& rDBDestBinding = *rDTSDestColumnData.pDBBinding;
-
- // set the dest length to max length
- ULONG ulDestLength = rDBDestBinding.cbMaxLen;
- LPSTR pDestString = (LPSTR)(rDTSDestColumnData.pvData + rDBDestBinding.obValue);
-
-
- if (!ulDestLength || !pDestString) //nothing to do ??
- return NOERROR;
-
- *pDestString = 0;
- for (UINT i = 0; i < pSrcColumnInfo->cColumns; i++)
- {
- DTSColumnData& rDTSSourceColumnData = pSrcColumnInfo->rgColumnData[i];
- const DBCOLUMNINFO& rDBSourceColumnInfo = *rDTSSourceColumnData.pDBColumnInfo;
-
- const DBBINDING& rDBSourceBinding = *rDTSSourceColumnData.pDBBinding;
- ULONG ulSourceLength = *reinterpret_cast<ULONG *>(rDTSSourceColumnData.pvData + rDBSourceBinding.obLength);
- LPSTR pSourceString = *(LPSTR *)(rDTSSourceColumnData.pvData + rDBSourceBinding.obValue);
-
- if (strlen(pDestString) + strlen(pSourceString) < rDBDestBinding.cbMaxLen)
- {
- strcat(pDestString, pSourceString);
- if (m_bRemoveSpace)
- RemoveTrailingSpace(pDestString, strlen(pDestString));
- strcat(pDestString, " ");
- }
- else
- break;
- }
- // set the dest length
- ULONG* ulLength = reinterpret_cast<ULONG *>(rDTSDestColumnData.pvData + rDBDestBinding.obLength);
- *ulLength = strlen(pDestString) + 1;
- return NOERROR;
- }
-
-
- STDMETHODIMP CXform::OnRowComplete(
- LPBYTE pvTransformServerData, // Transform server state data.
- LPDTSTransformColumnInfo pSrcColumnInfo, // Source columns and rowdata
- LPDTSTransformColumnInfo pDestColumnInfo, // Dest columns and rowdata
- IDTSDataConvert *pIDTSDataConvert, // Pointer to the data conversion interface
- DTSTransformStatus eTransformStatus, // Result of Execute()
- HRESULT hrInsert // Result of IRowsetChange::InsertRow()
- )
- {
- return NOERROR;
- }
-
-
- STDMETHODIMP CXform::OnTransformComplete(
- LPBYTE pvTransformServerData, // Transform server state data.
- LPDTSTransformColumnInfo pSrcColumnInfo, // Source columns and rowdata
- LPDTSTransformColumnInfo pDestColumnInfo, // Dest columns and rowdata
- IDTSDataConvert *pIDTSDataConvert // Pointer to the data conversion interface
- )
- {
- return NOERROR;
- }
-
-
-