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.

3124 lines
98 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // CRowset object implementation
  7. //
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. #include "WmiOleDBMap.h"
  12. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. // Constructor
  14. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. CRowset::CRowset(LPUNKNOWN pUnkOuter,PCDBSESSION pObj,CWbemConnectionWrapper *pCon ) : CBaseRowObj( pUnkOuter)
  16. {
  17. //===============================================================
  18. // Initialize simple member vars
  19. //===============================================================
  20. InitVars();
  21. m_pCreator = pObj;
  22. m_pCreator->GetOuterUnknown()->AddRef();
  23. //===============================================
  24. // Add this rowset ot list of open rowset
  25. //===============================================
  26. m_pCreator->AddRowset(this);
  27. m_pCon = pCon;
  28. }
  29. /////////////////////////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Constructor for this class , Initializing recordset for Qualifiers
  32. //
  33. /////////////////////////////////////////////////////////////////////////////////////////////////
  34. CRowset::CRowset(LPUNKNOWN pUnkOuter,ULONG uQType, LPWSTR PropertyName,PCDBSESSION pObj , CWmiOleDBMap *pMap) : CBaseRowObj(NULL)
  35. {
  36. //===============================================================
  37. // Initialize simple member vars
  38. //===============================================================
  39. InitVars();
  40. m_pCreator = pObj;
  41. m_pCreator->GetOuterUnknown()->AddRef();
  42. //===============================================
  43. // Add this rowset ot list of open rowset
  44. //===============================================
  45. m_pCreator->AddRowset(this);
  46. m_pMap = pMap;
  47. m_pMap->AddRef();
  48. //======================================================================
  49. // set the flag which indicates that this Rowset is a child recordsets;
  50. //======================================================================
  51. m_bIsChildRs = TRUE;
  52. // Initializing the Qualifier properties
  53. m_uRsType = uQType;
  54. if ( m_uRsType == PROPERTYQUALIFIER)
  55. {
  56. m_strPropertyName = Wmioledb_SysAllocString(PropertyName);
  57. }
  58. }
  59. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. // Function to Initialize all the member variables
  61. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. void CRowset::InitVars()
  63. {
  64. m_cCols = m_cCols = m_cNestedCols = 0L;
  65. //===============================================================
  66. // set the flag which indicates that this Rowset is not a child rowset
  67. //===============================================================
  68. m_bIsChildRs = FALSE;
  69. //===============================================================
  70. // Intialize buffered row count + pointers to allocated memory
  71. //===============================================================
  72. m_cRows = 0;
  73. m_cbRowSize = 0;
  74. m_irowMin = 0;
  75. m_ulRowRefCount = 0;
  76. m_dwStatus = 0;
  77. m_bHelperFunctionCreated= FALSE;
  78. m_hLastChapterAllocated = 0;
  79. m_ulProps = 0;
  80. m_ulLastFetchedRow = 0;
  81. m_hRow = 0;
  82. m_uRsType = 0;
  83. m_cRef = 0L;
  84. m_bIsChildRs = FALSE;
  85. m_FetchDir = FETCHDIRNONE;
  86. m_lLastFetchPos = 0;
  87. m_lRowCount = -1;
  88. m_hRowLastFetched = 0;
  89. //===============================================================
  90. // Initially, NULL all contained interfaces
  91. //===============================================================
  92. m_pIAccessor = (PIMPIACCESSOR)NULL;
  93. m_pIColumnsInfo = NULL;
  94. m_pIConvertType = NULL;
  95. m_pIRowset = NULL;
  96. m_pIRowsetChange = NULL;
  97. m_pIRowsetIdentity = NULL;
  98. m_pIRowsetInfo = NULL;
  99. m_pIChapteredRowset = NULL;
  100. m_pIGetRow = NULL;
  101. m_pIRowsetRefresh = NULL;
  102. m_pRowFetchObj = NULL;
  103. m_ppChildRowsets = NULL;
  104. m_pInstance = NULL;
  105. m_pParentCmd = NULL;
  106. m_pIBuffer = NULL;
  107. m_pLastBindBase = NULL;
  108. m_pRowData = NULL;
  109. m_pUtilProp = NULL;
  110. m_pChapterMgr = NULL;
  111. m_pMap = NULL;
  112. m_pCreator = NULL;
  113. m_pHashTblBkmark = NULL;
  114. m_InstMgr = NULL;
  115. m_pISupportErrorInfo = NULL;
  116. //===============================================================
  117. // Increment global object count.
  118. //===============================================================
  119. InterlockedIncrement(&g_cObj);
  120. }
  121. /////////////////////////////////////////////////////////////////////////////////////////////////
  122. // Destructor for this class
  123. /////////////////////////////////////////////////////////////////////////////////////////////////
  124. CRowset::~CRowset( void )
  125. {
  126. //==============================================================
  127. // Release all the open Rows
  128. //==============================================================
  129. ReleaseAllRows();
  130. //================================================
  131. // If Slot list is allocated, release them
  132. //================================================
  133. if (NULL != m_pIBuffer)
  134. {
  135. ReleaseSlotList( m_pIBuffer );
  136. }
  137. if ( m_uRsType == PROPERTYQUALIFIER)
  138. {
  139. SysFreeString(m_strPropertyName);
  140. }
  141. //===============================================================
  142. // Free pointers.
  143. //===============================================================
  144. SAFE_DELETE_PTR( m_pUtilProp );
  145. //===============================================================
  146. // NOTE: m_pMap releases the class ptr in destructor
  147. //===============================================================
  148. m_pMap->Release();
  149. SAFE_DELETE_PTR(m_pHashTblBkmark);
  150. //===============================================================
  151. // Free contained interfaces
  152. //===============================================================
  153. SAFE_DELETE_PTR( m_pIAccessor );
  154. SAFE_DELETE_PTR( m_pIColumnsInfo );
  155. SAFE_DELETE_PTR( m_pIConvertType );
  156. SAFE_DELETE_PTR( m_pIRowset );
  157. SAFE_DELETE_PTR( m_pIRowsetChange );
  158. SAFE_DELETE_PTR( m_pIRowsetIdentity );
  159. SAFE_DELETE_PTR( m_pIRowsetInfo );
  160. SAFE_DELETE_PTR( m_pIChapteredRowset);
  161. SAFE_DELETE_PTR( m_pIGetRow);
  162. SAFE_DELETE_PTR( m_pIRowsetRefresh);
  163. SAFE_DELETE_PTR(m_pISupportErrorInfo);
  164. SAFE_DELETE_PTR(m_pRowData);
  165. SAFE_DELETE_PTR(m_pRowFetchObj);
  166. SAFE_DELETE_PTR(m_InstMgr);
  167. //===============================================================
  168. // Decrement the DBSession Count. GetSpecification is not
  169. // possible anymore
  170. //===============================================================
  171. if( m_pCreator )
  172. {
  173. m_pCreator->GetOuterUnknown()->Release();
  174. }
  175. //===============================================================
  176. // If rowset is created by command then, decrement the number of rowsets
  177. // opened by the rowset and release the command pointer
  178. //===============================================================
  179. if(m_pParentCmd != NULL)
  180. {
  181. m_pParentCmd->DecrementOpenRowsets();
  182. m_pParentCmd->GetOuterUnknown()->Release();
  183. }
  184. SAFE_DELETE_PTR(m_pChapterMgr);
  185. //================================================
  186. // Release child rowsets
  187. //================================================
  188. if(m_ppChildRowsets != NULL)
  189. {
  190. for(UINT nIndex = 0 ; nIndex < m_cTotalCols ; nIndex++)
  191. {
  192. if(m_ppChildRowsets[nIndex] != NULL)
  193. {
  194. m_ppChildRowsets[nIndex]->Release();
  195. }
  196. }
  197. delete m_ppChildRowsets;
  198. }
  199. if(m_bNewConAllocated)
  200. {
  201. SAFE_DELETE_PTR(m_pCon);
  202. }
  203. //===============================================================
  204. // Decrement global object count.
  205. //===============================================================
  206. InterlockedDecrement(&g_cObj);
  207. }
  208. /////////////////////////////////////////////////////////////////////////////////////////////////
  209. //
  210. // Returns a pointer to a specified interface. Callers use QueryInterface to determine which
  211. // interfaces the called object supports.
  212. // Sucess of QI for some of the interfaces depend on some of the properties
  213. //
  214. // HRESULT indicating the status of the method
  215. // S_OK Interface is supported and ppvObject is set.
  216. // E_NOINTERFACE Interface is not supported by the object
  217. // E_INVALIDARG One or more arguments are invalid.
  218. //
  219. /////////////////////////////////////////////////////////////////////////////////////////////////
  220. STDMETHODIMP CRowset::QueryInterface ( REFIID riid, LPVOID * ppv )
  221. {
  222. HRESULT hr = S_OK;
  223. //======================================================
  224. // Check parameters, if not valid return
  225. //======================================================
  226. if (NULL == ppv)
  227. {
  228. hr = E_INVALIDARG ;
  229. }
  230. else
  231. {
  232. //======================================================
  233. // Place NULL in *ppv in case of failure
  234. //======================================================
  235. *ppv = NULL;
  236. //======================================================
  237. // This is the non-delegating IUnknown implementation
  238. //======================================================
  239. if (riid == IID_IUnknown)
  240. {
  241. *ppv = (LPVOID) this;
  242. }
  243. else if (riid == IID_IAccessor)
  244. {
  245. *ppv = (LPVOID) m_pIAccessor;
  246. }
  247. else if (riid == IID_IColumnsInfo)
  248. {
  249. *ppv = (LPVOID) m_pIColumnsInfo;
  250. }
  251. else if (riid == IID_IConvertType)
  252. {
  253. *ppv = (LPVOID) m_pIConvertType;
  254. }
  255. else if (riid == IID_IRowset)
  256. {
  257. *ppv = (LPVOID) m_pIRowset;
  258. }
  259. else if (riid == IID_IRowsetLocate && (m_ulProps & IROWSETLOCATE))
  260. {
  261. *ppv = (LPVOID) m_pIRowset;
  262. }
  263. else if (riid == IID_ISourcesRowset)
  264. {
  265. *ppv = (LPVOID) m_pIRowset;
  266. }
  267. else if (riid == IID_IRowsetChange && (m_ulProps & IROWSETCHANGE))
  268. {
  269. *ppv = (LPVOID) m_pIRowsetChange;
  270. }
  271. else if (riid == IID_IRowsetIdentity)
  272. {
  273. *ppv = (LPVOID) m_pIRowsetIdentity;
  274. }
  275. else if (riid == IID_IRowsetInfo)
  276. {
  277. *ppv = (LPVOID) m_pIRowsetInfo;
  278. }
  279. else if (riid == IID_IChapteredRowset && (m_ulProps & ICHAPTEREDROWSET))
  280. {
  281. *ppv = (LPVOID) m_pIChapteredRowset;
  282. }
  283. else if (riid == IID_IGetRow && (m_ulProps & IGETROW))
  284. {
  285. *ppv = (LPVOID) m_pIGetRow;
  286. }
  287. else if(riid == IID_IRowsetRefresh && (m_ulProps & IROWSETREFRESH))
  288. {
  289. *ppv = (LPVOID)m_pIRowsetRefresh;
  290. }
  291. else if(riid == IID_ISupportErrorInfo)
  292. {
  293. *ppv = (LPVOID)m_pISupportErrorInfo;
  294. }
  295. //======================================================
  296. // If we're going to return an interface, AddRef first
  297. //======================================================
  298. if (*ppv)
  299. {
  300. ((LPUNKNOWN) *ppv)->AddRef();
  301. hr = S_OK ;
  302. }
  303. else
  304. {
  305. hr = E_NOINTERFACE;
  306. }
  307. }
  308. return hr;
  309. }
  310. /////////////////////////////////////////////////////////////////////////////////////////////////
  311. //
  312. // Increments a persistence count for the object
  313. //
  314. // Returns Current reference count
  315. //
  316. /////////////////////////////////////////////////////////////////////////////////////////////////
  317. STDMETHODIMP_( ULONG ) CRowset::AddRef( void )
  318. {
  319. return InterlockedIncrement((long*)&m_cRef);
  320. }
  321. /////////////////////////////////////////////////////////////////////////////////////////////////
  322. //
  323. // Decrements a persistence count for the object and if persistence count is 0, the object
  324. // destroys itself.
  325. //
  326. /////////////////////////////////////////////////////////////////////////////////////////////////
  327. STDMETHODIMP_( ULONG ) CRowset::Release( void )
  328. {
  329. if (!InterlockedDecrement((long*)&m_cRef))
  330. {
  331. //===========================================================
  332. // Mark the session as not having an open rowset anymore
  333. //===========================================================
  334. this->m_pCreator->RemoveRowset(this);
  335. // this->m_pCreator->DecRowsetCount();
  336. delete this;
  337. return 0;
  338. }
  339. return m_cRef;
  340. }
  341. /////////////////////////////////////////////////////////////////////////////////////////////////
  342. //
  343. // Initialize the rowset for representing a row. This rowset will not be opened as a child rowset
  344. // This is used when rowset is opened on a qualifier
  345. //
  346. //
  347. // Did the Initialization Succeed
  348. // S_OK Initialization succeeded
  349. // E_INVALIDARG Some input data are incorrect
  350. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  351. //
  352. /////////////////////////////////////////////////////////////////////////////////////////////////
  353. HRESULT CRowset::InitRowsetForRow(LPUNKNOWN pUnkOuter ,
  354. const ULONG cPropertySets,
  355. const DBPROPSET rgPropertySets[] ,
  356. CWbemClassWrapper *pInst)
  357. {
  358. HRESULT hr = S_OK;
  359. HROW hRowCurrent = 0;
  360. CBSTR strKey;
  361. //================================================
  362. // Initialize the member variables
  363. //================================================
  364. m_bIsChildRs = FALSE;
  365. //==========================
  366. // Inititialize the rowset
  367. //==========================
  368. if(S_OK == (hr =InitRowset(cPropertySets,rgPropertySets)))
  369. {
  370. m_pMap->GetInstanceKey(pInst,strKey);
  371. m_pInstance = pInst;
  372. //===========================================================================
  373. // if there is atleast one row retrieved and there are neseted columns
  374. // then allocate rows for the child recordsets
  375. //===========================================================================
  376. if(m_cNestedCols > 0 )
  377. {
  378. if(m_ppChildRowsets == NULL)
  379. {
  380. AllocateAndInitializeChildRowsets();
  381. }
  382. //=====================================================================
  383. // Fill the HCHAPTERS for the column
  384. //=====================================================================
  385. if(S_OK != (hr = FillHChaptersForRow(pInst,strKey)))
  386. {
  387. hr = E_FAIL;
  388. }
  389. }
  390. if( FAILED(hr = CreateHelperFunctions()))
  391. {
  392. return hr;
  393. }
  394. m_bHelperFunctionCreated = TRUE;
  395. }
  396. return hr;
  397. }
  398. /////////////////////////////////////////////////////////////////////////////////////////////////
  399. //
  400. // Overloaded Rowset Initialization function to initialize rowset created from a command object
  401. //
  402. // Did the Initialization Succeed
  403. // S_OK Initialization succeeded
  404. // E_INVALIDARG Some input data are incorrect
  405. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  406. //
  407. /////////////////////////////////////////////////////////////////////////////////////////////////
  408. HRESULT CRowset::InitRowset( const ULONG cPropertySets, const DBPROPSET rgPropertySets[],DWORD dwFlags, CQuery* p,PCCOMMAND pCmd )
  409. {
  410. HRESULT hr = S_OK;
  411. //============================================
  412. // Set the qualifier flags
  413. //============================================
  414. dwFlags = (long)dwFlags == -1 ? GetQualifierFlags() : dwFlags;
  415. //==================================================================
  416. // Create a CWmiOleDBMap class with the appropriate constructor
  417. //==================================================================
  418. m_pMap = new CWmiOleDBMap;
  419. if( m_pMap != NULL)
  420. {
  421. if(SUCCEEDED(hr = m_pMap->FInit(dwFlags,p,m_pCon == NULL ?m_pCreator->m_pCDataSource->m_pWbemWrap: m_pCon)))
  422. {
  423. m_pMap->AddRef();
  424. m_pParentCmd = pCmd;
  425. m_uRsType = p->GetType(); // If it is a COMMAND_ROWSET or METHOD_ROWSET
  426. //============================================
  427. // To hold the parent command reference
  428. //============================================
  429. m_pParentCmd->GetOuterUnknown()->AddRef();
  430. //=====================================================
  431. // Call this function to do the rest of initialization
  432. //=====================================================
  433. hr = InitRowset(cPropertySets,rgPropertySets);
  434. }
  435. }
  436. else
  437. {
  438. hr = E_OUTOFMEMORY;
  439. }
  440. return hr;
  441. }
  442. /////////////////////////////////////////////////////////////////////////////////////////////////
  443. //
  444. // Overloaded Rowset Initialization function
  445. // This function is called for (1) Schema Rowsets via CSchema
  446. //
  447. // Did the Initialization Succeed
  448. // S_OK Initialization succeeded
  449. // E_INVALIDARG Some input data are incorrect
  450. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  451. //
  452. /////////////////////////////////////////////////////////////////////////////////////////////////
  453. HRESULT CRowset::InitRowset( int nBaseType,const ULONG cPropertySets, const DBPROPSET rgPropertySets[],LPWSTR TableID, DWORD dwFlags, LPWSTR SpecificTable )
  454. {
  455. HRESULT hr = S_OK;
  456. //============================================
  457. // Set the qualifier flags
  458. //============================================
  459. dwFlags = (long)dwFlags == -1 ? GetQualifierFlags() : dwFlags;
  460. //==================================================================
  461. // Create a CWmiOleDBMap class with the appropriate constructor
  462. //==================================================================
  463. m_pMap = new CWmiOleDBMap;
  464. if( m_pMap != NULL)
  465. {
  466. if(SUCCEEDED(hr = m_pMap->FInit(nBaseType, dwFlags, TableID, SpecificTable,
  467. m_pCon == NULL ?m_pCreator->m_pCDataSource->m_pWbemWrap: m_pCon)))
  468. {
  469. m_pMap->AddRef();
  470. m_uRsType = SCHEMA_ROWSET;
  471. //=====================================================
  472. // Call this function to do the rest of initialization
  473. //=====================================================
  474. hr = InitRowset(cPropertySets,rgPropertySets);
  475. }
  476. }
  477. else
  478. {
  479. hr = E_OUTOFMEMORY;
  480. }
  481. return hr;
  482. }
  483. /////////////////////////////////////////////////////////////////////////////////////////////////
  484. //
  485. // Overloaded Rowset Initialization function
  486. // This function is called for (1) Schema Rowsets
  487. // (2) rowsets created from IOpenrowset:OpenRowset
  488. //
  489. // Did the Initialization Succeed
  490. // S_OK Initialization succeeded
  491. // E_INVALIDARG Some input data are incorrect
  492. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  493. //
  494. /////////////////////////////////////////////////////////////////////////////////////////////////
  495. HRESULT CRowset::InitRowset( const ULONG cPropertySets, const DBPROPSET rgPropertySets[],LPWSTR TableID,BOOL fSchema , DWORD dwFlags )
  496. {
  497. HRESULT hr = S_OK;
  498. VARIANT vValue;
  499. VariantInit(&vValue);
  500. //============================================
  501. // Set the qualifier flags
  502. //============================================
  503. dwFlags = (long)dwFlags == -1 ? GetQualifierFlags() : dwFlags;
  504. //==================================================================
  505. // Create a CWmiOleDBMap class with the appropriate constructor
  506. //==================================================================
  507. m_pMap = new CWmiOleDBMap;
  508. if( m_pMap != NULL)
  509. {
  510. if(wcscmp(TableID,OPENCOLLECTION) == 0)
  511. {
  512. INSTANCELISTTYPE instType = GetObjectTypeProp(cPropertySets,rgPropertySets);
  513. hr = m_pMap->FInit(dwFlags,TableID,m_pCon == NULL ?m_pCreator->m_pCDataSource->m_pWbemWrap: m_pCon,instType);
  514. }
  515. else
  516. {
  517. hr = m_pMap->FInit(dwFlags,TableID,m_pCon == NULL ?m_pCreator->m_pCDataSource->m_pWbemWrap: m_pCon);
  518. }
  519. if(SUCCEEDED(hr))
  520. {
  521. m_pMap->AddRef();
  522. m_uRsType = fSchema == TRUE ? SCHEMA_ROWSET : 0;
  523. //=====================================================
  524. // Call this function to do the rest of initialization
  525. //=====================================================
  526. hr = InitRowset(cPropertySets,rgPropertySets);
  527. }
  528. }
  529. else
  530. {
  531. hr = E_OUTOFMEMORY;
  532. }
  533. return hr;
  534. }
  535. /////////////////////////////////////////////////////////////////////////////////////////////////
  536. //
  537. // Overloaded Rowset Initialization function
  538. // This function is called for (1) ROwsets created for Scope/Container
  539. //
  540. // Did the Initialization Succeed
  541. // S_OK Initialization succeeded
  542. // E_INVALIDARG Some input data are incorrect
  543. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  544. //
  545. /////////////////////////////////////////////////////////////////////////////////////////////////
  546. HRESULT CRowset::InitRowset( const ULONG cPropertySets,
  547. const DBPROPSET rgPropertySets[],
  548. LPWSTR strObjectID,
  549. LPWSTR strObjectToOpen,
  550. INSTANCELISTTYPE objInstListType ,
  551. DWORD dwFlags)
  552. {
  553. HRESULT hr = S_OK;
  554. WCHAR *pstrTableID = NULL;
  555. CWbemConnectionWrapper *pCon = m_pCon;
  556. pstrTableID = strObjectID;
  557. //============================================
  558. // Set the qualifier flags
  559. //============================================
  560. dwFlags = (long)dwFlags == -1 ? GetQualifierFlags() : dwFlags;
  561. if(!pstrTableID)
  562. {
  563. pstrTableID = new WCHAR[wcslen(OPENCOLLECTION) + 1];
  564. if(pstrTableID)
  565. {
  566. wcscpy(pstrTableID,OPENCOLLECTION);
  567. }
  568. else
  569. {
  570. hr = E_OUTOFMEMORY;
  571. }
  572. }
  573. if(SUCCEEDED(hr) && strObjectToOpen)
  574. // wbem_wcsincmp(m_pCreator->m_pCDataSource->m_pWbemWrap->GetNamespace(),strObjectID,wcslen(m_pCreator->m_pCDataSource->m_pWbemWrap->GetNamespace())))
  575. {
  576. m_pCon = new CWbemConnectionWrapper;
  577. if(m_pCon)
  578. {
  579. hr = m_pCon->FInit(pCon != NULL ? pCon : m_pCreator->m_pCDataSource->m_pWbemWrap,
  580. strObjectToOpen,objInstListType);
  581. m_bNewConAllocated = TRUE;
  582. }
  583. else
  584. {
  585. hr = E_OUTOFMEMORY;
  586. }
  587. }
  588. if(SUCCEEDED(hr))
  589. {
  590. //==================================================================
  591. // Create a CWmiOleDBMap class with the appropriate constructor
  592. //==================================================================
  593. m_pMap = new CWmiOleDBMap;
  594. if( m_pMap != NULL)
  595. {
  596. if(SUCCEEDED(hr = m_pMap ->FInit(dwFlags,
  597. pstrTableID,
  598. m_pCon == NULL ?m_pCreator->m_pCDataSource->m_pWbemWrap: m_pCon,
  599. objInstListType)))
  600. {
  601. m_pMap->AddRef();
  602. //=====================================================
  603. // Call this function to do the rest of initialization
  604. //=====================================================
  605. hr = InitRowset(cPropertySets,rgPropertySets);
  606. }
  607. }
  608. else
  609. {
  610. hr = E_OUTOFMEMORY;
  611. }
  612. }
  613. if(!strObjectID)
  614. {
  615. SAFE_DELETE_ARRAY(pstrTableID);
  616. }
  617. return hr;
  618. }
  619. /////////////////////////////////////////////////////////////////////////////////////////////////
  620. //
  621. // Initialize the rowset Object
  622. //
  623. // Did the Initialization Succeed
  624. // S_OK Initialization succeeded
  625. // E_INVALIDARG Some input data are incorrect
  626. // E_OUTOFMEMORY Out of memory when allocate memory for member data
  627. //
  628. /////////////////////////////////////////////////////////////////////////////////////////////////
  629. HRESULT CRowset::InitRowset( const ULONG cPropertySets, const DBPROPSET rgPropertySets[] )
  630. {
  631. HRESULT hr = S_OK;
  632. bool bRowChange = true;
  633. ULONG cErrors = 0;
  634. //============================================================================
  635. // allocate utility object that manages our properties
  636. //============================================================================
  637. m_pUtilProp = new CUtilProp;
  638. if ( m_pUtilProp == NULL )
  639. {
  640. hr = E_OUTOFMEMORY;
  641. }
  642. else
  643. // NTRaid: 136443
  644. // 07/05/00
  645. if(SUCCEEDED(hr = m_pUtilProp->FInit(ROWSETPROP)))
  646. {
  647. //07/06/00
  648. // NTRaid : 134987
  649. if(m_uRsType == SCHEMA_ROWSET)
  650. {
  651. hr = InitializePropertiesForSchemaRowset();
  652. }
  653. else
  654. if(m_uRsType == COMMAND_ROWSET )
  655. {
  656. hr = InitializePropertiesForCommandRowset();
  657. }
  658. else
  659. if(m_uRsType == METHOD_ROWSET)
  660. {
  661. hr = InitializePropertiesForMethodRowset();
  662. }
  663. //============================================================================
  664. // Set rowset properties
  665. // May be setting of optional properties might have failed and so we can continue
  666. //============================================================================
  667. // hr = SetRowsetProperties(cPropertySets,rgPropertySets);
  668. if(SUCCEEDED(hr) && SUCCEEDED(hr = SetRowsetProperties(cPropertySets,rgPropertySets)))
  669. {
  670. if(hr != S_OK)
  671. {
  672. cErrors++;
  673. }
  674. //===================================================================================
  675. // Call this function to initialize some of the rowset properties, set some flags
  676. // and set flags on CWmiOledbMap object
  677. //===================================================================================
  678. InitializeRowsetProperties();
  679. //====================================================================
  680. /// Get property and Set Serach Preferences
  681. //====================================================================
  682. hr = SetSearchPreferences();
  683. //===================================================================================
  684. // Get column the information for the rowset
  685. //===================================================================================
  686. if( S_OK == (hr = CBaseRowObj::GetColumnInfo()))
  687. {
  688. //=============================================================
  689. // Initialize the first instance to zero if the rowset is
  690. // not a child rowset
  691. //=============================================================
  692. if(m_bIsChildRs != TRUE && ( m_uRsType == 0 || m_uRsType == SCHEMA_ROWSET || m_uRsType == COMMAND_ROWSET || m_uRsType == METHOD_ROWSET))
  693. {
  694. hr = ResetInstances();
  695. }
  696. else
  697. //======================================================================================
  698. // Create the chaptermanager with CRowsetpointers only if the rowset is a child rowset
  699. //======================================================================================
  700. if(m_bIsChildRs == TRUE)
  701. {
  702. m_pChapterMgr = new CChapterMgr();
  703. if ( !m_pChapterMgr )
  704. {
  705. hr = E_OUTOFMEMORY;
  706. }
  707. }
  708. if(!FAILED(hr))
  709. {
  710. //=======================================================
  711. // Call this function to allocate memory for all
  712. // contained interfaces
  713. //=======================================================
  714. hr = AllocateInterfacePointers();
  715. }
  716. } // if( S_OK == (hr = CBaseRowObj::GetColumnInfo()))
  717. } // if(!FAILED(hr)) after Setting the rowset properties
  718. //===========================================================================
  719. // Call this function to increment the number of rowsets opened by command
  720. // if rowset is opened by command
  721. //===========================================================================
  722. if( SUCCEEDED(hr))
  723. {
  724. //==========================================================
  725. // Call this function to initialize the ISupportErrorInfo;
  726. //==========================================================
  727. hr = AddInterfacesForISupportErrorInfo();
  728. if(m_pParentCmd != NULL)
  729. {
  730. m_pParentCmd->IncrementOpenRowsets();
  731. }
  732. if(cErrors > 0)
  733. {
  734. hr = DB_S_ERRORSOCCURRED;
  735. }
  736. }
  737. } // If Succeeded(hr) after allocating memory for utilprop
  738. return hr;
  739. }
  740. ///////////////////////////////////////////////////////////////////////////////////////////////
  741. // Allocate memory for the different interfaces
  742. ///////////////////////////////////////////////////////////////////////////////////////////////
  743. HRESULT CRowset::AllocateInterfacePointers()
  744. {
  745. HRESULT hr = S_OK;
  746. BOOL bRowChange = TRUE;
  747. //===========================================================================================
  748. // Allocate contained interface objects
  749. // Note that our approach is simple - we always create *all* of the Rowset interfaces
  750. // If our properties were read\write (i.e., could be set), we would need to
  751. // consult properties to known which interfaces to create.
  752. // Also, none of our interfaces conflict. If any did conflict, then we could
  753. // not just blindly create them all.
  754. //===========================================================================================
  755. m_pIAccessor = new CImpIAccessor( this );
  756. if( m_pIAccessor )
  757. {
  758. hr = m_pIAccessor->FInit() ;
  759. }
  760. else
  761. hr = E_OUTOFMEMORY;
  762. if(SUCCEEDED(hr))
  763. {
  764. m_pIColumnsInfo = new CImpIColumnsInfo( this );
  765. m_pIConvertType = new CImpIConvertType(this);
  766. m_pIRowset = new CImpIRowsetLocate( this );
  767. if(m_ulProps & IROWSETCHANGE )
  768. {
  769. m_pIRowsetChange = new CImpIRowsetChange( this );
  770. }
  771. m_pIRowsetIdentity = new CImpIRowsetIdentity( this );
  772. m_pIRowsetInfo = new CImpIRowsetInfo( this );
  773. m_pIChapteredRowset = new CImpIChapteredRowset(this);
  774. m_pIGetRow = new CImpIGetRow(this);
  775. m_pIRowsetRefresh = new CImplIRowsetRefresh(this);
  776. m_pISupportErrorInfo = new CImpISupportErrorInfo(this);
  777. //===============================================================
  778. // If rowset is pointing to qualifier then instantiate the
  779. // qualifier fetch object
  780. //===============================================================
  781. if(m_uRsType == PROPERTYQUALIFIER || m_uRsType == CLASSQUALIFIER)
  782. {
  783. m_pRowFetchObj = (CRowFetchObj *)new CQualifierRowFetchObj;
  784. }
  785. else
  786. {
  787. m_pRowFetchObj = (CRowFetchObj *)new CInstanceRowFetchObj;
  788. }
  789. }
  790. if(SUCCEEDED(hr))
  791. {
  792. if( (m_pIRowsetChange == NULL) && ((m_ulProps & IROWSETCHANGE) != 0))
  793. {
  794. bRowChange = FALSE;
  795. }
  796. //===========================================================================================
  797. // if all interfaces were created, return success
  798. //===========================================================================================
  799. if( ! (m_pIAccessor && m_pIColumnsInfo && m_pIConvertType && m_pIRowset && bRowChange && m_pIRowsetIdentity && m_pIRowsetInfo && m_pIChapteredRowset && m_pIRowsetRefresh && m_pISupportErrorInfo))
  800. {
  801. hr = E_OUTOFMEMORY;
  802. }
  803. }
  804. return hr;
  805. }
  806. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  807. // Function to initialize Rowset properties and also set some of the flags on CWMIOledbMap accordingly
  808. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  809. void CRowset::InitializeRowsetProperties()
  810. {
  811. HRESULT hr = S_OK;
  812. VARIANT varProp;
  813. VariantInit(&varProp);
  814. //===========================================================================================
  815. // Initialize the common rowset properties ( boolean properties)
  816. // and put that in the member variable
  817. //===========================================================================================
  818. GetCommonRowsetProperties();
  819. //===========================================================================================
  820. // set the forwardonly flag of enumerator to null depending on
  821. // the properties
  822. //===========================================================================================
  823. // NTRaid 14199
  824. // 07/14/2000. The navigation flags of the parent rowset for qualifier rowset was getting changed
  825. if(!((CANSCROLLBACKWARDS & m_ulProps) || (CANFETCHBACKWARDS & m_ulProps) || (BOOKMARKPROP & m_ulProps)) ||
  826. (m_uRsType == METHOD_ROWSET) && (m_uRsType != PROPERTYQUALIFIER || m_uRsType != CLASSQUALIFIER))
  827. {
  828. m_pMap->SetNavigationFlags(WBEM_FLAG_FORWARD_ONLY);
  829. m_ulProps = m_ulProps & ~CANSCROLLBACKWARDS;
  830. m_ulProps = m_ulProps & ~CANFETCHBACKWARDS;
  831. m_ulProps = m_ulProps & ~BOOKMARKPROP;
  832. m_ulProps = m_ulProps & ~IROWSETLOCATE;
  833. }
  834. //===========================================================================================
  835. // If the custom WMIOLEDB property FETCHDEEP is set , then set the other OLEDB props
  836. // which reflects the behaviour of the rowset
  837. //===========================================================================================
  838. if(FETCHDEEP & m_ulProps)
  839. {
  840. varProp.vt = VT_BOOL;
  841. varProp.boolVal = VARIANT_TRUE;
  842. m_pMap->SetQueryFlags(WBEM_FLAG_DEEP);
  843. //===========================================================================================
  844. // If enumeration is opened as FLAG_DEEP, it is bidirectional
  845. // So set the respective properties
  846. //===========================================================================================
  847. SetRowsetProperty(DBPROP_CANSCROLLBACKWARDS,varProp);
  848. SetRowsetProperty(DBPROP_CANFETCHBACKWARDS,varProp);
  849. }
  850. VariantClear(&varProp);
  851. //===========================================================================================
  852. // Get the DataSource property to check if system Properties is to be fetched?
  853. //===========================================================================================
  854. m_pCreator->GetDataSrcProperty(DBPROP_WMIOLEDB_SYSTEMPROPERTIES,varProp);
  855. if( varProp.boolVal == VARIANT_TRUE)
  856. {
  857. m_pMap->SetSytemPropertiesFlag(TRUE);
  858. }
  859. VariantClear(&varProp);
  860. }
  861. /////////////////////////////////////////////////////////////////////////////////////////////////////
  862. // Function to add interfaces to ISupportErrorInfo interface
  863. /////////////////////////////////////////////////////////////////////////////////////////////////////
  864. HRESULT CRowset::AddInterfacesForISupportErrorInfo()
  865. {
  866. HRESULT hr = S_OK;
  867. if(SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IAccessor)) &&
  868. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IColumnsInfo)) &&
  869. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IConvertType)) &&
  870. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowset)) &&
  871. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_ISourcesRowset)) &&
  872. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowsetIdentity)))
  873. {
  874. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowsetInfo);
  875. }
  876. if(SUCCEEDED(hr) && (m_ulProps & IROWSETLOCATE))
  877. {
  878. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowsetLocate);
  879. }
  880. if(SUCCEEDED(hr) && (m_ulProps & IROWSETCHANGE))
  881. {
  882. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowsetChange);
  883. }
  884. if(SUCCEEDED(hr) && (m_ulProps & ICHAPTEREDROWSET))
  885. {
  886. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IChapteredRowset);
  887. }
  888. if(SUCCEEDED(hr) && (m_ulProps & IGETROW))
  889. {
  890. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IGetRow);
  891. }
  892. if(SUCCEEDED(hr) && (m_ulProps & IROWSETREFRESH))
  893. {
  894. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IRowsetRefresh);
  895. }
  896. return hr;
  897. }
  898. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  899. //
  900. // Creates DBCOLINFO structures for each column in the result set.
  901. //
  902. // HRESULT
  903. // S_OK Column Info Obtained
  904. // E_FAIL Problems getting Column Info
  905. //
  906. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  907. HRESULT CRowset::GatherColumnInfo()
  908. {
  909. //=======================================================
  910. // Call GatherColumnInfo() on the base object
  911. //=======================================================
  912. HRESULT hr = CBaseRowObj::GatherColumnInfo();
  913. //=============================================================
  914. // Initialize the first instance to zero if the rowset is
  915. // not a child rowset
  916. //=============================================================
  917. if(hr == S_OK && m_bIsChildRs != TRUE)
  918. {
  919. ResetInstances();
  920. }
  921. return hr;
  922. }
  923. /////////////////////////////////////////////////////////////////////////////////////////////////
  924. //
  925. // Creates Helper classes that are needed to manage the Rowset Object
  926. //
  927. // HRESULT
  928. // S_OK Helper classes created
  929. // E_FAIL Helper classes were not created
  930. //
  931. // NTRaid : 142133 & 141923
  932. // 07/12/00
  933. /////////////////////////////////////////////////////////////////////////////////////////////////
  934. HRESULT CRowset::CreateHelperFunctions ( void )
  935. {
  936. HRESULT hr = E_OUTOFMEMORY;
  937. if(m_cTotalCols == 0)
  938. {
  939. hr = S_OK;
  940. }
  941. else
  942. //============================================================================
  943. // List of free slots.
  944. // This manages the allocation of sets of contiguous rows.
  945. //============================================================================
  946. if (SUCCEEDED(hr = InitializeSlotList( MAX_TOTAL_ROWBUFF_SIZE / m_cbRowSize, m_cbRowSize, g_dwPageSize,
  947. m_pIAccessor->GetBitArrayPtr(),&m_pIBuffer, &m_rgbRowData )))
  948. {
  949. //============================================================================
  950. // Locate some free slots. Should be at very beginning.
  951. // This tells us which row we will bind to: m_irowMin.
  952. // After getting the slot just release it as this was just a test
  953. //============================================================================
  954. if (SUCCEEDED( hr = GetNextSlots( m_pIBuffer, 1, (HSLOT *)&m_irowMin )))
  955. {
  956. hr = ReleaseSlots( m_pIBuffer, m_irowMin, 1 );
  957. }
  958. }
  959. if(SUCCEEDED(hr))
  960. {
  961. //=================================================
  962. // Allocate and initialize rowdata manager
  963. //=================================================
  964. m_pRowData = new CRowDataMemMgr;
  965. if( m_pRowData != NULL)
  966. {
  967. //=================================================
  968. // Set the number of columns in row
  969. //=================================================
  970. m_pRowData->AllocRowData(m_cTotalCols);
  971. hr = S_OK;
  972. //=================================================
  973. // Allocate memory for instance manager
  974. //=================================================
  975. m_InstMgr = new CWMIInstanceMgr;
  976. if( m_InstMgr != NULL)
  977. {
  978. //==============================================================
  979. // If bookmark is required then allocate an new hashtbl class
  980. //==============================================================
  981. if(m_ulProps & BOOKMARKPROP)
  982. {
  983. m_pHashTblBkmark = new CHashTbl;
  984. if(m_pHashTblBkmark != NULL)
  985. {
  986. //=================================================
  987. // Initialize the hashtable
  988. //=================================================
  989. m_pHashTblBkmark->FInit((PLSTSLOT)m_pIBuffer);
  990. //=================================================
  991. // Call this function to get the number of rows
  992. //=================================================
  993. GetRowCount();
  994. hr = S_OK;
  995. } // if(m_HashTblBkmark != NULL)
  996. } // if( bookmark property is set)
  997. } // if ( instance manage is allocated correctly)
  998. else
  999. {
  1000. hr = E_OUTOFMEMORY;
  1001. }
  1002. } // if( m_pRowData != NULL)
  1003. } // GetNextSlots succeeded
  1004. return hr ;
  1005. }
  1006. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1007. //
  1008. // Establishes data offsets and type for the routines to place the data
  1009. //
  1010. // HRESULT
  1011. // S_OK Bindings set fine
  1012. // E_FAIL Bindings could not be set
  1013. //
  1014. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1015. HRESULT CRowset::Rebind( BYTE *pBase ) // IN Base pointer for Data Area
  1016. {
  1017. HRESULT hr= 0;
  1018. UWORD icol;
  1019. COLUMNDATA *pColumn;
  1020. //==============================================================================
  1021. // Bind result set columns.
  1022. // Use established types and sizes and offsets.
  1023. // Bind to internal row buffer, area beginning with 'pRowBuff'.
  1024. //
  1025. // For each column, bind it's data as well as length.
  1026. // Offsets point to start of COLUMNDATA structure.
  1027. //==============================================================================
  1028. assert( pBase );
  1029. //==============================================================================
  1030. // Optimize by not doing it over again.
  1031. //==============================================================================
  1032. if (pBase != m_pLastBindBase)
  1033. {
  1034. hr = E_UNEXPECTED;
  1035. m_pLastBindBase = 0;
  1036. for (icol=0; icol < m_cTotalCols; icol++)
  1037. {
  1038. //======================================================================
  1039. // Parent columns... what about nested ?
  1040. //======================================================================
  1041. pColumn = (COLUMNDATA *) (pBase + m_Columns.GetDataOffset(icol));
  1042. hr = m_pRowData->SetColumnBind( icol, pColumn );
  1043. if( hr != S_OK )
  1044. {
  1045. break;
  1046. }
  1047. }
  1048. if( hr == S_OK )
  1049. {
  1050. //=================================================
  1051. // Remember in case we bind to same place again.
  1052. //=================================================
  1053. m_pLastBindBase = pBase;
  1054. }
  1055. }
  1056. return hr;
  1057. }
  1058. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1059. //
  1060. //
  1061. // Shorthand way to get the address of a row buffer. Later we may extend this so that it can span several
  1062. // non-contiguous blocks of memory.
  1063. //
  1064. // Pointer to the buffer.
  1065. //
  1066. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1067. ROWBUFF* CRowset::GetRowBuff( HROW iRow, // IN Row to get address of.
  1068. BOOL fDataLocation ) // IN Get the Data offset.
  1069. {
  1070. HSLOT hSlot = -1;
  1071. //=====================================================================
  1072. // This assumes iRow is valid...
  1073. //=====================================================================
  1074. assert( m_rgbRowData );
  1075. assert( m_cbRowSize );
  1076. assert( iRow > 0 );
  1077. if(m_bIsChildRs == FALSE)
  1078. {
  1079. //=================================================
  1080. // Get the slot number for the row
  1081. //=================================================
  1082. hSlot = m_InstMgr->GetSlot(iRow);
  1083. }
  1084. //=================================================================================
  1085. // if rowset is refering to qualifiers then add the row to the particular chapter
  1086. //=================================================================================
  1087. else
  1088. {
  1089. //=================================================
  1090. // Get the slot number for the row
  1091. //=================================================
  1092. hSlot = m_pChapterMgr->GetSlot(iRow);
  1093. }
  1094. return (hSlot != -1) ? GetRowBuffer(m_pIBuffer,(ULONG)hSlot): NULL;
  1095. }
  1096. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1097. //
  1098. //
  1099. // Shorthand way to get the address of a row buffer.
  1100. //
  1101. // Pointer to the buffer.
  1102. //
  1103. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1104. ROWBUFF* CRowset::GetRowBuffFromSlot( HSLOT hSlot, // IN Row to get address of.
  1105. BOOL fDataLocation ) // IN Get the Data offset.
  1106. {
  1107. //=====================================================================
  1108. // This assumes iRow is valid...
  1109. //=====================================================================
  1110. assert( m_rgbRowData );
  1111. assert( m_cbRowSize );
  1112. assert( hSlot >= 0 );
  1113. return GetRowBuffer(m_pIBuffer,hSlot);
  1114. }
  1115. ////////////////////////////////////////////////////////////////////////////
  1116. // Reset the position of the instances in the enumerator to the begining
  1117. ////////////////////////////////////////////////////////////////////////////
  1118. HRESULT CRowset::ResetInstances()
  1119. {
  1120. return m_pMap->ResetInstances();
  1121. }
  1122. ////////////////////////////////////////////////////////////////////////////
  1123. // Reset the qualifer set of the property/class/instance
  1124. ////////////////////////////////////////////////////////////////////////////
  1125. HRESULT CRowset::ResetQualifers(HCHAPTER hChapter)
  1126. {
  1127. HRESULT hr = S_OK;
  1128. CWbemClassWrapper *pInst = NULL;
  1129. //=====================================================================
  1130. // Get the pointer to instance for which qualifier is to
  1131. // be reset
  1132. //=====================================================================
  1133. if( hChapter > 0 && m_bIsChildRs == TRUE)
  1134. {
  1135. pInst = m_pChapterMgr->GetInstance(hChapter);
  1136. }
  1137. else
  1138. {
  1139. pInst = m_pInstance;
  1140. }
  1141. //=================================================
  1142. // If valid instance then reset the qualifier
  1143. //=================================================
  1144. if(pInst)
  1145. {
  1146. m_pMap->ReleaseQualifier(pInst,m_strPropertyName);
  1147. }
  1148. else
  1149. {
  1150. hr = DB_E_BADCHAPTER;
  1151. }
  1152. return hr;
  1153. }
  1154. /////////////////////////////////////////////////////////////////////////////////
  1155. // Reset the position of the instances in the enumerator the required position
  1156. /////////////////////////////////////////////////////////////////////////////////
  1157. HRESULT CRowset::ResetRowsetToNewPosition(DBROWOFFSET uWhich,CWbemClassWrapper *pInst)
  1158. {
  1159. HRESULT hr = S_OK;
  1160. switch(m_uRsType)
  1161. {
  1162. case PROPERTYQUALIFIER:
  1163. hr = m_pMap->ResetPropQualiferToNewPosition(pInst,uWhich,m_strPropertyName);
  1164. break;
  1165. case CLASSQUALIFIER:
  1166. hr = m_pMap->ResetClassQualiferToNewPosition(pInst,uWhich);
  1167. break;
  1168. case SCHEMA_ROWSET:
  1169. // NTRaid : 134987
  1170. // 07/12/00
  1171. hr = m_pMap->ResetInstancesToNewPosition(uWhich);
  1172. break;
  1173. case 0:
  1174. case COMMAND_ROWSET:
  1175. case METHOD_ROWSET:
  1176. hr = m_pMap->ResetInstancesToNewPosition(uWhich);
  1177. break;
  1178. default:
  1179. hr = E_FAIL;
  1180. break;
  1181. }
  1182. return hr;
  1183. }
  1184. ///////////////////////////////////////////////////////
  1185. // Get the pointer and key to the next instance
  1186. ///////////////////////////////////////////////////////
  1187. HRESULT CRowset::GetNextInstance(CWbemClassWrapper *&ppInst,CBSTR &strKey, BOOL bFetchBack)
  1188. {
  1189. //=================================================
  1190. // Reset the column Index of the data manager
  1191. //=================================================
  1192. m_pRowData->ResetColumns();
  1193. return m_pMap->GetNextInstance(ppInst,strKey,bFetchBack);
  1194. }
  1195. ///////////////////////////////////////////////////////
  1196. // Get the next property qualifier
  1197. ///////////////////////////////////////////////////////
  1198. HRESULT CRowset::GetNextPropertyQualifier(CWbemClassWrapper *pInst,BSTR strPropName,BSTR &strQualifier,BOOL bFetchBack)
  1199. {
  1200. HRESULT hr = S_OK;
  1201. //=================================================
  1202. // Reset the column Index of the data manager
  1203. //=================================================
  1204. m_pRowData->ResetColumns();
  1205. hr = m_pMap->GetNextPropertyQualifier(pInst,strPropName,strQualifier,bFetchBack);
  1206. return hr;
  1207. }
  1208. ///////////////////////////////////////////////////////
  1209. // Get the next Class qualifier
  1210. ///////////////////////////////////////////////////////
  1211. HRESULT CRowset::GetNextClassQualifier(CWbemClassWrapper *pInst,BSTR &strQualifier,BOOL bFetchBack)
  1212. {
  1213. HRESULT hr = S_OK;
  1214. //=================================================
  1215. // Reset the column Index of the data manager
  1216. //=================================================
  1217. m_pRowData->ResetColumns();
  1218. hr = m_pMap->GetNextClassQualifier(pInst,strQualifier,bFetchBack);
  1219. return hr;
  1220. }
  1221. //////////////////////////////////////////////////////////////////////////
  1222. // Get the data from the instance and populate it into the local buffer
  1223. //////////////////////////////////////////////////////////////////////////
  1224. HRESULT CRowset::GetInstanceDataToLocalBuffer(CWbemClassWrapper *pInst,HSLOT hSlot,BSTR strQualifier)
  1225. {
  1226. HRESULT hr = S_OK;
  1227. PROWBUFF pRowBuff = NULL;
  1228. pRowBuff = GetRowBuffFromSlot( hSlot, TRUE );
  1229. if (FAILED( Rebind((BYTE *)pRowBuff )))
  1230. {
  1231. hr = E_FAIL ;
  1232. }
  1233. else
  1234. //=====================================================
  1235. // Reset the column to point to the first column and
  1236. // get the data and put it into the buffer
  1237. //=====================================================
  1238. if( S_OK == (hr = m_pRowData->ResetColumns()))
  1239. {
  1240. switch(m_uRsType)
  1241. {
  1242. case PROPERTYQUALIFIER:
  1243. hr = m_pMap->GetDataForPropertyQualifier(m_pRowData,pInst,m_strPropertyName,strQualifier,&m_Columns);
  1244. break;
  1245. case CLASSQUALIFIER:
  1246. hr = m_pMap->GetDataForClassQualifier(m_pRowData,pInst,strQualifier,&m_Columns);
  1247. break;
  1248. case SCHEMA_ROWSET:
  1249. hr = m_pMap->GetDataForSchemaInstance(m_pRowData,pInst,&m_Columns);
  1250. break;
  1251. case 0:
  1252. case COMMAND_ROWSET:
  1253. case METHOD_ROWSET:
  1254. hr = m_pMap->GetDataForInstance(m_pRowData,pInst,&m_Columns);
  1255. break;
  1256. default:
  1257. hr = E_FAIL;
  1258. break;
  1259. }
  1260. }
  1261. return hr;
  1262. }
  1263. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1264. // Set rowset properties. This is called during initialization of the rowset
  1265. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1266. HRESULT CRowset::SetRowsetProperties(const ULONG cPropertySets, const DBPROPSET rgPropertySets[] )
  1267. {
  1268. HRESULT hr = S_OK;
  1269. VARIANT varPropVal;
  1270. VariantInit(&varPropVal);
  1271. LONG lFlag = 0;
  1272. // call the base class implementation for setting properties
  1273. hr = SetProperties(cPropertySets,rgPropertySets);
  1274. //============================================================================
  1275. // call this function to set the DBPROP_UPDATIBILITY to readonly if the Datasource
  1276. // open mode is readonly
  1277. //============================================================================
  1278. if( (hr == S_OK) || (hr == DB_S_ERRORSOCCURRED) )
  1279. {
  1280. SynchronizeDataSourceMode();
  1281. }
  1282. //============================================================================
  1283. // Get some properties to determine whether to support bookmarks or not
  1284. //============================================================================
  1285. if( S_OK == GetRowsetProperty(DBPROP_CANSCROLLBACKWARDS,varPropVal) &&
  1286. varPropVal.vt == VT_BOOL && varPropVal.boolVal == VARIANT_TRUE)
  1287. {
  1288. lFlag = lFlag | CANSCROLLBACKWARDS;
  1289. }
  1290. if( S_OK == GetRowsetProperty(DBPROP_CANFETCHBACKWARDS,varPropVal) &&
  1291. varPropVal.vt == VT_BOOL && varPropVal.boolVal == VARIANT_TRUE)
  1292. {
  1293. lFlag = lFlag | CANFETCHBACKWARDS;
  1294. }
  1295. if( S_OK == GetRowsetProperty(DBPROP_IRowsetLocate,varPropVal) &&
  1296. varPropVal.vt == VT_BOOL && varPropVal.boolVal == VARIANT_TRUE)
  1297. {
  1298. lFlag = lFlag | IROWSETLOCATE;
  1299. }
  1300. if( S_OK == GetRowsetProperty(DBPROP_OTHERINSERT,varPropVal) &&
  1301. varPropVal.vt == VT_BOOL && varPropVal.boolVal == VARIANT_TRUE)
  1302. {
  1303. lFlag = lFlag | OTHERINSERT;
  1304. }
  1305. //============================================================================
  1306. // if bookmarks are asked then set the fetchback and scrollback properties to true
  1307. //============================================================================
  1308. varPropVal.vt = VT_BOOL;
  1309. if(IROWSETLOCATE & lFlag )
  1310. {
  1311. varPropVal.boolVal = VARIANT_TRUE;
  1312. SetRowsetProperty(DBPROP_CANFETCHBACKWARDS,varPropVal);
  1313. SetRowsetProperty(DBPROP_CANSCROLLBACKWARDS,varPropVal);
  1314. SetRowsetProperty(DBPROP_BOOKMARKS,varPropVal);
  1315. lFlag = lFlag | CANSCROLLBACKWARDS;
  1316. lFlag = lFlag | CANFETCHBACKWARDS;
  1317. lFlag = lFlag | BOOKMARKPROP;
  1318. }
  1319. //============================================================================
  1320. // Bookmarks are not supported for qualifier rowsets
  1321. //============================================================================
  1322. if(m_uRsType == PROPERTYQUALIFIER || m_uRsType == CLASSQUALIFIER)
  1323. {
  1324. varPropVal.boolVal = VARIANT_FALSE;
  1325. SetRowsetProperty(DBPROP_BOOKMARKS,varPropVal);
  1326. SetRowsetProperty(DBPROP_IRowsetLocate,varPropVal);
  1327. lFlag = lFlag & ~BOOKMARKPROP;
  1328. lFlag = lFlag & ~IROWSETLOCATE;
  1329. }
  1330. VariantClear(&varPropVal);
  1331. return hr;
  1332. }
  1333. ///////////////////////////////////////////////////////////////////////////
  1334. // Function to Allocate and Iniatialize rowsets for child recordsets //
  1335. ///////////////////////////////////////////////////////////////////////////
  1336. HRESULT CRowset::AllocateAndInitializeChildRowsets()
  1337. {
  1338. HRESULT hr = E_FAIL;
  1339. DBPROPSET *rgPropsets = NULL;
  1340. ULONG cProperties = 0;
  1341. ULONG nIndex = 0 , nIndex2 = 0;
  1342. ULONG lColType = 0;
  1343. //===========================================================================================
  1344. // if there are nested columns in the rowset and if childrowsets are not already allocated
  1345. //===========================================================================================
  1346. if(m_cNestedCols > 0 && m_ppChildRowsets == NULL)
  1347. {
  1348. //=============================================================
  1349. // Allocate pointers for the child rowsets
  1350. //=============================================================
  1351. m_ppChildRowsets = (CBaseRowObj **)new CRowset*[m_cTotalCols];
  1352. if(m_ppChildRowsets == NULL)
  1353. {
  1354. hr = E_OUTOFMEMORY;
  1355. }
  1356. else
  1357. {
  1358. //================================================================================
  1359. // Get the rowset Properties
  1360. //================================================================================
  1361. if(S_OK == (hr = m_pIRowsetInfo->GetProperties(cProperties,NULL,&cProperties,&rgPropsets)))
  1362. {
  1363. for ( nIndex = 0 ; nIndex < m_cTotalCols ; nIndex++)
  1364. {
  1365. //========================================================================
  1366. // if the columntype is of CHAPTER then allocate a rowset and initialize
  1367. //========================================================================
  1368. if(m_Columns.ColumnFlags(nIndex) & DBCOLUMNFLAGS_ISCHAPTER )
  1369. {
  1370. lColType = m_pMap->ParseQualifiedNameToGetColumnType(m_Columns.ColumnName(nIndex));
  1371. if(lColType == WMI_CLASS_QUALIFIER)
  1372. {
  1373. m_ppChildRowsets[nIndex] = (CBaseRowObj*) new CRowset(m_pUnkOuter,CLASSQUALIFIER, NULL,m_pCreator, m_pMap);
  1374. }
  1375. else
  1376. if(lColType == WMI_PROPERTY_QUALIFIER)
  1377. {
  1378. m_ppChildRowsets[nIndex] = (CBaseRowObj*) new CRowset(m_pUnkOuter,PROPERTYQUALIFIER, m_Columns.ColumnName(nIndex-1),m_pCreator, m_pMap);
  1379. }
  1380. if(m_ppChildRowsets[nIndex] == NULL)
  1381. {
  1382. hr = E_OUTOFMEMORY;
  1383. break;
  1384. }
  1385. else
  1386. {
  1387. //===================================================================
  1388. // Initialize the rowset properties
  1389. //===================================================================
  1390. hr = ((CRowset *)m_ppChildRowsets[nIndex])->InitRowset( cProperties, rgPropsets );
  1391. m_ppChildRowsets[nIndex]->AddRef();
  1392. }
  1393. } // if for columntype
  1394. else
  1395. m_ppChildRowsets[nIndex] = NULL;
  1396. } // for
  1397. } // GetProperties
  1398. //==========================================================================
  1399. // Free memory we allocated to by m_pIRowsetInfo->GetProperties
  1400. //==========================================================================
  1401. m_pUtilProp->m_PropMemMgr.FreeDBPROPSET( cProperties, rgPropsets);
  1402. } // if memory for pointers allocated successfully
  1403. }
  1404. return hr;
  1405. }
  1406. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1407. // Get the pointer to the child recordset for the given ordinal
  1408. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1409. HRESULT CRowset::GetChildRowset(DBORDINAL ulOrdinal,REFIID riid, IUnknown ** ppIRowset)
  1410. {
  1411. HRESULT hr = S_OK;
  1412. //===============================================================================================
  1413. // If row the child rowset pointer is fetched before fetching any rows from the parent rowsets
  1414. // then this will be called before allocating the child recordset. SO allocate the child rowsets
  1415. //===============================================================================================
  1416. if( m_ppChildRowsets == NULL)
  1417. {
  1418. hr = AllocateAndInitializeChildRowsets();
  1419. }
  1420. if(SUCCEEDED(hr))
  1421. {
  1422. hr = DB_E_NOTAREFERENCECOLUMN;
  1423. if(m_cNestedCols > 0)
  1424. {
  1425. if( ulOrdinal > m_cTotalCols)
  1426. {
  1427. hr = DB_E_BADORDINAL;
  1428. }
  1429. else
  1430. if(m_ppChildRowsets[ulOrdinal] != NULL)
  1431. {
  1432. hr = m_ppChildRowsets[ulOrdinal]->QueryInterface(riid,(void **)ppIRowset);
  1433. }
  1434. }
  1435. }
  1436. return hr;
  1437. }
  1438. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1439. // Check if the HCHAPTER passed is valid or not
  1440. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1441. HRESULT CRowset::CheckAndInitializeChapter(HCHAPTER hChapter)
  1442. {
  1443. HRESULT hr = E_FAIL;
  1444. if(m_bIsChildRs && m_pChapterMgr->IsExists(hChapter))
  1445. {
  1446. hr = S_OK;
  1447. }
  1448. return hr;
  1449. }
  1450. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1451. // Function to release the instance pointers when ReleaseRows is called
  1452. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1453. HRESULT CRowset::ReleaseInstancePointer(HROW hRow)
  1454. {
  1455. //========================================================================
  1456. // if the recordset is representing a class
  1457. //========================================================================
  1458. if(m_bIsChildRs == FALSE )
  1459. {
  1460. m_InstMgr->DeleteInstanceFromList(hRow);
  1461. }
  1462. //===============================================================================
  1463. // if the row is a child recordset then delete the row from the chapter manager
  1464. //===============================================================================
  1465. if(m_bIsChildRs == TRUE)
  1466. {
  1467. m_pChapterMgr->DeleteHRow(hRow);
  1468. }
  1469. return S_OK;
  1470. }
  1471. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1472. // Function to check if the row exist in the chapter or instance manager
  1473. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1474. BOOL CRowset::IsRowExists(HROW hRow)
  1475. {
  1476. BOOL bRet = FALSE;
  1477. if( hRow > 0)
  1478. {
  1479. //========================================================================
  1480. // if the recordset is representing a class
  1481. //========================================================================
  1482. if(m_bIsChildRs == FALSE)
  1483. {
  1484. bRet = m_InstMgr->IsRowExists(hRow);
  1485. }
  1486. //===============================================================================
  1487. // if the row is a child recordset then delete the row from the chapter manager
  1488. //===============================================================================
  1489. if(m_bIsChildRs == TRUE)
  1490. {
  1491. bRet = m_pChapterMgr->IsRowExists(hRow);
  1492. }
  1493. }
  1494. return bRet;
  1495. }
  1496. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1497. // Function to release all the open rows
  1498. // This is called from the destructor
  1499. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1500. HRESULT CRowset::ReleaseAllRows()
  1501. {
  1502. DBROWOPTIONS rgRowOptions[1];
  1503. DBREFCOUNT rgRefCounts[1];
  1504. DBROWSTATUS rgRowStatus[1];
  1505. HRESULT hr = S_OK;
  1506. //==========================================================
  1507. // if there are any rows fetched
  1508. //==========================================================
  1509. if(!( ( m_bIsChildRs == TRUE && m_pChapterMgr == NULL) ||
  1510. ( m_bIsChildRs == FALSE && m_InstMgr == NULL)))
  1511. {
  1512. memset(rgRowOptions,0,sizeof(DBROWOPTIONS));
  1513. memset(rgRowStatus,0,sizeof(DBROWSTATUS));
  1514. rgRefCounts[0] = 0;
  1515. DBCOUNTITEM cRows = 0 , nIndex = 0;
  1516. HROW *prghRows = NULL;
  1517. //=================================================
  1518. // if the rowset is child rowset get the list
  1519. // open rowset from the chapter manager
  1520. //=================================================
  1521. if(m_bIsChildRs)
  1522. {
  1523. hr = m_pChapterMgr->GetAllHROWs(prghRows,cRows);
  1524. }
  1525. //=========================================
  1526. // else get it from the instance manager
  1527. //=========================================
  1528. else
  1529. {
  1530. hr = m_InstMgr->GetAllHROWs(prghRows,cRows);
  1531. }
  1532. //===============================================
  1533. // If there are open rows the release the rows
  1534. //===============================================
  1535. if(cRows > 0)
  1536. {
  1537. for(nIndex = 0 ; nIndex < cRows ; nIndex++)
  1538. {
  1539. //==============================================================
  1540. // Release till the reference count on the row goes to zero
  1541. // and thus all the resources allocated for the is released
  1542. //==============================================================
  1543. do
  1544. {
  1545. hr = m_pIRowset->ReleaseRows(1, &(prghRows[nIndex]),rgRowOptions,rgRefCounts,NULL);
  1546. }while(rgRefCounts[0] > 0 && hr == S_OK);
  1547. }
  1548. //====================================================================================
  1549. // delete the memory allocated by the functions which gives the list of open rows
  1550. //====================================================================================
  1551. if(prghRows != NULL)
  1552. {
  1553. delete [] prghRows;
  1554. prghRows = NULL;
  1555. }
  1556. }
  1557. }
  1558. return hr;
  1559. }
  1560. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1561. // Function to find whether the slot for the particular row is set
  1562. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1563. HRESULT CRowset::IsSlotSet(HSLOT hRow)
  1564. {
  1565. HSLOT hSlot = -1;
  1566. HRESULT hr = E_FAIL;
  1567. hSlot = GetSlotForRow(hRow);
  1568. // If valid slot
  1569. if( (hSlot) >= 0)
  1570. {
  1571. hr = m_pIAccessor->GetBitArrayPtr()->IsSlotSet(hSlot);
  1572. }
  1573. return hr;
  1574. }
  1575. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1576. // Function to return the slot number of the row
  1577. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1578. HSLOT CRowset::GetSlotForRow(HROW hRow ) // IN Row handle for which slot number is required
  1579. {
  1580. HSLOT hSlot = -1;
  1581. //=================================================================
  1582. // if the rowset is a parent rowset then
  1583. // get slot number from the instance manager else get it
  1584. // from the chapter manager
  1585. //=================================================================
  1586. if(m_bIsChildRs == FALSE)
  1587. {
  1588. //=================================================
  1589. // Get the slot for the row
  1590. //=================================================
  1591. hSlot = m_InstMgr->GetSlot(hRow);
  1592. }
  1593. //=================================================================================
  1594. // if rowset is refering to qualifiers then add the row to the particular chapter
  1595. //=================================================================================
  1596. else
  1597. {
  1598. //=================================================
  1599. // Get the slot for the row
  1600. //=================================================
  1601. hSlot = m_pChapterMgr->GetSlot(hRow);
  1602. }
  1603. return hSlot;
  1604. }
  1605. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1606. // Function which fetches data and puts it into the local buffer
  1607. // NTRaid: 145773
  1608. // 07/18/00
  1609. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1610. HRESULT CRowset::GetData(HROW hRow,BSTR strQualifier )
  1611. {
  1612. CWbemClassWrapper * pInst = NULL;
  1613. BSTR strKey;
  1614. HSLOT hSlot = 0;
  1615. HRESULT hr = S_OK;
  1616. PROWBUFF pRowBuff = NULL;
  1617. CVARIANT varKey;
  1618. HCHAPTER hChapter = 0;
  1619. //===================================================================
  1620. /// get the instance pointer corresponding to the HROW passed
  1621. // if rowset is referiing to a class and not to qualifiers then
  1622. //===================================================================
  1623. if(m_bIsChildRs == FALSE)
  1624. {
  1625. pInst = m_InstMgr->GetInstance(hRow);
  1626. m_InstMgr->GetInstanceKey(hRow,&strKey);
  1627. hSlot = m_InstMgr->GetSlot(hRow);
  1628. }
  1629. //===================================================================
  1630. // if the recordset is a child rs and representing a qualifier
  1631. //===================================================================
  1632. else
  1633. {
  1634. hChapter = m_pChapterMgr->GetChapterForHRow(hRow);
  1635. if( hChapter <= 0)
  1636. {
  1637. hr = DB_E_BADCHAPTER;
  1638. }
  1639. else
  1640. {
  1641. //===================================================================
  1642. // get the instance pointer corresponding to the
  1643. //===================================================================
  1644. pInst = m_pChapterMgr->GetInstance(hChapter);
  1645. m_pChapterMgr->GetInstanceKey(hChapter,&strKey, hRow);
  1646. hSlot = m_pChapterMgr->GetSlot(hRow);
  1647. }
  1648. }
  1649. // NTRaid:111830
  1650. if(hSlot == 0 || pInst == NULL)
  1651. {
  1652. hr = DB_E_BADROWHANDLE;
  1653. }
  1654. else
  1655. if ( SUCCEEDED(hr))
  1656. {
  1657. if(!( m_uRsType == PROPERTYQUALIFIER ||
  1658. m_uRsType == CLASSQUALIFIER))
  1659. {
  1660. assert(strQualifier == NULL);
  1661. //===================================================================
  1662. // Refresh the instance.
  1663. // This is to get the latest instance if modified from another instance
  1664. //===================================================================
  1665. if(m_ulProps & OTHERUPDATEDELETE)
  1666. {
  1667. hr = RefreshInstance(pInst);
  1668. }
  1669. //===================================================================
  1670. // Filling data for the bookmark column
  1671. //===================================================================
  1672. varKey.SetStr(strKey);
  1673. }
  1674. else
  1675. {
  1676. // If the otherupdate is true then strQualifier will be NULL
  1677. if(m_ulProps & OTHERUPDATEDELETE)
  1678. {
  1679. // Filling data for the bookmark column
  1680. varKey.SetStr(strKey);
  1681. }
  1682. else
  1683. {
  1684. // Filling data for the bookmark column
  1685. varKey.SetStr(strQualifier);
  1686. }
  1687. }
  1688. if(SUCCEEDED(hr = GetInstanceDataToLocalBuffer(pInst,hSlot,varKey.GetStr())))
  1689. {
  1690. //===========================================================================
  1691. // if there is atleast one row retrieved and there are neseted columns
  1692. // then allocate rows for the child recordsets
  1693. //===========================================================================
  1694. if(m_cNestedCols > 0 )
  1695. {
  1696. if(m_ppChildRowsets == NULL)
  1697. {
  1698. hr = AllocateAndInitializeChildRowsets();
  1699. }
  1700. //=====================================================================
  1701. // Fill the HCHAPTERS for the column
  1702. //=====================================================================
  1703. if( SUCCEEDED(hr))
  1704. {
  1705. hr = FillHChaptersForRow(pInst,strKey);
  1706. }
  1707. }
  1708. if( SUCCEEDED(hr))
  1709. {
  1710. //===================================================
  1711. // if the class is not representing qualilfiers
  1712. //===================================================
  1713. if(m_bIsChildRs == FALSE)
  1714. {
  1715. //=================================================
  1716. // Set the slot for the row
  1717. //=================================================
  1718. hr = m_InstMgr->SetSlot(hRow,hSlot);
  1719. }
  1720. //=================================================================================
  1721. // if rowset is refering to qualifiers then add the row to the particular chapter
  1722. //=================================================================================
  1723. else
  1724. {
  1725. //==============================================
  1726. // Set the slot for the Row
  1727. //==============================================
  1728. if(SUCCEEDED(hr = m_pChapterMgr->SetSlot(hRow,hSlot)))
  1729. {
  1730. m_pChapterMgr->SetInstance(hChapter,pInst, varKey.GetStr() ,hRow);
  1731. }
  1732. }
  1733. if(SUCCEEDED(hr))
  1734. {
  1735. pRowBuff = GetRowBuff( (ULONG) hRow, TRUE );
  1736. // NTRaid:111830
  1737. // 06/07/00
  1738. if(pRowBuff)
  1739. {
  1740. //========================================
  1741. // Increment the reference count
  1742. //========================================
  1743. pRowBuff->ulRefCount++;
  1744. }
  1745. else
  1746. {
  1747. hr = E_FAIL;
  1748. }
  1749. }
  1750. //==============================================
  1751. // Free the string
  1752. //==============================================
  1753. if(m_bIsChildRs == FALSE)
  1754. {
  1755. SysFreeString(strKey);
  1756. }
  1757. } // Succeeded(hr)
  1758. }
  1759. varKey.Clear();
  1760. } // Succeeded(hr)
  1761. return hr;
  1762. }
  1763. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1764. // Function to update a row to WMI
  1765. // NTRaid : 143868
  1766. // 07/15/00
  1767. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1768. HRESULT CRowset::UpdateRowData(HROW hRow,PACCESSOR pAccessor , BOOL bNewInst)
  1769. {
  1770. HRESULT hr = S_OK;
  1771. PROWBUFF pRowBuff = NULL;
  1772. DBORDINAL ibind = 0;
  1773. COLUMNDATA * pColumnData = NULL;
  1774. CWbemClassWrapper * pInst = NULL;
  1775. DBORDINAL icol = 0;
  1776. BOOL bRowModified = FALSE;
  1777. BSTR bstrColName;
  1778. BSTR strQualifierName =Wmioledb_SysAllocString(NULL);
  1779. CDataMap dataMap;
  1780. VARIANT varData;
  1781. LONG lFlavor = 0;
  1782. VariantInit(&varData);
  1783. DWORD dwCIMType = 0;
  1784. //=================================================================================
  1785. // get the pointer to the instance
  1786. //=================================================================================
  1787. if(m_bIsChildRs == FALSE)
  1788. {
  1789. if( m_uRsType == PROPERTYQUALIFIER ||
  1790. m_uRsType == CLASSQUALIFIER )
  1791. {
  1792. pInst = m_pInstance;
  1793. }
  1794. else
  1795. if( m_uRsType != COLUMNSROWSET && m_uRsType != SCHEMA_ROWSET && m_uRsType != METHOD_ROWSET)
  1796. {
  1797. pInst = m_InstMgr->GetInstance(hRow);
  1798. }
  1799. }
  1800. else
  1801. {
  1802. pInst = m_pChapterMgr->GetInstance(m_pChapterMgr->GetChapterForHRow(hRow));
  1803. }
  1804. //=================================================================================
  1805. // Get the pointer to the row data
  1806. //=================================================================================
  1807. pRowBuff = GetRowBuff((ULONG) hRow, TRUE );
  1808. // NTRaid:111823-111825
  1809. // 06/07/00
  1810. // If the row is not an instance or qualifier
  1811. if(pInst == NULL)
  1812. {
  1813. hr = DB_E_NOTSUPPORTED;
  1814. }
  1815. else
  1816. //=================================================================================
  1817. // IF the rowset is a qualifier type rowset
  1818. //=================================================================================
  1819. if( m_uRsType == PROPERTYQUALIFIER || m_uRsType == CLASSQUALIFIER )
  1820. {
  1821. //=================================================================================
  1822. // get the qualifier name
  1823. //=================================================================================
  1824. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERNAMECOL));
  1825. if( pColumnData->pbData == NULL)
  1826. {
  1827. hr = DB_E_INTEGRITYVIOLATION; // This is because one of the column values expected
  1828. // is NULL or EMPTY
  1829. bRowModified = TRUE;
  1830. }
  1831. else
  1832. {
  1833. strQualifierName = Wmioledb_SysAllocString((WCHAR *)pColumnData->pbData);
  1834. //=================================================================================
  1835. // Get the qualifier Value
  1836. //=================================================================================
  1837. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERVALCOL));
  1838. VariantCopy(&varData,(VARIANT *)pColumnData->pbData);
  1839. //=================================================================================
  1840. // Get the qualifier flavor
  1841. //=================================================================================
  1842. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERFLAVOR));
  1843. lFlavor = pColumnData->pbData !=NULL ? *(LONG *)pColumnData->pbData : 0 ;
  1844. if( varData.vt != VT_EMPTY || varData.vt != VT_NULL)
  1845. {
  1846. //=================================================================================
  1847. // Set the qualifier
  1848. //=================================================================================
  1849. hr = m_pMap->SetQualifier(pInst,m_strPropertyName,strQualifierName,&varData,lFlavor);
  1850. if( SUCCEEDED(hr))
  1851. {
  1852. //=================================================================================
  1853. // This is becuase , we are just adding a qualifier not a new instance
  1854. //=================================================================================
  1855. bNewInst = FALSE;
  1856. bRowModified = TRUE;
  1857. }
  1858. }
  1859. else
  1860. {
  1861. //=================================================================================
  1862. // This is because one of the column values expected is NULL or empty
  1863. //=================================================================================
  1864. hr = DB_E_INTEGRITYVIOLATION;
  1865. bRowModified = TRUE;
  1866. }
  1867. SysFreeString(strQualifierName);
  1868. VariantClear(&varData);
  1869. }
  1870. }
  1871. else
  1872. for (ibind = 0; ibind < (int)pAccessor->cBindings; ibind++)
  1873. {
  1874. icol = pAccessor->rgBindings[ibind].iOrdinal;
  1875. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(icol));
  1876. //=================================================================================
  1877. // If the columndata is modified then
  1878. //=================================================================================
  1879. if(pColumnData->dwStatus & COLUMNSTAT_MODIFIED)
  1880. {
  1881. bstrColName = Wmioledb_SysAllocString((OLECHAR *)m_Columns.ColumnName(icol));
  1882. // this variable gets value only if the CIMTYPE is array
  1883. dwCIMType = -1;
  1884. // if the type is array , then get the original CIMTYPE as array type will
  1885. // be given out as VT_ARRAY | VT_VARIANT
  1886. if(pColumnData->dwType & DBTYPE_ARRAY)
  1887. {
  1888. dwCIMType = m_Columns.GetCIMType(icol);
  1889. }
  1890. if( pColumnData->pbData == NULL)
  1891. {
  1892. varData.vt = VT_NULL;
  1893. }
  1894. else
  1895. {
  1896. //=================================================================================
  1897. // Call this function to convert the data to the appropriate datatype in a variant
  1898. //=================================================================================
  1899. dataMap.MapAndConvertOLEDBTypeToCIMType((USHORT)pColumnData->dwType,pColumnData->pbData,pColumnData->dwLength,varData,dwCIMType);
  1900. }
  1901. if( m_uRsType == 0)
  1902. {
  1903. //=================================================================================
  1904. // Update the property
  1905. //=================================================================================
  1906. hr = m_pMap->SetProperty(pInst,bstrColName,&varData);
  1907. }
  1908. pColumnData->dwStatus &= ~COLUMNSTAT_MODIFIED;
  1909. VariantClear(&varData);
  1910. SysFreeString(bstrColName);
  1911. bRowModified = TRUE;
  1912. }
  1913. }
  1914. if(SUCCEEDED(hr) && (bRowModified == TRUE || bNewInst == TRUE))
  1915. {
  1916. hr = m_pMap->UpdateInstance(pInst , bNewInst);
  1917. }
  1918. return hr;
  1919. }
  1920. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1921. // Function to update a row to WMI
  1922. // this is called from Row Object
  1923. // NTRaid : 143868
  1924. // 07/15/00
  1925. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1926. HRESULT CRowset::UpdateRowData(HROW hRow,DBORDINAL cColumns,DBCOLUMNACCESS rgColumns[ ])
  1927. {
  1928. HRESULT hr = S_OK;
  1929. PROWBUFF pRowBuff = NULL;
  1930. DBORDINAL lIndex = 0;
  1931. COLUMNDATA * pColumnData = NULL;
  1932. CWbemClassWrapper * pInst = NULL;
  1933. DBORDINAL icol = 0;
  1934. BSTR bstrColName;
  1935. CDataMap dataMap;
  1936. VARIANT varData;
  1937. VariantInit(&varData);
  1938. LONG lFlavor = 0;
  1939. BSTR strQualifierName =Wmioledb_SysAllocString(NULL);
  1940. DWORD dwCIMType = 0;
  1941. // get the pointer to the instance
  1942. if(m_bIsChildRs == FALSE)
  1943. {
  1944. if( m_uRsType == PROPERTYQUALIFIER ||
  1945. m_uRsType == CLASSQUALIFIER )
  1946. {
  1947. pInst = m_pInstance;
  1948. }
  1949. else
  1950. if( m_uRsType != COLUMNSROWSET && m_uRsType != SCHEMA_ROWSET && m_uRsType != METHOD_ROWSET)
  1951. {
  1952. pInst = m_InstMgr->GetInstance(hRow);
  1953. }
  1954. }
  1955. else
  1956. {
  1957. pInst = m_pChapterMgr->GetInstance(m_pChapterMgr->GetChapterForHRow(hRow));
  1958. }
  1959. //=========================================
  1960. // Get the pointer to the row data
  1961. //=========================================
  1962. pRowBuff = GetRowBuff((ULONG) hRow, TRUE );
  1963. // NTRaid:111823-111825
  1964. // 06/07/00
  1965. // If the row is not an instance or qualifier
  1966. if(pInst == NULL)
  1967. {
  1968. hr = DB_E_NOTSUPPORTED;
  1969. }
  1970. else
  1971. //================================================
  1972. // IF the rowset is a qualifier type rowset
  1973. //================================================
  1974. if( m_uRsType == PROPERTYQUALIFIER || m_uRsType == CLASSQUALIFIER )
  1975. {
  1976. icol = GetOrdinalFromColName(rgColumns[lIndex].columnid.uName.pwszName);
  1977. //===============================================
  1978. // Only qualifier value can be modified
  1979. //===============================================
  1980. if(cColumns == 1 && icol == QUALIFIERVALCOL)
  1981. {
  1982. //===============================================
  1983. // get the qualifier name
  1984. //===============================================
  1985. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERNAMECOL));
  1986. if( pColumnData->pbData == NULL)
  1987. {
  1988. hr = DB_E_INTEGRITYVIOLATION; // This is because one of the column values expected
  1989. // is NULL or EMPTY
  1990. }
  1991. else
  1992. {
  1993. strQualifierName = Wmioledb_SysAllocString((WCHAR *)pColumnData->pbData);
  1994. //===============================================
  1995. // Get the qualifier Value
  1996. //===============================================
  1997. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERVALCOL));
  1998. VariantCopy(&varData,(VARIANT *)pColumnData->pbData);
  1999. //===============================================
  2000. // Get the qualifier flavor
  2001. //===============================================
  2002. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERFLAVOR));
  2003. lFlavor = pColumnData->pbData !=NULL ? *(LONG *)pColumnData->pbData : 0 ;
  2004. if( varData.vt != VT_EMPTY || varData.vt != VT_NULL)
  2005. {
  2006. //===============================================
  2007. // Set the qualifier
  2008. //===============================================
  2009. hr = m_pMap->SetQualifier(pInst,m_strPropertyName,strQualifierName,&varData,lFlavor);
  2010. }
  2011. else
  2012. {
  2013. //========================================================
  2014. // This is because one of the column values expected
  2015. //is NULL or EMPTY
  2016. //========================================================
  2017. hr = DB_E_INTEGRITYVIOLATION;
  2018. }
  2019. SysFreeString(strQualifierName);
  2020. VariantClear(&varData);
  2021. }
  2022. }
  2023. else
  2024. {
  2025. //====================================================
  2026. // Only qualifier value can be modified
  2027. //====================================================
  2028. hr = E_FAIL;
  2029. }
  2030. }
  2031. else
  2032. for (lIndex = 0; lIndex < cColumns; lIndex++)
  2033. {
  2034. icol = GetOrdinalFromColName(rgColumns[lIndex].columnid.uName.pwszName);
  2035. //=============================================================================
  2036. // If the column is not present in the rowset it is already updated in the
  2037. // row. This will happen only when this method is called from the row object
  2038. //=============================================================================
  2039. if( (DB_LORDINAL)icol < 0)
  2040. {
  2041. continue;
  2042. }
  2043. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(icol));
  2044. //=============================================================================
  2045. // If the columndata is modified then
  2046. //=============================================================================
  2047. if(pColumnData->dwStatus & COLUMNSTAT_MODIFIED)
  2048. {
  2049. bstrColName = Wmioledb_SysAllocString((OLECHAR *)m_Columns.ColumnName(icol));
  2050. dwCIMType = -1;
  2051. //===================================================================================
  2052. // if the type is array , then get the original CIMTYPE as array type will
  2053. // be given out as VT_ARRAY | VT_VARIANT
  2054. //===================================================================================
  2055. if(pColumnData->dwType & DBTYPE_ARRAY)
  2056. {
  2057. dwCIMType = m_Columns.GetCIMType(icol);
  2058. }
  2059. if( pColumnData->pbData == NULL)
  2060. {
  2061. varData.vt = VT_NULL;
  2062. }
  2063. else
  2064. {
  2065. //===================================================================================
  2066. // Call this function to convert the data to the appropriate datatype in a variant
  2067. //===================================================================================
  2068. dataMap.MapAndConvertOLEDBTypeToCIMType((USHORT)pColumnData->dwType,pColumnData->pbData,pColumnData->dwLength,varData,dwCIMType);
  2069. }
  2070. //================================
  2071. // Update the property
  2072. //================================
  2073. if( m_uRsType == 0)
  2074. {
  2075. //==================================
  2076. // Update the property
  2077. //==================================
  2078. hr = m_pMap->SetProperty(pInst,bstrColName,&varData);
  2079. }
  2080. pColumnData->dwStatus &= ~COLUMNSTAT_MODIFIED;
  2081. VariantClear(&varData);
  2082. SysFreeString(bstrColName);
  2083. }
  2084. }
  2085. //=============================================================================
  2086. // If everything is fine then update the instance
  2087. //=============================================================================
  2088. if( hr == S_OK)
  2089. {
  2090. hr = m_pMap->UpdateInstance(pInst , FALSE);
  2091. }
  2092. return hr;
  2093. }
  2094. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2095. // Function to delete a instance(Row) from WMI
  2096. // NTRaid : 143524
  2097. // 07/15/00
  2098. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2099. HRESULT CRowset::DeleteRow(HROW hRow,DBROWSTATUS * pRowStatus)
  2100. {
  2101. HRESULT hr = S_OK;
  2102. DBROWOPTIONS rgRowOptions[1];
  2103. ULONG rgRefCounts[1];
  2104. DBROWSTATUS rgRowStatus[1];
  2105. CWbemClassWrapper *pInst = NULL;
  2106. VARIANT varProp;
  2107. PROWBUFF pRowBuff = NULL;
  2108. COLUMNDATA * pColumnData = NULL;
  2109. VariantInit(&varProp);
  2110. memset(rgRowOptions,0,sizeof(DBROWOPTIONS));
  2111. memset(rgRowStatus,0,sizeof(DBROWSTATUS));
  2112. rgRefCounts[0] = 0;
  2113. if(pRowStatus != NULL)
  2114. *pRowStatus = DBROWSTATUS_S_OK;
  2115. //===================================================================
  2116. /// get the instance pointer corresponding to the HROW passed
  2117. // if rowset is referiing to a class and not to qualifiers then
  2118. //===================================================================
  2119. if(m_bIsChildRs == FALSE)
  2120. {
  2121. if( m_uRsType == PROPERTYQUALIFIER ||
  2122. m_uRsType == CLASSQUALIFIER )
  2123. {
  2124. pInst = m_pInstance;
  2125. }
  2126. else
  2127. if( m_uRsType != COLUMNSROWSET && m_uRsType != SCHEMA_ROWSET && m_uRsType != METHOD_ROWSET)
  2128. {
  2129. pInst = m_InstMgr->GetInstance(hRow);
  2130. }
  2131. }
  2132. //===================================================================
  2133. // if the recordset is a child rs and representing a qualifier
  2134. //===================================================================
  2135. else
  2136. {
  2137. //===================================================================
  2138. // get the instance pointer corresponding to the
  2139. //===================================================================
  2140. pInst = m_pChapterMgr->GetInstance(m_pChapterMgr->GetChapterForHRow(hRow));
  2141. }
  2142. // NTRaid:111800
  2143. // 06/07/00
  2144. // If the row is not an instance or qualifier
  2145. if(pInst == NULL)
  2146. {
  2147. hr = DB_E_NOTSUPPORTED;
  2148. }
  2149. else
  2150. // NTRaid : 143425
  2151. // 07/17/00
  2152. if( m_uRsType == PROPERTYQUALIFIER ||
  2153. m_uRsType == CLASSQUALIFIER )
  2154. {
  2155. // Delete qualifier
  2156. //=========================================
  2157. // Get the pointer to the row data
  2158. //=========================================
  2159. pRowBuff = GetRowBuff(hRow, TRUE );
  2160. //=============================================
  2161. // Get the Data for the qualifier name
  2162. //=============================================
  2163. pColumnData = (COLUMNDATA *) (((BYTE *)pRowBuff )+ m_Columns.GetDataOffset(QUALIFIERNAMECOL));
  2164. //================================================================================
  2165. // This will always of type VT_BSTR as this column represents the QUALIFER name
  2166. //================================================================================
  2167. if(pColumnData->dwType == VT_BSTR)
  2168. {
  2169. hr = m_pMap->DeleteQualifier(pInst,(BSTR)pColumnData->pbData,(m_uRsType == CLASSQUALIFIER),m_strPropertyName);
  2170. }
  2171. }
  2172. else
  2173. if( m_uRsType != COLUMNSROWSET && m_uRsType != SCHEMA_ROWSET && m_uRsType != METHOD_ROWSET)
  2174. {
  2175. //===================================
  2176. // Delete the Instance
  2177. //===================================
  2178. hr = m_pMap->DeleteInstance(pInst);
  2179. }
  2180. else
  2181. {
  2182. hr = WBEM_E_PROVIDER_NOT_CAPABLE;
  2183. }
  2184. //===================================================================
  2185. // If delete is not allowed if it is not capable of deletion then
  2186. // set the updatibility property of the rowset
  2187. //===================================================================
  2188. if( hr == WBEM_E_PROVIDER_NOT_CAPABLE)
  2189. {
  2190. GetRowsetProperty(DBPROP_UPDATABILITY,varProp);
  2191. varProp.lVal ^= DBPROPVAL_UP_DELETE;
  2192. SetRowsetProperty(DBPROP_UPDATABILITY,varProp);
  2193. hr = DB_E_NOTSUPPORTED;
  2194. if(pRowStatus)
  2195. {
  2196. *pRowStatus = DBROWSTATUS_E_INTEGRITYVIOLATION;
  2197. }
  2198. }
  2199. else
  2200. if(FAILED(hr) && (pRowStatus != NULL))
  2201. {
  2202. if(pRowStatus)
  2203. {
  2204. *pRowStatus = DBROWSTATUS_E_FAIL;
  2205. }
  2206. }
  2207. if( hr == S_OK)
  2208. {
  2209. //====================================
  2210. // Set the row status to DELETED
  2211. //====================================
  2212. SetRowStatus(hRow,DBROWSTATUS_E_DELETED);
  2213. if(pRowStatus)
  2214. {
  2215. *pRowStatus = DBROWSTATUS_S_OK;
  2216. }
  2217. }
  2218. return hr;
  2219. }
  2220. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2221. // Set the status of a row
  2222. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2223. void CRowset::SetRowStatus(HROW hRow , DBSTATUS dwStatus)
  2224. {
  2225. if(m_bIsChildRs == FALSE)
  2226. {
  2227. m_InstMgr->SetRowStatus(hRow , dwStatus);
  2228. }
  2229. else
  2230. {
  2231. m_pChapterMgr->SetRowStatus(hRow , dwStatus);
  2232. }
  2233. }
  2234. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2235. // Gets the current status of the row
  2236. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2237. DBSTATUS CRowset::GetRowStatus(HROW hRow )
  2238. {
  2239. DBSTATUS dwStatus = DBROWSTATUS_E_FAIL;
  2240. if(m_bIsChildRs == FALSE)
  2241. {
  2242. dwStatus = m_InstMgr->GetRowStatus(hRow);
  2243. }
  2244. else
  2245. {
  2246. dwStatus = m_pChapterMgr->GetRowStatus(hRow);
  2247. }
  2248. return dwStatus;
  2249. }
  2250. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2251. // Gets Key value of a instance
  2252. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2253. void CRowset::GetInstanceKey(HROW hRow , BSTR *strKey)
  2254. {
  2255. CWbemClassWrapper *pInst = NULL;
  2256. //====================================
  2257. // get the pointer to the instance
  2258. //====================================
  2259. if(m_bIsChildRs == FALSE)
  2260. {
  2261. pInst = m_InstMgr->GetInstance(hRow);
  2262. m_InstMgr->GetInstanceKey(hRow,strKey);
  2263. }
  2264. else
  2265. {
  2266. pInst = m_pChapterMgr->GetInstance(m_pChapterMgr->GetChapterForHRow(hRow));
  2267. m_pChapterMgr->GetInstanceKey(hRow,strKey);
  2268. }
  2269. }
  2270. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2271. // Set the status of a rowset or a chapter
  2272. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2273. void CRowset::SetStatus(HCHAPTER hChapter , DWORD dwStatus)
  2274. {
  2275. if(m_bIsChildRs == FALSE)
  2276. {
  2277. //================================
  2278. // skip caused END_OF_ROWSET
  2279. //================================
  2280. m_dwStatus |= dwStatus;
  2281. }
  2282. else
  2283. {
  2284. //========================================================================
  2285. // set the status of the chapter to end of rowset
  2286. //========================================================================
  2287. m_pChapterMgr->SetChapterStatus(hChapter , dwStatus);
  2288. }
  2289. }
  2290. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2291. // Gets the status of a rowset or a chapter
  2292. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2293. DBSTATUS CRowset::GetStatus(HCHAPTER hChapter)
  2294. {
  2295. DBSTATUS dwStatus = 0;
  2296. if(m_bIsChildRs == FALSE)
  2297. {
  2298. //================================
  2299. // skip caused END_OF_ROWSET
  2300. //================================
  2301. dwStatus = m_dwStatus;
  2302. }
  2303. else
  2304. {
  2305. //========================================================================
  2306. // set the status of the chapter to end of rowset
  2307. //========================================================================
  2308. dwStatus = m_pChapterMgr->GetChapterStatus(hChapter );
  2309. }
  2310. return dwStatus;
  2311. }
  2312. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2313. // Adds a new instance to the class
  2314. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2315. HRESULT CRowset::InsertNewRow(CWbemClassWrapper **ppNewInst)
  2316. {
  2317. HRESULT hr = S_OK;
  2318. switch(m_uRsType)
  2319. {
  2320. case PROPERTYQUALIFIER:
  2321. break;
  2322. case CLASSQUALIFIER:
  2323. break;
  2324. case SCHEMA_ROWSET:
  2325. hr = DB_E_NOTSUPPORTED;
  2326. break;
  2327. case 0:
  2328. hr = m_pMap->AddNewInstance(ppNewInst);
  2329. break;
  2330. default:
  2331. hr = E_FAIL;
  2332. }
  2333. return hr;
  2334. }
  2335. ///////////////////////////////////////////////////////////////////////////////////////
  2336. // Function which releases the rowdata ( does not release the row)
  2337. // release the memory allocated for the row and also the slot allocated for the row
  2338. ///////////////////////////////////////////////////////////////////////////////////////
  2339. HRESULT CRowset::ReleaseRowData(HROW hRow,BOOL bReleaseSlot)
  2340. {
  2341. HSLOT hSlot = 0;
  2342. HRESULT hr = S_OK;
  2343. //===================================================================
  2344. /// get the handle to slot
  2345. //===================================================================
  2346. if(m_bIsChildRs == FALSE)
  2347. {
  2348. //===================================================================
  2349. // get the handle to slot for the instance
  2350. //===================================================================
  2351. hSlot = m_InstMgr->GetSlot(hRow);
  2352. if(bReleaseSlot)
  2353. {
  2354. // Reset the HSLOT in the chapter Manager
  2355. m_InstMgr->SetSlot(hRow , -1);
  2356. }
  2357. }
  2358. //===================================================================
  2359. // if the recordset is a child rs and representing a qualifier
  2360. //===================================================================
  2361. else
  2362. {
  2363. //===================================================================
  2364. // get the handle to slot for the instance
  2365. //===================================================================
  2366. hSlot = m_pChapterMgr->GetSlot(hRow);
  2367. //================================================
  2368. // Reset the HSLOT in the chapter Manager
  2369. //================================================
  2370. if(bReleaseSlot)
  2371. {
  2372. m_pChapterMgr->SetSlot(hRow ,-1);
  2373. }
  2374. }
  2375. if( hSlot > 0)
  2376. {
  2377. if (FAILED( Rebind((BYTE *) GetRowBuffFromSlot( hSlot, TRUE ))))
  2378. {
  2379. hr = E_FAIL ;
  2380. }
  2381. else
  2382. {
  2383. //===========================================================
  2384. // release the memory allocated for the different columns
  2385. //===========================================================
  2386. m_pRowData->ReleaseRowData();
  2387. //==============================
  2388. // release the slots
  2389. //==============================
  2390. if(bReleaseSlot)
  2391. {
  2392. ReleaseSlots( m_pIBuffer, hSlot, 1 );
  2393. }
  2394. }
  2395. }
  2396. return hr;
  2397. }
  2398. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2399. // Virtual Overidden function which is called from IColumnInfo to get the column information
  2400. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2401. HRESULT CRowset::GetColumnInfo(DBORDINAL* pcColumns, DBCOLUMNINFO** prgInfo,WCHAR** ppStringsBuffer)
  2402. {
  2403. ULONG icol = 0;
  2404. DBCOLUMNINFO* rgdbcolinfo = NULL;
  2405. WCHAR* pstrBuffer = NULL;
  2406. WCHAR* pstrBufferForColInfo = NULL;
  2407. HRESULT hr = S_OK;
  2408. DBCOUNTITEM nTotalCols = m_cTotalCols;
  2409. BOOL bFlag = TRUE;
  2410. if(!(m_ulProps & BOOKMARKPROP))
  2411. {
  2412. nTotalCols--;
  2413. bFlag = FALSE;
  2414. }
  2415. //=======================================
  2416. // Copy the columninformation
  2417. //=======================================
  2418. if(SUCCEEDED(hr = m_Columns.CopyColumnInfoList(rgdbcolinfo,bFlag)))
  2419. {
  2420. //===========================================
  2421. // Copy the heap for column names.
  2422. //===========================================
  2423. if ( m_Columns.ColumnNameListStartingPoint() != NULL){
  2424. ptrdiff_t dp;
  2425. hr = m_Columns.CopyColumnNamesList(pstrBuffer);
  2426. dp = (LONG_PTR) pstrBuffer - (LONG_PTR) (m_Columns.ColumnNameListStartingPoint());
  2427. dp >>= 1;
  2428. //===========================================
  2429. // Loop through columns and adjust pointers
  2430. // to column names.
  2431. //===========================================
  2432. for ( icol =0; icol < nTotalCols; icol++ )
  2433. {
  2434. if ( rgdbcolinfo[icol].pwszName )
  2435. {
  2436. rgdbcolinfo[icol].pwszName += dp;
  2437. }
  2438. }
  2439. }
  2440. //==============================
  2441. // Set the output parameters
  2442. //==============================
  2443. *prgInfo = &rgdbcolinfo[0];
  2444. *ppStringsBuffer = pstrBuffer;
  2445. *pcColumns = nTotalCols;
  2446. }
  2447. return hr;
  2448. }
  2449. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2450. // get the instance pointer of a particular row
  2451. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2452. CWbemClassWrapper *CRowset::GetInstancePtr(HROW hRow)
  2453. {
  2454. CWbemClassWrapper *pInst = NULL;
  2455. if(m_bIsChildRs == FALSE)
  2456. {
  2457. pInst = m_InstMgr->GetInstance(hRow);
  2458. }
  2459. else
  2460. {
  2461. pInst = m_pChapterMgr->GetInstance(m_pChapterMgr->GetChapterForHRow(hRow));
  2462. }
  2463. return pInst;
  2464. }
  2465. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2466. // Get the qualifier name which will be present in the first column for
  2467. // qualifier rowset
  2468. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2469. void CRowset::GetQualiferName(HROW hRow,BSTR &strBookMark)
  2470. {
  2471. PROWBUFF pRowBuff = NULL;
  2472. PCOLUMNDATA pColumnData = NULL;
  2473. pRowBuff = GetRowBuff( (ULONG) hRow, TRUE );
  2474. pColumnData = (COLUMNDATA *) ((BYTE *) pRowBuff + m_Columns.GetDataOffset(0));
  2475. //===================================================================
  2476. // FIXXX More work is to be done on this
  2477. //===================================================================
  2478. if( pColumnData->dwType == DBTYPE_BSTR )
  2479. strBookMark = Wmioledb_SysAllocString((WCHAR *)(pColumnData->pbData));
  2480. }
  2481. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2482. // Generate a new HCHAPTER for the current row and add it to the CHAPTER manager
  2483. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2484. HRESULT CRowset::FillHChaptersForRow(CWbemClassWrapper *pInst, BSTR strKey)
  2485. {
  2486. HRESULT hr = S_OK;
  2487. ULONG nIndex = 0;
  2488. PCOLUMNDATA * pColumnData = NULL;
  2489. CVARIANT var;
  2490. HCHAPTER hChapter = 0;
  2491. //============================================================================
  2492. // if there are nested columns in the rowset
  2493. //============================================================================
  2494. if(m_cNestedCols > 0)
  2495. {
  2496. for ( ULONG nIndex = 0 ; nIndex < m_cTotalCols ; nIndex++)
  2497. {
  2498. //============================================================================
  2499. // if the columntype is of CHAPTER then allocate a rowset and initialize
  2500. //============================================================================
  2501. if(m_Columns.ColumnFlags(nIndex) & DBCOLUMNFLAGS_ISCHAPTER )
  2502. {
  2503. hChapter = GetNextHChapter();
  2504. var.SetLONG((LONG)hChapter);
  2505. if(FAILED(hr = m_pRowData->CommitColumnToRowData(var,nIndex,VT_UI4)))
  2506. {
  2507. break;
  2508. }
  2509. //============================================================================
  2510. // Add the chapter to the corresponding child recordset
  2511. //============================================================================
  2512. m_ppChildRowsets[nIndex]->m_pChapterMgr->AddChapter(hChapter);
  2513. m_ppChildRowsets[nIndex]->m_pChapterMgr->SetInstance(hChapter,pInst,strKey);
  2514. } // if for columntype
  2515. } // for
  2516. }
  2517. return hr;
  2518. }
  2519. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2520. // Function to add reference to a chapter
  2521. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2522. HRESULT CRowset::AddRefChapter(HCHAPTER hChapter,DBREFCOUNT * pcRefCount)
  2523. {
  2524. HRESULT hr = E_UNEXPECTED;
  2525. ULONG ulRet = -1;
  2526. //===========================================
  2527. // if the rowset is a child rowset
  2528. //===========================================
  2529. if(m_bIsChildRs == TRUE)
  2530. {
  2531. //=======================================
  2532. // If chapter belongs to the rowset
  2533. //=======================================
  2534. if(m_pChapterMgr->IsExists(hChapter) == FALSE)
  2535. {
  2536. hr = DB_E_BADCHAPTER;
  2537. }
  2538. else
  2539. {
  2540. //===================================
  2541. // Add reference to the chapter
  2542. //===================================
  2543. ulRet = m_pChapterMgr->AddRefChapter(hChapter);
  2544. if( ulRet > 0)
  2545. {
  2546. hr = S_OK;
  2547. }
  2548. }
  2549. }
  2550. if(pcRefCount != NULL)
  2551. {
  2552. *pcRefCount = ulRet;
  2553. }
  2554. return hr;
  2555. }
  2556. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2557. // Function to release reference to a chapter
  2558. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2559. HRESULT CRowset::ReleaseRefChapter(HCHAPTER hChapter , ULONG * pcRefCount)
  2560. {
  2561. HRESULT hr = E_UNEXPECTED;
  2562. ULONG ulRet = -1;
  2563. //=======================================
  2564. // if the rowset is a child rowset
  2565. //=======================================
  2566. if(m_bIsChildRs == TRUE)
  2567. {
  2568. //===================================
  2569. // If chapter belongs to the rowset
  2570. //===================================
  2571. if(m_pChapterMgr->IsExists(hChapter) == FALSE)
  2572. {
  2573. hr = DB_E_BADCHAPTER;
  2574. }
  2575. else
  2576. {
  2577. //======================================
  2578. // Release reference to the chapter
  2579. //======================================
  2580. ulRet = m_pChapterMgr->ReleaseRefChapter(hChapter);
  2581. if(((LONG)ulRet) >= 0)
  2582. {
  2583. hr = S_OK;
  2584. }
  2585. }
  2586. }
  2587. if(pcRefCount != NULL)
  2588. {
  2589. *pcRefCount = ulRet;
  2590. }
  2591. return hr;
  2592. }
  2593. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2594. // Get the number of rows in the rowset
  2595. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2596. HRESULT CRowset::GetRowCount()
  2597. {
  2598. HRESULT hr = S_OK;
  2599. switch(m_uRsType)
  2600. {
  2601. case PROPERTYQUALIFIER:
  2602. m_lRowCount = -1;
  2603. break;
  2604. case CLASSQUALIFIER:
  2605. m_lRowCount = -1;
  2606. break;
  2607. case SCHEMA_ROWSET:
  2608. m_lRowCount = -1;
  2609. break;
  2610. case 0:
  2611. case COMMAND_ROWSET:
  2612. hr = m_pMap->GetInstanceCount(m_lRowCount);
  2613. break;
  2614. default:
  2615. hr = E_FAIL;
  2616. }
  2617. return hr;
  2618. }
  2619. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2620. // Get the Data to local buffer for a particular row
  2621. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2622. HRESULT CRowset::GetDataToLocalBuffer(HROW hRow)
  2623. {
  2624. HSLOT hSlot = 0;
  2625. HRESULT hr = S_OK;
  2626. BSTR strBookMark = Wmioledb_SysAllocString(NULL);
  2627. if(m_uRsType == PROPERTYQUALIFIER ||
  2628. m_uRsType == CLASSQUALIFIER )
  2629. {
  2630. GetQualiferName(hRow,strBookMark);
  2631. }
  2632. hSlot = GetSlotForRow(hRow);
  2633. if (FAILED( Rebind((BYTE *) GetRowBuffFromSlot( hSlot, TRUE ))))
  2634. {
  2635. hr = E_FAIL;
  2636. }
  2637. else
  2638. {
  2639. //======================================
  2640. // Release the previous row data
  2641. //======================================
  2642. m_pRowData->ReleaseRowData();
  2643. //======================================
  2644. // Get the data for the current row
  2645. //======================================
  2646. if(SUCCEEDED(hr = GetData(hRow,strBookMark)))
  2647. {
  2648. m_ulLastFetchedRow = hRow;
  2649. }
  2650. if( strBookMark != NULL)
  2651. {
  2652. SysFreeString(strBookMark);
  2653. }
  2654. }
  2655. return hr;
  2656. }
  2657. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2658. // Check if a particular instance is deleted.
  2659. // A particular instance is deleted , if it is deleted from WMI and appropriate properties are
  2660. // set for different cursor types
  2661. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2662. BOOL CRowset::IsInstanceDeleted(CWbemClassWrapper *pInst)
  2663. {
  2664. DWORD dwStatus = m_pMap->GetInstanceStatus(pInst);
  2665. BOOL bRet = FALSE;
  2666. //===================================
  2667. // if the cursor is dynamic
  2668. //===================================
  2669. if((m_ulProps & OTHERINSERT) && dwStatus != DBSTATUS_S_OK)
  2670. {
  2671. bRet = TRUE;
  2672. }
  2673. else
  2674. if(((m_ulProps & OWNUPDATEDELETE) && dwStatus == DBROWSTATUS_E_DELETED) ||
  2675. ((m_ulProps & OTHERUPDATEDELETE) && dwStatus == DBSTATUS_E_UNAVAILABLE))
  2676. {
  2677. bRet = TRUE;
  2678. }
  2679. return bRet;
  2680. }
  2681. void CRowset::SetCurFetchDirection(FETCHDIRECTION FetchDir)
  2682. {
  2683. m_FetchDir = FetchDir;
  2684. m_pMap->SetCurFetchDirection(FetchDir);
  2685. }