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.

762 lines
25 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. //
  7. // CDBSession object implementation
  8. //
  9. // NTRaid:: 139685 Transaction support removed
  10. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. #include "headers.h"
  12. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Constructor for this class
  15. //
  16. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. CDBSession::CDBSession( LPUNKNOWN pUnkOuter ) : CBaseObj(BOT_SESSION, pUnkOuter)
  18. {
  19. //==========================================================================
  20. // Initialize simple member vars
  21. //==========================================================================
  22. m_nOpenedRowset = 0;
  23. m_bTxnStarted = FALSE;
  24. //==========================================================================
  25. // Initially, NULL all contained interfaces
  26. //==========================================================================
  27. m_pIGetDataSource = NULL;
  28. m_pIOpenRowset = NULL;
  29. m_pISchemaRowset = NULL;
  30. m_pIDBCreateCommand = NULL;
  31. m_pISessionProperties = NULL;
  32. m_pUtilProp = NULL;
  33. m_pITableDefinition = NULL;
  34. m_pISessionCache = NULL;
  35. m_pIBindResource = NULL;
  36. m_pIIndexDefinition = NULL;
  37. m_pIAlterTable = NULL;
  38. m_pISupportErrorInfo = NULL;
  39. m_pITransLocal = NULL;
  40. //==========================================================================
  41. // Pointer to parent object
  42. //==========================================================================
  43. m_pCDataSource = NULL;
  44. memset(&m_TxnGuid , 0 , sizeof(XACTUOW));
  45. //==========================================================================
  46. // Increment global object count.
  47. //==========================================================================
  48. InterlockedIncrement(&g_cObj);
  49. }
  50. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. //
  52. // Destructor for this class
  53. //
  54. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. CDBSession:: ~CDBSession ( void )
  56. {
  57. //===========================================================================
  58. // Free properties management object
  59. //===========================================================================
  60. SAFE_DELETE_PTR( m_pUtilProp );
  61. //===========================================================================
  62. // Free contained interfaces
  63. //===========================================================================
  64. SAFE_DELETE_PTR( m_pIGetDataSource );
  65. SAFE_DELETE_PTR( m_pIOpenRowset );
  66. SAFE_DELETE_PTR( m_pISchemaRowset );
  67. SAFE_DELETE_PTR( m_pIDBCreateCommand );
  68. SAFE_DELETE_PTR( m_pISessionProperties );
  69. SAFE_DELETE_PTR( m_pITableDefinition );
  70. SAFE_DELETE_PTR(m_pIBindResource);
  71. SAFE_DELETE_PTR(m_pIIndexDefinition);
  72. SAFE_DELETE_PTR(m_pIAlterTable);
  73. SAFE_DELETE_PTR(m_pISupportErrorInfo);
  74. // SAFE_DELETE_PTR(m_pITransLocal);
  75. m_pCDataSource->RemoveSession();
  76. m_pCDataSource->GetOuterUnknown()->Release();
  77. //===========================================================================
  78. // Decrement global object count.
  79. //===========================================================================
  80. InterlockedDecrement(&g_cObj);
  81. }
  82. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  83. //
  84. // Initialize the command Object
  85. //
  86. // Did the Initialization Succeed
  87. // TRUE Initialization succeeded
  88. // FALSE Initialization failed
  89. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  90. HRESULT CDBSession::FInit ( CDataSource *pCDataSource )
  91. {
  92. HRESULT hr = E_OUTOFMEMORY;
  93. //===========================================================================
  94. // Establish parent object pointer
  95. //===========================================================================
  96. assert( pCDataSource );
  97. m_pCDataSource = pCDataSource;
  98. m_pCDataSource->GetOuterUnknown()->AddRef();
  99. //===========================================================================
  100. // Allocate properties management object
  101. //===========================================================================
  102. m_pUtilProp = new CUtilProp;
  103. // NTRaid: 136443
  104. // 07/05/00
  105. if(m_pUtilProp == NULL)
  106. {
  107. hr = E_OUTOFMEMORY;
  108. }
  109. else
  110. if(SUCCEEDED(hr = m_pUtilProp->FInit(SESSIONPROP)))
  111. {
  112. //===========================================================================
  113. // Allocate contained interface objects
  114. //===========================================================================
  115. m_pIGetDataSource = new CImpIGetDataSource( this );
  116. m_pIOpenRowset = new CImpIOpenRowset( this );
  117. m_pISchemaRowset = new CImpIDBSchemaRowset( this );
  118. m_pIDBCreateCommand = new CImpIDBCreateCommand( this );
  119. m_pISessionProperties = new CImpISessionProperties( this );
  120. m_pITableDefinition = new CImpITableDefinition( this );
  121. m_pIBindResource = new CImplIBindRsrc( this );
  122. m_pIIndexDefinition = new CImplIIndexDefinition( this );
  123. m_pIAlterTable = new CImplIAlterTable( this );
  124. m_pISupportErrorInfo = new CImpISupportErrorInfo(this);
  125. // Removing transaction support as per alanbos mail ( core is removing the support)
  126. // 06/30/2000
  127. // m_pITransLocal = new CImpITransactionLocal(this);
  128. if( m_pIGetDataSource && m_pIOpenRowset && m_pIDBCreateCommand && m_pISchemaRowset && m_pISessionProperties &&
  129. m_pITableDefinition && m_pIBindResource && m_pIIndexDefinition && m_pIAlterTable) // && m_pITransLocal)
  130. {
  131. hr = S_OK;
  132. }
  133. else
  134. {
  135. hr = E_OUTOFMEMORY;
  136. }
  137. }
  138. if(SUCCEEDED(hr))
  139. {
  140. hr = AddInterfacesForISupportErrorInfo();
  141. }
  142. return hr;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////////////////////////////
  145. // Function to add interfaces to ISupportErrorInfo interface
  146. /////////////////////////////////////////////////////////////////////////////////////////////////////
  147. HRESULT CDBSession::AddInterfacesForISupportErrorInfo()
  148. {
  149. HRESULT hr = S_OK;
  150. if( SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IGetDataSource)) &&
  151. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IOpenRowset)) &&
  152. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IDBSchemaRowset)) &&
  153. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_ISessionProperties)) &&
  154. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_ITableDefinition)) &&
  155. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IBindResource)) &&
  156. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IDBCreateCommand)) &&
  157. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_IIndexDefinition)) &&
  158. SUCCEEDED(hr = m_pISupportErrorInfo->AddInterfaceID(IID_ITransactionLocal)))
  159. {
  160. hr = m_pISupportErrorInfo->AddInterfaceID(IID_IAlterTable);
  161. }
  162. return hr;
  163. }
  164. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  165. //
  166. // Returns a pointer to a specified interface. Callers use QueryInterface to determine which interfaces
  167. // the called object supports.
  168. //
  169. // HRESULT indicating the status of the method
  170. // S_OK Interface is supported and ppvObject is set.
  171. // E_NOINTERFACE Interface is not supported by the object
  172. // E_INVALIDARG One or more arguments are invalid.
  173. //
  174. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  175. STDMETHODIMP CDBSession::QueryInterface ( REFIID riid, // IN | Interface ID of the interface being queried for.
  176. LPVOID * ppv ) // OUT | Pointer to interface that was instantiated
  177. {
  178. HRESULT hr = E_INVALIDARG;
  179. if(CheckIfValidDataSrc() == FALSE)
  180. return g_pCError->PostHResult(hr,&IID_IUnknown);
  181. //============================================================================
  182. // Is the pointer bad?
  183. //============================================================================
  184. if (ppv != NULL){
  185. //========================================================================
  186. // Place NULL in *ppv in case of failure
  187. //========================================================================
  188. *ppv = NULL;
  189. //========================================================================
  190. // This is the non-delegating IUnknown implementation
  191. //========================================================================
  192. if (riid == IID_IUnknown)
  193. *ppv = (LPVOID) this;
  194. else if (riid == IID_IGetDataSource)
  195. *ppv = (LPVOID) m_pIGetDataSource;
  196. else if (riid == IID_IOpenRowset)
  197. *ppv = (LPVOID) m_pIOpenRowset;
  198. else if (riid == IID_IDBSchemaRowset)
  199. *ppv = (LPVOID) m_pISchemaRowset;
  200. else if (riid == IID_ISessionProperties)
  201. *ppv = (LPVOID) m_pISessionProperties;
  202. else if (riid == IID_ITableDefinition)
  203. *ppv = (LPVOID) m_pITableDefinition;
  204. else if (riid == IID_IBindResource)
  205. *ppv = (LPVOID) m_pIBindResource;
  206. else if ( riid == IID_IDBCreateCommand )
  207. *ppv = (LPVOID)m_pIDBCreateCommand;
  208. else if ( riid == IID_IIndexDefinition)
  209. *ppv = (LPVOID)m_pIIndexDefinition;
  210. else if ( riid == IID_IAlterTable)
  211. *ppv = (LPVOID)m_pIAlterTable;
  212. // Removing transaction support as per alanbos mail ( core is removing the support)
  213. // 06/30/2000
  214. // else if ( riid == IID_ITransactionLocal || riid == IID_ITransaction)
  215. // *ppv = (LPVOID)m_pITransLocal;
  216. else if ( riid == IID_ISupportErrorInfo)
  217. *ppv = (LPVOID)m_pISupportErrorInfo;
  218. //========================================================================
  219. // If we're going to return an interface, AddRef it first
  220. //========================================================================
  221. if (*ppv){
  222. ((LPUNKNOWN) *ppv)->AddRef();
  223. hr = S_OK;
  224. }
  225. else{
  226. hr = E_NOINTERFACE;
  227. }
  228. }
  229. return hr;
  230. }
  231. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  232. //
  233. // Increments a persistence count for the object
  234. //
  235. // Current reference count
  236. //
  237. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  238. STDMETHODIMP_( ULONG ) CDBSession::AddRef ( void )
  239. {
  240. return InterlockedIncrement((long *)&m_cRef);
  241. }
  242. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  243. //
  244. // Decrements a persistence count for the object and if persistence count is 0, the object destroys itself.
  245. //
  246. // Current reference count
  247. //
  248. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  249. STDMETHODIMP_( ULONG ) CDBSession::Release ( void )
  250. {
  251. if (!InterlockedDecrement((long *)&m_cRef)){
  252. delete this;
  253. return 0;
  254. }
  255. return m_cRef;
  256. }
  257. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  258. //
  259. // Gets a particular datasource property
  260. //
  261. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  262. HRESULT CDBSession::GetDataSrcProperty(DBPROPID propId , VARIANT & varValue)
  263. {
  264. return m_pCDataSource->GetDataSrcProperty(propId,varValue);
  265. }
  266. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  267. //
  268. // Creates a new command called by IBindResource implementation of the session
  269. //
  270. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  271. HRESULT CDBSession::CreateCommand(IUnknown *pUnkOuter, REFGUID riid,IUnknown ** ppCommand)
  272. {
  273. HRESULT hr = S_OK;
  274. CCommand* pcmd = NULL;
  275. if(CheckIfValidDataSrc() == FALSE)
  276. {
  277. hr = E_INVALIDARG;
  278. }
  279. else
  280. {
  281. //=========================================================================
  282. // Initialize output param
  283. //=========================================================================
  284. if (ppCommand)
  285. {
  286. *ppCommand = NULL;
  287. }
  288. //=========================================================================
  289. // Check Function Arguments
  290. //=========================================================================
  291. if( ppCommand == NULL )
  292. {
  293. hr = E_INVALIDARG;
  294. }
  295. else
  296. //=========================================================================
  297. // The outer object must explicitly ask for IUnknown
  298. //=========================================================================
  299. if (pUnkOuter != NULL && riid != IID_IUnknown)
  300. {
  301. hr = DB_E_NOAGGREGATION;
  302. }
  303. else
  304. {
  305. try
  306. {
  307. //=========================================================================
  308. // This is the outer unknown from the user, for the new Command,
  309. // not to be confused with the outer unknown of this DBSession object.
  310. //=========================================================================
  311. pcmd = new CCommand(this, pUnkOuter);
  312. }
  313. catch(...)
  314. {
  315. SAFE_DELETE_PTR(pcmd);
  316. throw;
  317. }
  318. if (pcmd)
  319. {
  320. /* //=====================================================================
  321. // Need to increment usage count since passed out to CCommand
  322. //=====================================================================
  323. m_pCDBSession->AddRef();
  324. */
  325. //=====================================================================
  326. // Initialize the command
  327. //=====================================================================
  328. hr = pcmd->FInit();
  329. if( SUCCEEDED(hr) )
  330. {
  331. hr = pcmd->QueryInterface( riid, (void **) ppCommand );
  332. if( SUCCEEDED(hr) )
  333. {
  334. // If everything is fine then set the datasource persist info to dirty
  335. m_pCDataSource->SetPersistDirty();
  336. }
  337. //=================================================================
  338. // Need to drop through on error, so command object is destroyed
  339. //=================================================================
  340. }
  341. else
  342. {
  343. SAFE_DELETE_PTR(pcmd);
  344. }
  345. }
  346. else
  347. {
  348. //=====================================================================
  349. // Since Ctor failed, it cannot know to Release pUnkOuter,
  350. // so we must do it here since we are owner.
  351. //=====================================================================
  352. if (pUnkOuter)
  353. {
  354. pUnkOuter->Release();
  355. }
  356. hr = E_OUTOFMEMORY;
  357. }
  358. } // else for NOAGGREGATION
  359. } // else for INVALID_ARG
  360. return hr;
  361. }
  362. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  363. //
  364. // Creates a new Row called by IBindResource implementation of the session
  365. //
  366. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  367. HRESULT CDBSession::CreateRow(IUnknown *pUnkOuter, WCHAR *pstrURL,REFGUID guidTemp,IUnknown ** ppUnk)
  368. {
  369. HRESULT hr = E_FAIL;
  370. CRow * pNewRow = NULL;
  371. DBPROPSET * pPropSet = NULL;
  372. BSTR strTable;
  373. BSTR strPath;
  374. CURLParser urlParser;
  375. strPath = Wmioledb_SysAllocString(pstrURL);
  376. // Modified on 06/09/00
  377. // Bug while getting a row from ADO Row object
  378. // urlParser.SetPath(strPath);
  379. urlParser.SetURL(strPath);
  380. SysFreeString(strPath);
  381. if(CheckIfValidDataSrc() == FALSE)
  382. {
  383. hr = E_INVALIDARG;
  384. }
  385. else
  386. {
  387. //===================================
  388. // Get the path of the object
  389. //===================================
  390. if(SUCCEEDED(hr = urlParser.GetPathWithEmbededInstInfo(strPath)))
  391. {
  392. //===================================
  393. // Get the class name
  394. //===================================
  395. // NTRaid:134967
  396. // 07/11/2000
  397. if(SUCCEEDED(hr) && SUCCEEDED(hr = m_pCDataSource->GetConnectionInitProperties(&pPropSet)))
  398. {
  399. hr = GetClassName(&urlParser,pPropSet,strTable,m_pCDataSource->m_pWbemWrap);
  400. //==========================================================================
  401. // Free memory we allocated to get the namespace property above
  402. //==========================================================================
  403. CPropertyMemoryMgr::FreeDBPROPSET( 1, pPropSet);
  404. }
  405. try
  406. {
  407. pNewRow = new CRow(pUnkOuter,this);
  408. }
  409. catch(...)
  410. {
  411. SAFE_DELETE_PTR(pNewRow);
  412. throw;
  413. }
  414. if(SUCCEEDED(hr) && SUCCEEDED(hr = pNewRow->InitRow(strPath,strTable)))
  415. {
  416. hr = pNewRow->QueryInterface(guidTemp,(void **)ppUnk);
  417. }
  418. //=====================================================
  419. // Free the strings allocated by the URLParser class
  420. //=====================================================
  421. SysFreeString(strTable);
  422. SysFreeString(strPath);
  423. if(FAILED(hr))
  424. {
  425. SAFE_DELETE_PTR(pNewRow);
  426. *ppUnk = NULL;
  427. }
  428. }
  429. } // INVALIDARG
  430. return hr;
  431. }
  432. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  433. //
  434. // Creates a new Rowset called by IBindResource implementation of the session
  435. //
  436. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  437. HRESULT CDBSession::CreateRowset(IUnknown *pUnkOuter, WCHAR *pstrURL, REFGUID guidTemp,IUnknown ** ppUnk)
  438. {
  439. HRESULT hr = E_FAIL;
  440. ULONG cPropSets = 0;
  441. DBPROPSET* prgPropertySets = NULL;
  442. BSTR strTableName = NULL;
  443. CURLParser urlParser;
  444. DBPROPSET * pPropSet = NULL;
  445. {
  446. CBSTR strTemp;
  447. strTemp.SetStr(pstrURL);
  448. urlParser.SetURL(pstrURL);
  449. }
  450. if(CheckIfValidDataSrc() == FALSE)
  451. {
  452. hr =E_INVALIDARG;
  453. }
  454. else
  455. {
  456. DBPROPIDSET rgPropIDSet[1];
  457. rgPropIDSet[0].cPropertyIDs = 0;
  458. rgPropIDSet[0].guidPropertySet = DBPROPSET_ROWSET;
  459. //===============================
  460. // Get the properties
  461. //===============================
  462. if(SUCCEEDED(hr = m_pUtilProp->GetProperties(PROPSET_ROWSET,0,rgPropIDSet, &cPropSets,&prgPropertySets)))
  463. {
  464. //====================================================
  465. // Get the class name and initialize the tableID
  466. //====================================================
  467. // NTRaid:134967
  468. // 07/11/2000
  469. if( SUCCEEDED(hr = m_pCDataSource->GetConnectionInitProperties(&pPropSet)) )
  470. {
  471. hr = GetClassName(&urlParser,pPropSet,strTableName,m_pCDataSource->m_pWbemWrap);
  472. if (SUCCEEDED(hr))
  473. {
  474. DBID tableID;
  475. memset(&tableID , 0 , sizeof(DBID));
  476. tableID.eKind = DBKIND_NAME;
  477. tableID.uName.pwszName = strTableName;
  478. //===============================
  479. // Open the rowset
  480. //===============================
  481. hr = m_pIOpenRowset->OpenRowset(pUnkOuter,&tableID,NULL,guidTemp,cPropSets,prgPropertySets,ppUnk);
  482. SAFE_FREE_SYSSTRING(strTableName);
  483. }
  484. //==========================================================================
  485. // Free memory we allocated to get the namespace property above
  486. //==========================================================================
  487. CPropertyMemoryMgr::FreeDBPROPSET( 1, pPropSet);
  488. }
  489. //==========================================================================
  490. // Free memory we allocated to by GetProperties
  491. //==========================================================================
  492. m_pUtilProp->m_PropMemMgr.FreeDBPROPSET( cPropSets, prgPropertySets);
  493. }
  494. }
  495. return hr;
  496. }
  497. BOOL CDBSession::CheckIfValidDataSrc()
  498. {
  499. if(m_pCDataSource != NULL && m_pCDataSource->m_fDSOInitialized == TRUE)
  500. return TRUE;
  501. return FALSE;
  502. }
  503. HRESULT CDBSession::GenerateNewUOW(GUID &guidTrans)
  504. {
  505. HRESULT hr = S_OK;
  506. assert (sizeof(XACTUOW) == sizeof(GUID));
  507. if(SUCCEEDED(hr = CoCreateGuid(&guidTrans)))
  508. {
  509. memcpy(&m_TxnGuid.rgb,&guidTrans,sizeof(GUID));
  510. }
  511. return hr;
  512. }
  513. void CDBSession::AddRowset(CBaseRowObj * pRowset)
  514. {
  515. m_nOpenedRowset++;
  516. m_OpenedRowsets.Add(pRowset);
  517. }
  518. void CDBSession::RemoveRowset(CBaseRowObj * pRowset)
  519. {
  520. m_nOpenedRowset--;
  521. for( int i = 0 ; i < m_OpenedRowsets.Size(); i++)
  522. {
  523. if(pRowset == (CBaseRowObj *) m_OpenedRowsets.GetAt(i))
  524. {
  525. m_OpenedRowsets.RemoveAt(i);
  526. break;
  527. }
  528. }
  529. m_OpenedRowsets.Add(pRowset);
  530. }
  531. void CDBSession::SetAllOpenRowsetToZoombieState()
  532. {
  533. CBaseRowObj * pRowObj = NULL;
  534. m_nOpenedRowset--;
  535. for( int i = 0 ; i < m_OpenedRowsets.Size(); i++)
  536. {
  537. pRowObj = (CBaseRowObj *) m_OpenedRowsets.GetAt(i);
  538. if(pRowObj != NULL)
  539. {
  540. pRowObj->SetStatusToZoombie();
  541. }
  542. pRowObj = NULL;
  543. }
  544. }
  545. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  546. //
  547. // Retrieve an interface pointer on the session object
  548. //
  549. //
  550. // S_OK Session Object Interface returned
  551. // E_INVALIDARG ppDataSource was NULL
  552. // E_NOINTERFACE IID not supported
  553. //
  554. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  555. STDMETHODIMP CImpIGetDataSource::GetDataSource( REFIID riid, // IN IID desired
  556. IUnknown** ppDataSource // OUT ptr to interface
  557. )
  558. {
  559. HRESULT hr = E_INVALIDARG;
  560. CSetStructuredExceptionHandler seh;
  561. TRY_BLOCK;
  562. // Seriliaze the object
  563. CAutoBlock cab(m_pObj->GetCriticalSection());
  564. // Clear ErrorInfo
  565. g_pCError->ClearErrorInfo();
  566. //========================================================================
  567. // Check Function Arguments
  568. //========================================================================
  569. if( ppDataSource != NULL ){
  570. assert(m_pObj->m_pCDataSource);
  571. assert(m_pObj->m_pCDataSource->GetOuterUnknown());
  572. //====================================================================
  573. //Handle Aggregated DataSource (if aggregated)
  574. //====================================================================
  575. hr = m_pObj->m_pCDataSource->GetOuterUnknown()->QueryInterface(riid, (LPVOID*)ppDataSource);
  576. }
  577. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IGetDataSource);
  578. CATCH_BLOCK_HRESULT(hr,L"IGetDataSource::GetDataSource");
  579. return hr;
  580. }
  581. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  582. //
  583. // Returns current settings of all properties in the DBPROPFLAGS_SESSION property group
  584. // HRESULT
  585. // S_OK The method succeeded
  586. // E_INVALIDARG pcProperties or prgPropertyInfo was NULL
  587. // E_OUTOFMEMORY Out of memory
  588. //
  589. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  590. STDMETHODIMP CImpISessionProperties::GetProperties (
  591. ULONG cPropertySets, // IN count of restiction guids
  592. const DBPROPIDSET rgPropertySets[], // IN restriction guids
  593. ULONG* pcProperties, // OUT count of properties returned
  594. DBPROPSET** prgProperties // OUT property information returned
  595. )
  596. {
  597. assert( m_pObj );
  598. assert( m_pObj->m_pUtilProp );
  599. HRESULT hr = S_OK;
  600. CSetStructuredExceptionHandler seh;
  601. TRY_BLOCK;
  602. // Seriliaze the object
  603. CAutoBlock cab(m_pObj->GetCriticalSection());
  604. g_pCError->ClearErrorInfo();
  605. //========================================================================
  606. // Check Arguments
  607. //========================================================================
  608. hr = m_pObj->m_pUtilProp->GetPropertiesArgChk(PROPSET_SESSION, cPropertySets,
  609. rgPropertySets, pcProperties, prgProperties);
  610. if ( !FAILED(hr) ){
  611. //========================================================================
  612. // just pass this call on to the utility object that manages our
  613. // properties
  614. //========================================================================
  615. hr = m_pObj->m_pUtilProp->GetProperties( PROPSET_SESSION,cPropertySets,rgPropertySets,pcProperties, prgProperties );
  616. }
  617. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ISessionProperties);
  618. CATCH_BLOCK_HRESULT(hr,L"ISessionProperties::GetProperties ");
  619. return hr;
  620. }
  621. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  622. //
  623. // Set properties in the DBPROPFLAGS_SESSION property group
  624. //
  625. // HRESULT
  626. // E_INVALIDARG cProperties was not equal to 0 and rgProperties was NULL
  627. // E_NOTIMPL this method is not implemented
  628. //
  629. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  630. STDMETHODIMP CImpISessionProperties::SetProperties ( ULONG cProperties, DBPROPSET rgProperties[] )
  631. {
  632. HRESULT hr = S_OK;
  633. assert( m_pObj );
  634. assert( m_pObj->m_pUtilProp );
  635. CSetStructuredExceptionHandler seh;
  636. TRY_BLOCK;
  637. // Seriliaze the object
  638. CAutoBlock cab(m_pObj->GetCriticalSection());
  639. // Clear Error information
  640. g_pCError->ClearErrorInfo();
  641. //========================================================================
  642. // Quick return if the Count of Properties is 0
  643. //========================================================================
  644. if( cProperties != 0 ){
  645. //====================================================================
  646. // Check Arguments for use by properties
  647. //====================================================================
  648. hr = m_pObj->m_pUtilProp->SetPropertiesArgChk(cProperties, rgProperties);
  649. if( !FAILED(hr) ){
  650. //====================================================================
  651. // just pass this call on to the utility object that manages our properties
  652. //====================================================================
  653. hr = m_pObj->m_pUtilProp->SetProperties( PROPSET_SESSION,cProperties, rgProperties);
  654. }
  655. }
  656. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_ISessionProperties);
  657. CATCH_BLOCK_HRESULT(hr,L"ISessionProperties::GetProperties ");
  658. return hr;
  659. }