Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.9 KiB

  1. // ODBCAttribute.cpp: implementation of the CODBCAttribute class.
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ODBCAttribute.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CODBCAttribute::CODBCAttribute(CRequestObject *pObj, IWbemServices *pNamespace,
  12. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  13. {
  14. }
  15. CODBCAttribute::~CODBCAttribute()
  16. {
  17. }
  18. HRESULT CODBCAttribute::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  19. {
  20. HRESULT hr = WBEM_S_NO_ERROR;
  21. MSIHANDLE hView = NULL, hRecord = NULL;
  22. int i = -1;
  23. WCHAR wcBuf[BUFF_SIZE];
  24. WCHAR wcQuery[BUFF_SIZE];
  25. DWORD dwBufSize;
  26. bool bMatch = false;
  27. UINT uiStatus;
  28. //These will change from class to class
  29. bool bDriver, bAttribute;
  30. wcscpy(wcQuery, L"select distinct `Driver_`, `Attribute`, `Value` from ODBCAttribute");
  31. LPWSTR Buffer = NULL;
  32. LPWSTR dynBuffer = NULL;
  33. DWORD dwDynBuffer = 0L;
  34. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  35. {
  36. //Open our database
  37. try
  38. {
  39. if ( GetView ( &hView, m_pRequest->Package(i), wcQuery, L"ODBCAttribute", TRUE, FALSE ) )
  40. {
  41. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  42. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  43. CheckMSI(uiStatus);
  44. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  45. //----------------------------------------------------
  46. dwBufSize = BUFF_SIZE;
  47. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  48. PutKeyProperty(m_pObj, pDriver, Buffer, &bDriver, m_pRequest);
  49. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  50. {
  51. dynBuffer [ 0 ] = 0;
  52. }
  53. dwBufSize = BUFF_SIZE;
  54. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  55. PutKeyProperty(m_pObj, pAttribute, Buffer, &bAttribute, m_pRequest);
  56. PutProperty(m_pObj, pCaption, Buffer);
  57. PutProperty(m_pObj, pDescription, Buffer);
  58. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  59. {
  60. dynBuffer [ 0 ] = 0;
  61. }
  62. //=====================================================
  63. dwBufSize = BUFF_SIZE;
  64. PutPropertySpecial ( hRecord, 3, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, pValue);
  65. //----------------------------------------------------
  66. if(bDriver && bAttribute) bMatch = true;
  67. if((atAction != ACTIONTYPE_GET) || bMatch){
  68. hr = pHandler->Indicate(1, &m_pObj);
  69. }
  70. m_pObj->Release();
  71. m_pObj = NULL;
  72. g_fpMsiCloseHandle(hRecord);
  73. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  74. }
  75. }
  76. }
  77. catch(...)
  78. {
  79. if ( dynBuffer )
  80. {
  81. delete [] dynBuffer;
  82. dynBuffer = NULL;
  83. }
  84. if (hRecord)
  85. g_fpMsiCloseHandle(hRecord);
  86. if (hView)
  87. {
  88. g_fpMsiViewClose(hView);
  89. g_fpMsiCloseHandle(hView);
  90. }
  91. msidata.CloseDatabase ();
  92. if(m_pObj)
  93. {
  94. m_pObj->Release();
  95. m_pObj = NULL;
  96. }
  97. throw;
  98. }
  99. if (hRecord)
  100. g_fpMsiCloseHandle(hRecord);
  101. if (hView)
  102. {
  103. g_fpMsiViewClose(hView);
  104. g_fpMsiCloseHandle(hView);
  105. }
  106. msidata.CloseDatabase ();
  107. }
  108. if ( dynBuffer )
  109. {
  110. delete [] dynBuffer;
  111. dynBuffer = NULL;
  112. }
  113. return hr;
  114. }