📄 ctable.cpp
字号:
switch(eRowsetSource)
{
case ROWSET_FROMCOMMANDWITHPARAMETERS:
DisplayPropErrors(hWnd, COMMAND, m_pCCommand->m_pICommand);
DisplayBindingErrors(hWnd, m_pCCommand->m_cParamBindings, m_pCCommand->m_rgParamBindings, m_pCCommand->m_ParamInfo.pData);
break;
case ROWSET_FROMCOMMAND:
DisplayPropErrors(hWnd, COMMAND, m_pCCommand->m_pICommand);
break;
default:
DisplayPropErrors(hWnd, cPropSets, rgPropSets);
break;
};
}
if(!pIUnknown)
{
hr = S_FALSE;
goto CLEANUP;
}
// Save rowset source
m_eRowsetSource = eRowsetSource;
//Delegate - now that we have a rowset pointer...
TESTC(hr = CreateRowset(pIUnknown));
CLEANUP:
//Display Errors (if occurred)
if(hr == DB_S_ERRORSOCCURRED || hr == DB_E_ERRORSOCCURRED)
{
switch(eRowsetSource)
{
case ROWSET_FROMCOMMANDWITHPARAMETERS:
DisplayPropErrors(hWnd, COMMAND, m_pCCommand->m_pICommand);
DisplayBindingErrors(hWnd, m_pCCommand->m_cParamBindings, m_pCCommand->m_rgParamBindings, m_pCCommand->m_ParamInfo.pData);
break;
case ROWSET_FROMCOMMAND:
DisplayPropErrors(hWnd, COMMAND, m_pCCommand->m_pICommand);
break;
default:
DisplayPropErrors(hWnd, cPropSets, rgPropSets);
break;
};
}
pCListBox->OutputRelease(&pIUnknown);
pCListBox->OutputRelease((IUnknown**)&pIMultipleResults, "IMultipleResults");
SAFE_FREE(rgOptColumns);
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CRowset::CreateRowset
//
/////////////////////////////////////////////////////////////////
HRESULT CRowset::CreateRowset(IUnknown* pIUnknown)
{
HRESULT hr = S_OK; // HRESULT
HRESULT hrOptional = S_OK; // HRESULT
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
COptionsDlg* pCOptionsDlg = GetOptionsObj();
//Some SQL Statements don't return a rowset
if(pIUnknown==NULL)
goto CLEANUP;
//Clear previous rowset
ReleaseRowset();
//[MANDATORY] Obtain [mandatory] interfaces
XTEST(hWnd, hr = pCListBox->OutputQI(pIUnknown, IID_IUnknown, (IUnknown**)&m_pIUnknown));
XTEST(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IRowset, (IUnknown**)&m_pIRowset));
XTEST(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IAccessor, (IUnknown**)&m_pIAccessor));
XTEST(hWnd, hr = pCListBox->OutputQI(m_pIUnknown, IID_IColumnsInfo, (IUnknown**)&m_pIColumnsInfo));
//Auto QI
if(pCOptionsDlg->m_dwRowsetOpts & ROWSET_AUTOQI)
{
//Obtain [optional] interfaces
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IConvertType, (IUnknown**)&m_pIConvertType);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetInfo, (IUnknown**)&m_pIRowsetInfo);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IColumnsRowset, (IUnknown**)&m_pIColumnsRowset);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IConnectionPointContainer, (IUnknown**)&m_pIConnectionPointContainer);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IDBAsynchStatus, (IUnknown**)&m_pIDBAsynchStatus);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetChange, (IUnknown**)&m_pIRowsetChange);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetIdentity, (IUnknown**)&m_pIRowsetIdentity);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetLocate, (IUnknown**)&m_pIRowsetLocate);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetFind, (IUnknown**)&m_pIRowsetFind);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetView, (IUnknown**)&m_pIRowsetView);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IChapteredRowset, (IUnknown**)&m_pIChapteredRowset);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetResynch, (IUnknown**)&m_pIRowsetResynch);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetScroll, (IUnknown**)&m_pIRowsetScroll);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_IRowsetUpdate, (IUnknown**)&m_pIRowsetUpdate);
hrOptional = pCListBox->OutputQI(m_pIUnknown, IID_ISupportErrorInfo,(IUnknown**)&m_pISupportErrorInfo);
}
/* if(m_pIRowsetScroll)
{
//Don't return a failure if this optional interface fails...
pCListBox->OutputPreMethod("IRowsetScroll::GetApproximatePosition(DB_NULL_HCHAPTER, 0, NULL, NULL, &%d)", m_ulEstimatedRows);
XTEST(hWnd, hrOptional = m_pIRowsetScroll->GetApproximatePosition(DB_NULL_HCHAPTER, 0, NULL, NULL, &m_ulEstimatedRows));
pCListBox->OutputPostMethod(hrOptional, "IRowsetScroll::GetApproximatePosition(DB_NULL_HCHAPTER, 0, NULL, NULL, &%d)", m_ulEstimatedRows);
}
*/
//Listeners
AdviseListeners();
//Setup RowPosition Object
m_pCRowPos->CreateRowPos(m_pIUnknown);
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// HRESULT CRowset::CreateDataset
//
// called for ROWSET_FROMCOMMANDDATASET only
//
/////////////////////////////////////////////////////////////////
HRESULT CRowset::CreateDataset(ROWSETSOURCE eRowsetSource, LONG* pcRowsAffected, WCHAR* pwszCmd)
{
ASSERT(pwszCmd);
HRESULT hr = S_OK; // HRESULT
HRESULT hrOptional = S_OK; // HRESULT
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
// initialize returned row count
if (pcRowsAffected)
*pcRowsAffected = DB_COUNTUNAVAILABLE;
// Save rowset source
m_eRowsetSource = eRowsetSource;
ASSERT(eRowsetSource == ROWSET_FROMCOMMANDDATASET);
// Clear previous rowset
ReleaseRowset();
// Set CommandText
m_pCDataset->ReleaseDataset();
TESTC(hr = m_pCCommand->SetCommandText(pwszCmd));
//Execute
XTESTC(hWnd, hr = m_pCCommand->m_pICommandText->Execute(NULL, IID_IMDDataset, NULL, NULL,
(IUnknown**)&m_pCDataset->m_pIMDDataset));
TESTC(pCListBox->OutputPostMethod(hr, "ICommandText::Execute(NULL, IID_IMDDataset, NULL, &0x%08x)", m_pCDataset->m_pIMDDataset));
CLEANUP:
// Display Property Errors (if occurred)
if (hr == DB_S_ERRORSOCCURRED || hr == DB_E_ERRORSOCCURRED)
{
if (eRowsetSource == ROWSET_FROMCOMMANDDATASET)
DisplayPropErrors(NULL, COMMAND, m_pCCommand->m_pICommandText);
}
return hr;
}
/////////////////////////////////////////////////////////////////
// CMultipleResults::CMultipleResults
//
/////////////////////////////////////////////////////////////////
CMultipleResults::CMultipleResults(CMDIChild* pCMDIChild) : CBase(pCMDIChild)
{
//MultipleResults
m_pIMultipleResults = NULL;//MultipleResults Interface
m_pISupportErrorInfo = NULL;//MultipleResults Interface
}
/////////////////////////////////////////////////////////////////
// CMultipleResults::~CMultipleResults
//
/////////////////////////////////////////////////////////////////
CMultipleResults::~CMultipleResults()
{
ReleaseObject();
}
/////////////////////////////////////////////////////////////////
// HRESULT CMultipleResults::SetInterface
//
/////////////////////////////////////////////////////////////////
HRESULT CMultipleResults::SetInterface(REFIID riid, IUnknown* pIUnknown)
{
HRESULT hr = S_OK;
//no-op
if(pIUnknown == NULL)
return E_INVALIDARG;
//If the requested interface is a valid 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_IUnknown)
m_pIUnknown = (IUnknown*)pIUnknown;
else if(riid == IID_IMultipleResults)
m_pIMultipleResults = (IMultipleResults*)pIUnknown;
else if(riid == IID_ISupportErrorInfo)
m_pISupportErrorInfo = (ISupportErrorInfo*)pIUnknown;
else
hr = E_NOINTERFACE;
return hr;
}
/////////////////////////////////////////////////////////////////
// CMultipleResults::ReleaseRowset
//
/////////////////////////////////////////////////////////////////
HRESULT CMultipleResults::ReleaseObject()
{
//MultipleResults
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pIMultipleResults, "IMultipleResults");
pCListBox->OutputRelease((IUnknown**)&m_pISupportErrorInfo, "IRowsetErrorInfo");
//Base
ReleaseBase("MultipleResults");
return S_OK;
}
////////////////////////////////////////////////////////////////
// CMultipleResults::CreateObject
//
/////////////////////////////////////////////////////////////////
HRESULT CMultipleResults::CreateObject(IUnknown* pIUnknown)
{
HRESULT hr = E_FAIL;
HRESULT hrOptional = E_FAIL;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
COptionsDlg* pCOptionsDlg = GetOptionsObj();
//Some don't return a rowset
if(pIUnknown==NULL)
goto CLEANUP;
//Release any previous object
ReleaseObject();
//Now use the new object
//[MANDATORY]
XTESTC(hWnd, hr = pCListBox->OutputQI(pIUnknown, IID_IUnknown, (IUnknown**)&m_pIUnknown));
XTESTC(hWnd, hr = pCListBox->OutputQI(pIUnknown, IID_IMultipleResults, (IUnknown**)&m_pIMultipleResults));
//Auto QI
if(pCOptionsDlg->m_dwRowsetOpts & ROWSET_AUTOQI)
{
//Obtain [optional] interfaces
hrOptional = pCListBox->OutputQI(pIUnknown, IID_ISupportErrorInfo, (IUnknown**)&m_pISupportErrorInfo);
}
CLEANUP:
return hr;
}
////////////////////////////////////////////////////////////////
// CMultipleResults::GetResult
//
/////////////////////////////////////////////////////////////////
HRESULT CMultipleResults::GetResult(REFIID riid, LONG* pcRowsAffected, IUnknown** ppIUnknown)
{
ASSERT(pcRowsAffected);
ASSERT(ppIUnknown);
HRESULT hr = E_FAIL;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
//No-op
if(m_pIMultipleResults == NULL)
return E_FAIL;
//IMultipleResults::GetResult...
TESTC(pCListBox->OutputPreMethod("IMultipleResults::GetResult(NULL, 0, %s, &%d, &0x%08x)", GetInterfaceName(riid), *pcRowsAffected, *ppIUnknown));
XTEST(hWnd, hr = m_pIMultipleResults->GetResult(NULL, 0, riid, pcRowsAffected, ppIUnknown));
TESTC(pCListBox->OutputPostMethod(hr, "IMultipleResults::GetResult(NULL, 0, %s, &%d, &0x%08x)", GetInterfaceName(riid), *pcRowsAffected, *ppIUnknown));
CLEANUP:
return hr;
}
/////////////////////////////////////////////////////////////////
// CRowPos::CRowPos
//
/////////////////////////////////////////////////////////////////
CRowPos::CRowPos(CMDIChild* pCMDIChild) : CBase(pCMDIChild)
{
//RowPosition
m_pIConnectionPointContainer = NULL;//RowPosition Interface
m_pIRowPosition = NULL;//RowPosition Interface
//Extra Interfaces
m_pIConnectionPoint = NULL;//Connection Interface
//Listeners
m_pCRowPosChange = new CRowPosChange(m_pCMDIChild->m_pCListBox);
}
/////////////////////////////////////////////////////////////////
// CRowPos::~CRowPos
//
/////////////////////////////////////////////////////////////////
CRowPos::~CRowPos()
{
ReleaseRowPos();
//Verify Listeners have no extra references on them...
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pCRowPosChange, "IRowPositionChange", 0);
}
/////////////////////////////////////////////////////////////////
// HRESULT CRowPos::SetInterface
//
/////////////////////////////////////////////////////////////////
HRESULT CRowPos::SetInterface(REFIID riid, IUnknown* pIUnknown)
{
HRESULT hr = S_OK;
//no-op
if(pIUnknown == NULL)
return E_INVALIDARG;
//If the requested interface is a RowPosition 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_IUnknown)
m_pIUnknown = (IUnknown*)pIUnknown;
else if(riid == IID_IConnectionPointContainer)
m_pIConnectionPointContainer = (IConnectionPointContainer*)pIUnknown;
else if(riid == IID_IRowPosition)
m_pIRowPosition = (IRowPosition*)pIUnknown;
else
hr = E_NOINTERFACE;
return hr;
}
/////////////////////////////////////////////////////////////////
// CRowPos::ReleaseRowPos
//
/////////////////////////////////////////////////////////////////
HRESULT CRowPos::ReleaseRowPos()
{
//Rowset
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
pCListBox->OutputRelease((IUnknown**)&m_pIConnectionPointContainer, "IConnectionPointContainer");
pCListBox->OutputRelease((IUnknown**)&m_pIRowPosition, "IRowPosition");
//Extra intefaces
pCListBox->OutputRelease((IUnknown**)&m_pIConnectionPoint, "IConnectionPoint");
//Base
ReleaseBase("RowPosition");
//Don't Unadvise the Lsiteners until the Rowset goes away.
//We want to receive and Display the ROWSET_RELEASE notifications
UnadviseListeners();
return S_OK;
}
////////////////////////////////////////////////////////////////
// CRowPos::CreateRowPos
//
/////////////////////////////////////////////////////////////////
HRESULT CRowPos::CreateRowPos(IUnknown* pIRowset)
{
ASSERT(pIRowset);
HRESULT hr = E_FAIL;
HRESULT hrOptional = E_FAIL;
HWND hWnd = m_pCMDIChild->m_hWnd;
CListBox* pCListBox = m_pCMDIChild->m_pCListBox;
//Release all previous interfaces
Release
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -