📄 datasource.cpp
字号:
//[OPTIONAL]
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IDBSchemaRowset, (IUnknown**)&m_pIDBSchemaRowset);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IIndexDefinition, (IUnknown**)&m_pIIndexDefinition);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ISupportErrorInfo, (IUnknown**)&m_pISupportErrorInfo);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ITableDefinition, (IUnknown**)&m_pITableDefinition);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ITransactionJoin, (IUnknown**)&m_pITransactionJoin);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ITransactionLocal, (IUnknown**)&m_pITransactionLocal);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ITransactionObject, (IUnknown**)&m_pITransactionObject);
}
//CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CSession::CreateSession
//
/////////////////////////////////////////////////////////////////
HRESULT CSession::CreateSession(REFIID riid)
{
HRESULT hr = S_OK;
HRESULT hrOptional = S_OK;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
HWND hWnd = pCListBox->m_hWnd;
IUnknown* pIUnknown = NULL;
//This interface is required to continue...
if(m_pCDataSource->m_pIDBCreateSession)
{
//CreateSession
TESTC(pCListBox->OutputPreMethod("IDBCreateSession::CreateSession(NULL, %s, &0x%08x)", GetInterfaceName(riid), pIUnknown));
XTEST(hWnd, hr = m_pCDataSource->m_pIDBCreateSession->CreateSession(NULL, riid, (IUnknown**)&pIUnknown));
TESTC(pCListBox->OutputPostMethod(hr, "IDBCreateSession::CreateSession(NULL, %s, &0x%08x)", GetInterfaceName(riid), pIUnknown));
//Now that we now CreateSession has succeeded, use that for our
//object, otherwise we ruin our existing session if there was one...
m_pIUnknown = pIUnknown;
//Delegate
TESTC(hr = CreateSession(this));
}
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// CCommand::CCommand
//
/////////////////////////////////////////////////////////////////
CCommand::CCommand(CMDIChild* pCMDIChild, CSession* pCSession) : CBase(pCMDIChild)
{
//BackPointer
ASSERT(pCSession);
m_pCSession = pCSession;
//OLEDB Interfaces
m_pIAccessor = NULL; //Command interface
m_pIColumnsInfo = NULL; //Command interface
m_pICommand = NULL; //Command interface
m_pICommandProperties = NULL; //Command interface
m_pICommandText = NULL; //Command interface
m_pIConvertType = NULL; //Command interface
m_pIColumnsRowset = NULL; //Command interface
m_pICommandPrepare = NULL; //Command interface
m_pICommandWithParameters = NULL; //Command interface
m_pISupportErrorInfo = NULL; //Command interface
//Parameters
m_cParamBindings = 0;
m_rgParamBindings = NULL;
memset(&m_ParamInfo, 0, sizeof(DBPARAMS));
}
/////////////////////////////////////////////////////////////////
// CCommand::~CCommand
//
/////////////////////////////////////////////////////////////////
CCommand::~CCommand()
{
ReleaseCommand();
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::SetInterface
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::SetInterface(REFIID riid, IUnknown* pIUnknown)
{
HRESULT hr = S_OK;
//no-op
if(pIUnknown == NULL)
return E_INVALIDARG;
//If the requested interface is a Command interface, place it in the
//Appropiate member variable, otherwise we have to release it, since we
//have no place to store it...
if(riid == IID_IAccessor)
m_pIAccessor = (IAccessor*)pIUnknown;
else if(riid == IID_IColumnsInfo)
m_pIColumnsInfo = (IColumnsInfo*)pIUnknown;
else if(riid == IID_ICommand)
m_pICommand = (ICommand*)pIUnknown;
else if(riid == IID_ICommandProperties)
m_pICommandProperties = (ICommandProperties*)pIUnknown;
else if(riid == IID_ICommandText)
m_pICommandText = (ICommandText*)pIUnknown;
else if(riid == IID_IConvertType)
m_pIConvertType = (IConvertType*)pIUnknown;
else if(riid == IID_IColumnsRowset)
m_pIColumnsRowset = (IColumnsRowset*)pIUnknown;
else if(riid == IID_ICommandPrepare)
m_pICommandPrepare = (ICommandPrepare*)pIUnknown;
else if(riid == IID_ICommandWithParameters)
m_pICommandWithParameters = (ICommandWithParameters*)pIUnknown;
else if(riid == IID_ISupportErrorInfo)
m_pISupportErrorInfo = (ISupportErrorInfo*)pIUnknown;
else
hr = E_NOINTERFACE;
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::ReleaseCommand
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::ReleaseCommand()
{
ReleaseAccessor(&m_ParamInfo.hAccessor);
FreeBindings(&m_cParamBindings, &m_rgParamBindings);
SAFE_FREE(m_ParamInfo.pData);
//Command
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pIAccessor, "IAccessor");
pCListBox->OutputRelease((IUnknown**)&m_pIColumnsInfo, "IColumnsInfo");
pCListBox->OutputRelease((IUnknown**)&m_pICommand, "ICommand");
pCListBox->OutputRelease((IUnknown**)&m_pICommandProperties, "ICommandProperties");
pCListBox->OutputRelease((IUnknown**)&m_pICommandText, "ICommandText");
pCListBox->OutputRelease((IUnknown**)&m_pIConvertType, "IConvertType");
pCListBox->OutputRelease((IUnknown**)&m_pIColumnsRowset, "IColumnsRowset");
pCListBox->OutputRelease((IUnknown**)&m_pICommandPrepare, "ICommandPrepare");
pCListBox->OutputRelease((IUnknown**)&m_pICommandWithParameters,"ICommandWithParameters");
pCListBox->OutputRelease((IUnknown**)&m_pISupportErrorInfo, "ISupportErrorInfo");
ReleaseBase("Command");
return S_OK;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::CreateCommand
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::CreateCommand(REFIID riid)
{
HRESULT hr = S_OK;
HRESULT hrOptional = S_OK;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
HWND hWnd = pCListBox->m_hWnd;
IUnknown* pIUnknown = NULL;
if(m_pCSession->m_pIDBCreateCommand)
{
//CreateCommand
TESTC(pCListBox->OutputPreMethod("IDBCreateCommand::CreateCommand(NULL, %s, &0x%08x", GetInterfaceName(riid), pIUnknown));
XTEST(hWnd, hr = m_pCSession->m_pIDBCreateCommand->CreateCommand(NULL, riid, (IUnknown**)&pIUnknown));
TESTC(pCListBox->OutputPostMethod(hr, "IDBCreateCommand::CreateCommand(NULL, %s, &0x%08x", GetInterfaceName(riid), pIUnknown));
//Now that we now CreateSession has succeeded, use that for our
//object, otherwise we ruin our existing session if there was one...
ReleaseCommand();
m_pIUnknown = pIUnknown;
//AutoQI
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_AUTOQI)
{
//[MANDATORY]
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_ICommand, (IUnknown**)&m_pICommand));
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IAccessor, (IUnknown**)&m_pIAccessor));
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IColumnsInfo, (IUnknown**)&m_pIColumnsInfo));
XTESTC(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_ICommandText, (IUnknown**)&m_pICommandText));
//[OPTIONAL]
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ICommandProperties, (IUnknown**)&m_pICommandProperties);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IConvertType, (IUnknown**)&m_pIConvertType);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IColumnsRowset, (IUnknown**)&m_pIColumnsRowset);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ICommandPrepare, (IUnknown**)&m_pICommandPrepare);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ICommandWithParameters, (IUnknown**)&m_pICommandWithParameters);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ISupportErrorInfo, (IUnknown**)&m_pISupportErrorInfo);
}
}
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::CreateParamAccessor
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::CreateParamAccessor(ULONG cParams, DBPARAMINFO* rgParamInfo)
{
HRESULT hr = S_OK;
ULONG cbRowSize = 0;
//Release Previous Accessor
ReleaseAccessor(&m_ParamInfo.hAccessor);
FreeBindings(&m_cParamBindings, &m_rgParamBindings);
SAFE_FREE(m_ParamInfo.pData);
//Delegate
TESTC(hr = SetupBindings(cParams, rgParamInfo, &m_cParamBindings, &m_rgParamBindings, &cbRowSize));
TESTC(hr = CreateAccessor(DBACCESSOR_PARAMETERDATA, m_cParamBindings, m_rgParamBindings, cbRowSize, &m_ParamInfo.hAccessor));
//Allocate pData
SAFE_ALLOC(m_ParamInfo.pData, BYTE, cbRowSize);
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::SetupBindings
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::SetupBindings(ULONG cParams, DBPARAMINFO* rgParamInfo, ULONG* pcBindings, DBBINDING** prgBindings, ULONG* pcRowSize, BOOL* pbOutofLine)
{
ASSERT(pcBindings);
ASSERT(prgBindings);
HRESULT hr = S_OK;
CMDIChild* pCMDIChild = m_pCMDIChild;
HWND hWnd = pCMDIChild->m_hWnd;
CListBox* pCListBox = pCMDIChild->m_pCListBox;
ULONG dwOffset = 0;
ULONG i,cBindings = 0;
DBBINDING* rgBindings = NULL;
ULONG cStorageObjects = 0;
//Only capable of the Following Converions (for Display)
DBTYPE wBindingType = (DBTYPE)GetOptionsObj()->m_dwBindingType;
//Alloc the space to hold the Bindings and Accessors
SAFE_ALLOC(rgBindings, DBBINDING, cParams);
cBindings = 0;
for(i=0; i<cParams; i++)
{
ASSERT(rgParamInfo);
//SetUp the Bindings
rgBindings[cBindings].iOrdinal = rgParamInfo[i].iOrdinal;
rgBindings[cBindings].obStatus = dwOffset;
rgBindings[cBindings].obLength = dwOffset + sizeof(DBSTATUS);
rgBindings[cBindings].obValue = dwOffset + sizeof(DBSTATUS) + sizeof(ULONG);
rgBindings[cBindings].pTypeInfo = NULL;
rgBindings[cBindings].pBindExt = NULL;
rgBindings[cBindings].dwPart = DBPART_VALUE|DBPART_LENGTH|DBPART_STATUS;
rgBindings[cBindings].dwMemOwner= DBMEMOWNER_CLIENTOWNED;
rgBindings[cBindings].eParamIO = DBPARAMIO_NOTPARAM;
if(rgParamInfo[i].dwFlags & DBPARAMFLAGS_ISINPUT)
rgBindings[cBindings].eParamIO |= DBPARAMIO_INPUT;
if(rgParamInfo[i].dwFlags & DBPARAMFLAGS_ISOUTPUT)
rgBindings[cBindings].eParamIO |= DBPARAMIO_OUTPUT;
rgBindings[cBindings].dwFlags = 0;
rgBindings[cBindings].bPrecision= rgParamInfo[i].bPrecision;
rgBindings[cBindings].bScale = rgParamInfo[i].bScale;
rgBindings[cBindings].pObject = NULL;
rgBindings[cBindings].wType = wBindingType;
//MAX_LENGTH
rgBindings[cBindings].cbMaxLen = rgParamInfo[i].ulParamSize;
//Account for TYPE -> VARIANT Converion
if(wBindingType == DBTYPE_VARIANT)
{
rgBindings[cBindings].cbMaxLen = sizeof(VARIANT);
}
//Account for the NULL terminator
if(rgBindings[cBindings].wType == DBTYPE_STR)
rgBindings[cBindings].cbMaxLen += sizeof(CHAR);
if(rgBindings[cBindings].wType == DBTYPE_WSTR)
rgBindings[cBindings].cbMaxLen += sizeof(WCHAR);
//MAX_LENGTH
rgBindings[cBindings].cbMaxLen = min(rgBindings[cBindings].cbMaxLen, MAX_COL_SIZE);
dwOffset = rgBindings[cBindings].cbMaxLen + rgBindings[cBindings].obValue;
dwOffset = ROUNDUP( dwOffset );
cBindings++;
}
//Size for pData
if(pcRowSize)
*pcRowSize = dwOffset;
CLEANUP:
//Accessors
*pcBindings = cBindings;
*prgBindings = rgBindings;
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::CreateAccessor
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::CreateAccessor(DBACCESSORFLAGS dwAccessorFlags, ULONG cBindings, DBBINDING* rgBindings, ULONG cRowSize, HACCESSOR* phAccessor)
{
ASSERT(phAccessor);
ASSERT(m_pIAccessor);
HRESULT hr = S_OK;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
DBBINDSTATUS* rgStatus = NULL;
//Alloc the space to hold the status
SAFE_ALLOC(rgStatus, DBBINDSTATUS, cBindings);
//Create the accessor
*phAccessor = NULL;
TESTC(pCListBox->OutputPreMethod("IAccessor::CreateAccessor(%d, %d, 0x%08x, %d, &0x%08x, 0x%08x)", dwAccessorFlags, cBindings, rgBindings, cRowSize, *phAccessor, rgStatus));
XTEST(hWnd, hr = m_pIAccessor->CreateAccessor(dwAccessorFlags, cBindings, rgBindings, cRowSize, phAccessor, rgStatus));
if(hr == DB_S_ERRORSOCCURRED || hr == DB_E_ERRORSOCCURRED)
DisplayAccessorErrors(NULL, cBindings, rgBindings, rgStatus);
TESTC(pCListBox->OutputPostMethod(hr, "IAccessor::CreateAccessor(%d, %d, 0x%08x, 0, &0x%08x, 0x%08x)", dwAccessorFlags, cBindings, rgBindings, cRowSize, *phAccessor, rgStatus));
CLEANUP:
SAFE_FREE(rgStatus);
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CCommand::ReleaseAccessor
//
/////////////////////////////////////////////////////////////////
HRESULT CCommand::ReleaseAccessor(HACCESSOR* phAccessor)
{
ASSERT(phAccessor);
HRESULT hr = S_OK;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
ULONG ulRefCount = 0;
if(m_pIAccessor && *phAccessor)
{
TESTC(hr = pCListBox->OutputPreMethod("IAccessor::ReleaseAccessor(0x%08x, &%d)", *phAccessor, ulRefCount));
XTEST(hWnd, hr = m_pIAccessor->ReleaseAccessor(*phAccessor, &ulRefCount));
TESTC(hr = pCListBox->OutputPostMethod(hr, "IAccessor::ReleaseAccessor(0x%08x, &%d)", *phAccessor, ulRefCount));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -