WindowsXP/admin/wmi/wbem/providers/msiprovider/dll/odbcsourceattribute.cpp
2025-04-27 07:49:33 -04:00

118 lines
3.5 KiB
C++

// ODBCSourceAttribute.cpp: implementation of the CODBCSourceAttribute class.
//
// Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
#include "precomp.h"
#include "ODBCSourceAttribute.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CODBCSourceAttribute::CODBCSourceAttribute(CRequestObject *pObj, IWbemServices *pNamespace,
IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
{
}
CODBCSourceAttribute::~CODBCSourceAttribute()
{
}
HRESULT CODBCSourceAttribute::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
{
HRESULT hr = WBEM_S_NO_ERROR;
MSIHANDLE hView, hRecord;
int i = -1;
WCHAR wcBuf[BUFF_SIZE];
WCHAR wcQuery[BUFF_SIZE];
DWORD dwBufSize;
bool bMatch = false;
UINT uiStatus;
//These will change from class to class
bool bDriver, bAttribute;
wcscpy(wcQuery, L"select distinct `DataSource_`, `Attribute`, `Value` from ODBCSourceAttribute");
while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED)){
//Open our database
try
{
if ( GetView ( &hView, m_pRequest->Package(i), wcQuery, L"ODBCSourceAttribute", TRUE, FALSE ) )
{
uiStatus = g_fpMsiViewFetch(hView, &hRecord);
while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
CheckMSI(uiStatus);
if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
//----------------------------------------------------
dwBufSize = BUFF_SIZE;
CheckMSI(g_fpMsiRecordGetStringW(hRecord, 1, wcBuf, &dwBufSize));
PutKeyProperty(m_pObj, pDataSource, wcBuf, &bDriver, m_pRequest);
dwBufSize = BUFF_SIZE;
CheckMSI(g_fpMsiRecordGetStringW(hRecord, 2, wcBuf, &dwBufSize));
PutKeyProperty(m_pObj, pAttribute, wcBuf, &bAttribute, m_pRequest);
PutProperty(m_pObj, pCaption, wcBuf);
PutProperty(m_pObj, pDescription, wcBuf);
//=====================================================
dwBufSize = BUFF_SIZE;
CheckMSI(g_fpMsiRecordGetStringW(hRecord, 3, wcBuf, &dwBufSize));
PutProperty(m_pObj, pValue, wcBuf);
//----------------------------------------------------
if(bDriver && bAttribute) bMatch = true;
if((atAction != ACTIONTYPE_GET) || bMatch){
hr = pHandler->Indicate(1, &m_pObj);
}
m_pObj->Release();
m_pObj = NULL;
g_fpMsiCloseHandle(hRecord);
uiStatus = g_fpMsiViewFetch(hView, &hRecord);
}
}
}
catch(...)
{
g_fpMsiCloseHandle(hRecord);
g_fpMsiViewClose(hView);
g_fpMsiCloseHandle(hView);
msidata.CloseDatabase ();
if(m_pObj)
{
m_pObj->Release();
m_pObj = NULL;
}
throw;
}
g_fpMsiCloseHandle(hRecord);
g_fpMsiViewClose(hView);
g_fpMsiCloseHandle(hView);
msidata.CloseDatabase ();
}
return hr;
}