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.

297 lines
7.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. //
  5. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  6. //
  7. // ICREATEROW.CPP ICreateRow interface implementation
  8. //
  9. ///////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. HRESULT CImplICreateRow::CreateRow(IUnknown * pUnkOuter,
  12. LPCOLESTR pwszURL,
  13. DBBINDURLFLAG dwBindURLFlags,
  14. REFGUID rguid,
  15. REFIID riid,
  16. IAuthenticate * pAuthenticate,
  17. DBIMPLICITSESSION * pImplSession,
  18. DBBINDURLSTATUS * pdwBindStatus,
  19. LPOLESTR * ppwszNewURL,
  20. IUnknown ** ppUnk)
  21. {
  22. HRESULT hr = S_OK;
  23. BSTR strUrl;
  24. BOOL bCreateNew = TRUE;
  25. CSetStructuredExceptionHandler seh;
  26. TRY_BLOCK;
  27. // Serialize the object
  28. CAutoBlock cab(BINDER->GetCriticalSection());
  29. // Clear ErrorInfo
  30. g_pCError->ClearErrorInfo();
  31. // Allocate the string
  32. strUrl = Wmioledb_SysAllocString(pwszURL);
  33. if(!CheckBindURLFlags(dwBindURLFlags,rguid))
  34. {
  35. hr = E_INVALIDARG;
  36. }
  37. else
  38. if(!CheckIfProperURL(strUrl,rguid,pdwBindStatus))
  39. {
  40. hr = DB_E_OBJECTMISMATCH;
  41. }
  42. else
  43. if( pUnkOuter != NULL && riid != IID_IUnknown)
  44. {
  45. hr = DB_E_NOAGGREGATION;
  46. }
  47. else
  48. {
  49. m_pObj->m_pUrlParser->ClearParser();
  50. if(DBBINDURLFLAG_OPENIFEXISTS & dwBindURLFlags)
  51. {
  52. // Calling this to bind the URL to the appropriate object
  53. hr = BindURL(pUnkOuter,strUrl,dwBindURLFlags,rguid,riid,pImplSession,pdwBindStatus,ppUnk);
  54. if( SUCCEEDED(hr))
  55. {
  56. bCreateNew = FALSE;
  57. }
  58. }
  59. // If row does not exist or if a new row is to be created
  60. if( bCreateNew == TRUE)
  61. {
  62. hr = CreateNewRow(pUnkOuter,strUrl,dwBindURLFlags,rguid,riid,pImplSession,pdwBindStatus,ppUnk);
  63. }
  64. }
  65. SysFreeString(strUrl);
  66. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ICreateRow);
  67. CATCH_BLOCK_HRESULT(hr,L"ICreateRow::CreateRow");
  68. return hr;
  69. }
  70. ////////////////////////////////////////////////////////////////////////////////////////////
  71. // Function which checks if the URL flags matches the requested object
  72. // This is as per the OLEDB specs
  73. ///////////////////////////////////////////////////////////////////////////////////////////
  74. BOOL CImplICreateRow::CheckBindURLFlags(DBBINDURLFLAG dwBindURLFlags , REFGUID rguid)
  75. {
  76. BOOL bFlag = FALSE;
  77. LONG lTemp = 0;
  78. if( DBGUID_ROW == rguid)
  79. {
  80. if(!((dwBindURLFlags & DBBINDURLFLAG_OPENIFEXISTS ) && // Flags cannot have any of these two values
  81. (dwBindURLFlags & DBBINDURLFLAG_OVERWRITE )))
  82. bFlag = TRUE;
  83. }
  84. if( DBGUID_ROWSET == rguid)
  85. {
  86. if((dwBindURLFlags & DBBINDURLFLAG_COLLECTION ) &&
  87. !(dwBindURLFlags & DBBINDURLFLAG_DELAYFETCHCOLUMNS ) &&
  88. !(dwBindURLFlags & DBBINDURLFLAG_DELAYFETCHCOLUMNS ))
  89. bFlag = TRUE;
  90. }
  91. if( DBGUID_STREAM == rguid)
  92. {
  93. }
  94. return bFlag;
  95. }
  96. ////////////////////////////////////////////////////////////////////////////////////////////
  97. // Function which checks if the URL is valid for the requested object
  98. ///////////////////////////////////////////////////////////////////////////////////////////
  99. BOOL CImplICreateRow::CheckIfProperURL(BSTR & strUrl,REFGUID rguid,DBBINDURLSTATUS * pdwBindStatus)
  100. {
  101. BOOL bRet = FALSE;
  102. LONG lUrlType = -1;
  103. m_pObj->m_pUrlParser->ClearParser();
  104. // Set the URL string of the URL parser utility class
  105. if(SUCCEEDED(m_pObj->m_pUrlParser->SetURL(strUrl)))
  106. {
  107. bRet = TRUE;
  108. // If the url is a valid URL
  109. if((lUrlType = m_pObj->m_pUrlParser->GetURLType()) != -1)
  110. {
  111. switch(lUrlType)
  112. {
  113. case URL_ROW:
  114. if(rguid == DBGUID_ROW)
  115. bRet = TRUE;
  116. break;
  117. case URL_ROWSET:
  118. if(rguid == DBGUID_ROWSET)
  119. bRet = TRUE;
  120. break;
  121. };
  122. }
  123. }
  124. return bRet;
  125. }
  126. ///////////////////////////////////////////////////////////////////////////
  127. // Function to bind the requested URL
  128. ///////////////////////////////////////////////////////////////////////////
  129. HRESULT CImplICreateRow::BindURL( IUnknown * pUnkOuter,
  130. LPCOLESTR pwszURL,
  131. DBBINDURLFLAG dwBindURLFlags,
  132. REFGUID rguid,
  133. REFIID riid,
  134. DBIMPLICITSESSION * pImplSession,
  135. DBBINDURLSTATUS * pdwBindStatus,
  136. IUnknown ** ppUnk)
  137. {
  138. HRESULT hr = E_FAIL;
  139. IUnknown *pTempUnk = NULL;
  140. LONG lInitFlags = 0;
  141. LONG lBindFlags = 0;
  142. REFGUID guidTemp = GUID_NULL;
  143. IUnknown* pReqestedPtr = NULL;
  144. GetInitAndBindFlagsFromBindFlags(dwBindURLFlags,lInitFlags,lBindFlags);
  145. if(S_OK == (hr = m_pObj->CreateDSO(NULL,lInitFlags,guidTemp,NULL)))
  146. {
  147. if(pImplSession != NULL)
  148. {
  149. pTempUnk = pImplSession->pUnkOuter;
  150. if(pTempUnk != NULL && *pImplSession->piid != IID_IUnknown)
  151. return DB_E_NOAGGREGATION;
  152. hr = m_pObj->CreateSession(pTempUnk,IID_IUnknown,&pReqestedPtr);
  153. }
  154. else
  155. hr = m_pObj->CreateSession(pTempUnk,guidTemp,&pReqestedPtr);
  156. if(S_OK == hr)
  157. {
  158. // If the implicit session is not null then get the requested
  159. // session pointer
  160. if(pImplSession != NULL)
  161. {
  162. if( S_OK == pReqestedPtr->QueryInterface(*pImplSession->piid,(void **)&pImplSession->pSession))
  163. pReqestedPtr->Release();
  164. }
  165. // If requested object is row then call function to
  166. // to create a row
  167. if( rguid == DBGUID_ROW)
  168. {
  169. pReqestedPtr = NULL;
  170. hr = m_pObj->CreateRow(pUnkOuter,riid,ppUnk);
  171. }
  172. // If requested object is rowset then call function to
  173. // to create a rowset
  174. if( rguid == DBGUID_ROWSET)
  175. {
  176. pReqestedPtr = NULL;
  177. hr = m_pObj->CreateRowset(pUnkOuter,riid,ppUnk);
  178. }
  179. }
  180. }
  181. // If failed due to some reason then release all the
  182. // object created for binding
  183. if( hr != S_OK)
  184. {
  185. m_pObj->ReleaseAllObjects();
  186. }
  187. return hr ;
  188. }
  189. ///////////////////////////////////////////////////////////////////////////
  190. // Function to create a new row as given by the URL
  191. ///////////////////////////////////////////////////////////////////////////
  192. HRESULT CImplICreateRow::CreateNewRow( IUnknown * pUnkOuter,
  193. LPCOLESTR pwszURL,
  194. DBBINDURLFLAG dwBindURLFlags,
  195. REFGUID rguid,
  196. REFIID riid,
  197. DBIMPLICITSESSION * pImplSession,
  198. DBBINDURLSTATUS * pdwBindStatus,
  199. IUnknown ** ppUnk)
  200. {
  201. HRESULT hr = E_FAIL;
  202. IUnknown *pTempUnk = NULL;
  203. LONG lInitFlags = 0;
  204. LONG lBindFlags = 0;
  205. REFGUID guidTemp = GUID_NULL;
  206. IUnknown* pReqestedPtr = NULL;
  207. ROWCREATEBINDFLAG rowCreateFlag = ROWCREATE;
  208. GetInitAndBindFlagsFromBindFlags(dwBindURLFlags,lInitFlags,lBindFlags);
  209. if(S_OK == (hr = m_pObj->CreateDSO(NULL,lInitFlags,guidTemp,NULL)))
  210. {
  211. if(pImplSession != NULL)
  212. {
  213. pTempUnk = pImplSession->pUnkOuter;
  214. if(pTempUnk != NULL && *pImplSession->piid != IID_IUnknown)
  215. return DB_E_NOAGGREGATION;
  216. hr = m_pObj->CreateSession(pTempUnk,IID_IUnknown,&pReqestedPtr);
  217. }
  218. else
  219. hr = m_pObj->CreateSession(pTempUnk,guidTemp,&pReqestedPtr);
  220. if(S_OK == hr)
  221. {
  222. // If the implicit session is not null then get the requested
  223. // session pointer
  224. if(pImplSession != NULL)
  225. {
  226. if( S_OK == pReqestedPtr->QueryInterface(*pImplSession->piid,(void **)&pImplSession->pSession))
  227. pReqestedPtr->Release();
  228. }
  229. // If requested object is row then call function to
  230. // to create a new row
  231. if( rguid == DBGUID_ROW)
  232. {
  233. if(DBBINDURLFLAG_OVERWRITE & dwBindURLFlags)
  234. rowCreateFlag = ROWOVERWRITE;
  235. pReqestedPtr = NULL;
  236. hr = m_pObj->CreateRow(pUnkOuter,riid,ppUnk,rowCreateFlag);
  237. }
  238. else
  239. hr = DB_E_NOTSUPPORTED;
  240. }
  241. }
  242. return hr;
  243. }