Source code of Windows XP (NT5)
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.

226 lines
5.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. //
  5. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  6. //
  7. // IChapteredRowset.CPP IChapteredRowset interface implementation
  8. //
  9. ///////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. /////////////////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Adds a reference to a chapter
  14. //
  15. // Returns one of the following values:
  16. // S_OK Method Succeeded
  17. // E_FAIL General Error
  18. //
  19. /////////////////////////////////////////////////////////////////////////////////////////////////
  20. STDMETHODIMP CImpIGetRow::GetRowFromHROW(IUnknown * pUnkOuter,HROW hRow,REFIID riid,IUnknown ** ppUnk)
  21. {
  22. HRESULT hr = DB_E_BADROWHANDLE;
  23. CRow *pRow = NULL;
  24. CSetStructuredExceptionHandler seh;
  25. TRY_BLOCK;
  26. // Serialize the object
  27. CAutoBlock cab(ROWSET->GetCriticalSection());
  28. // Clear ErrorInfo
  29. g_pCError->ClearErrorInfo();
  30. if(m_pObj->IsZoombie())
  31. {
  32. hr = E_UNEXPECTED;
  33. }
  34. else
  35. if( pUnkOuter != NULL && riid != IID_IUnknown)
  36. {
  37. hr = DB_E_NOAGGREGATION;
  38. }
  39. else
  40. if(ppUnk == NULL)
  41. {
  42. hr = E_INVALIDARG;
  43. }
  44. else
  45. if( m_pObj->m_uRsType == PROPERTYQUALIFIER ||
  46. m_pObj->m_uRsType == CLASSQUALIFIER ||
  47. m_pObj->m_uRsType == METHOD_ROWSET ||
  48. m_pObj->m_uRsType == SCHEMA_ROWSET)
  49. {
  50. hr = E_FAIL;
  51. LogMessage("URL for Qualifier or Schema rows not supported",hr);
  52. }
  53. // else was missing
  54. // modified on 06/07/00
  55. else
  56. if(hRow > 0)
  57. {
  58. if(TRUE == m_pObj->IsRowExists(hRow))
  59. {
  60. DWORD dwStatus = m_pObj->GetRowStatus(hRow);
  61. if(dwStatus != DBSTATUS_S_OK)
  62. {
  63. LogMessage("Status of the row is not DBSTATUS_S_OK",hr);
  64. hr = dwStatus == DBROWSTATUS_E_DELETED ? DB_E_DELETEDROW : E_FAIL;
  65. }
  66. else
  67. {
  68. CBSTR strKey;
  69. if(SUCCEEDED(hr = ((CWbemClassInstanceWrapper *)m_pObj->GetInstancePtr(hRow))->GetKey(strKey)))
  70. {
  71. try
  72. {
  73. pRow = new CRow(pUnkOuter,m_pObj,m_pObj->m_pCreator,m_pObj->m_pCon);
  74. }
  75. catch(...)
  76. {
  77. SAFE_DELETE_PTR(pRow);
  78. throw;
  79. }
  80. if(pRow != NULL)
  81. {
  82. if(S_OK == (hr = pRow->InitRow(hRow,m_pObj->GetInstancePtr(hRow))))
  83. {
  84. hr = pRow->QueryInterface(riid,(void **)ppUnk);
  85. }
  86. }
  87. else
  88. {
  89. hr = E_OUTOFMEMORY;
  90. }
  91. }
  92. else
  93. {
  94. hr = E_FAIL;
  95. *ppUnk = NULL;
  96. }
  97. }
  98. }
  99. }
  100. if(FAILED(hr))
  101. {
  102. SAFE_DELETE_PTR(pRow);
  103. }
  104. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IGetRow);
  105. CATCH_BLOCK_HRESULT(hr,L"IGetRow::GetRowFromHROW");
  106. return hr;
  107. }
  108. /////////////////////////////////////////////////////////////////////////////////////////////////
  109. //
  110. // Adds a reference to a chapter
  111. //
  112. // Returns one of the following values:
  113. // S_OK Method Succeeded
  114. // E_FAIL General Error
  115. //
  116. /////////////////////////////////////////////////////////////////////////////////////////////////
  117. STDMETHODIMP CImpIGetRow::GetURLFromHROW(HROW hRow,LPOLESTR * ppwszURL)
  118. {
  119. HRESULT hr = DB_E_BADROWHANDLE;
  120. CSetStructuredExceptionHandler seh;
  121. TRY_BLOCK;
  122. //========================
  123. // Serialize the object
  124. //========================
  125. CAutoBlock cab(ROWSET->GetCriticalSection());
  126. //========================
  127. // Clear ErrorInfo
  128. //========================
  129. g_pCError->ClearErrorInfo();
  130. if(m_pObj->IsZoombie())
  131. {
  132. hr = E_UNEXPECTED;
  133. }
  134. else
  135. if( m_pObj->m_uRsType == PROPERTYQUALIFIER ||
  136. m_pObj->m_uRsType == CLASSQUALIFIER ||
  137. m_pObj->m_uRsType == METHOD_ROWSET||
  138. m_pObj->m_uRsType == SCHEMA_ROWSET)
  139. {
  140. hr = E_FAIL;
  141. LogMessage("URL for Qualifier or Schema rows not supported",hr);
  142. }
  143. else
  144. if(hRow > 0)
  145. {
  146. //========================
  147. // If row exists
  148. //========================
  149. if(TRUE == m_pObj->IsRowExists(hRow))
  150. {
  151. DWORD dwStatus = m_pObj->GetRowStatus(hRow);
  152. if(dwStatus != DBSTATUS_S_OK)
  153. {
  154. LogMessage("Status of the row is not DBSTATUS_S_OK",hr);
  155. hr = dwStatus == DBROWSTATUS_E_DELETED ? DB_E_DELETEDROW : E_FAIL;
  156. }
  157. else
  158. {
  159. CBSTR strKey;
  160. if(SUCCEEDED(hr = ((CWbemClassInstanceWrapper *)m_pObj->GetInstancePtr(hRow))->GetKey(strKey)))
  161. {
  162. BSTR strPath = NULL;
  163. BSTR strURL = NULL;
  164. hr = S_OK;
  165. CURLParser urlParser;
  166. urlParser.SetPath(strKey);
  167. urlParser.GetURL(strURL);
  168. try
  169. {
  170. *ppwszURL = (LPOLESTR)g_pIMalloc->Alloc((SysStringLen(strURL) + 1) *sizeof(WCHAR));
  171. }
  172. catch(...)
  173. {
  174. if(*ppwszURL)
  175. {
  176. g_pIMalloc->Free(*ppwszURL);
  177. }
  178. throw;
  179. }
  180. if(*ppwszURL == NULL)
  181. {
  182. hr = E_OUTOFMEMORY;
  183. }
  184. else
  185. {
  186. wcscpy(*ppwszURL,strURL);
  187. }
  188. SysFreeString(strURL);
  189. SysFreeString(strPath);
  190. }
  191. else
  192. {
  193. LogMessage("Getting a URL on command executed row is not supported except" \
  194. "except if query is not REFERENCES OF or ASSOCIATERS OF",hr);
  195. hr = E_FAIL;
  196. }
  197. }
  198. }
  199. }
  200. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IGetRow);
  201. CATCH_BLOCK_HRESULT(hr,L"IGetRow::GetURLFromHROW");
  202. return hr;
  203. }