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.

241 lines
7.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: StdQSpec.cxx
  7. //
  8. // Contents: ICommand for file-based queries
  9. //
  10. // Classes: CMetadataQuerySpec
  11. //
  12. // History: 30 Jun 1995 AlanW Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "metqspec.hxx"
  18. //+-------------------------------------------------------------------------
  19. //
  20. // Member: CMetadataQuerySpec::CMetadataQuerySpec, public
  21. //
  22. // Synopsis: Constructor of a CMetadataQuerySpec
  23. //
  24. // Arguments: [pOuterUnk] - Outer unknown
  25. // [ppMyUnk] - OUT: filled in with pointer to non-delegated
  26. // IUnknown on return
  27. // [eType] - Class of metadata to return
  28. // [pCat] - Content index catalog
  29. // [pMachine]
  30. //
  31. // History: 08-Feb-96 KyleP Added support for virtual paths
  32. //
  33. //--------------------------------------------------------------------------
  34. CMetadataQuerySpec::CMetadataQuerySpec (
  35. IUnknown * pOuterUnk,
  36. IUnknown ** ppMyUnk,
  37. CiMetaData eType,
  38. WCHAR const * pCat,
  39. WCHAR const * pMachine )
  40. : CRootQuerySpec(pOuterUnk, ppMyUnk),
  41. _eType( eType ),
  42. _pCat(0),
  43. _pMachine(0)
  44. {
  45. //
  46. // Make a copy of the catalog string for ICommand::Clone
  47. //
  48. unsigned len = wcslen( pCat ) + 1;
  49. _pCat = new WCHAR[len];
  50. RtlCopyMemory( _pCat, pCat, len * sizeof(WCHAR) );
  51. //
  52. // Make a copy of the machine string for ICommand::Clone
  53. //
  54. if ( 0 != pMachine )
  55. {
  56. len = wcslen( pMachine ) + 1;
  57. _pMachine = new WCHAR[len];
  58. RtlCopyMemory( _pMachine, pMachine, len * sizeof(WCHAR) );
  59. }
  60. END_CONSTRUCTION( CMetadataQuerySpec );
  61. }
  62. //+-------------------------------------------------------------------------
  63. //
  64. // Member: CMetadataQuerySpec::~CMetadataQuerySpec, private
  65. //
  66. // Synopsis: Destructor of a CMetadataQuerySpec
  67. //
  68. //--------------------------------------------------------------------------
  69. CMetadataQuerySpec::~CMetadataQuerySpec()
  70. {
  71. delete [] _pCat;
  72. delete [] _pMachine;
  73. }
  74. //+-------------------------------------------------------------------------
  75. //
  76. // Member: CMetadataQuerySpec::QueryInternalQuery, protected
  77. //
  78. // Synopsis: Instantiates internal query, using current parameters.
  79. //
  80. // Returns: Pointer to internal query object.
  81. //
  82. // History: 03-Mar-1997 KyleP Created
  83. //
  84. //--------------------------------------------------------------------------
  85. PIInternalQuery * CMetadataQuerySpec::QueryInternalQuery()
  86. {
  87. //
  88. // get a pointer to the IInternalQuery interface
  89. //
  90. PIInternalQuery * pQuery = 0;
  91. SCODE sc = EvalMetadataQuery( &pQuery, _eType, _pCat, _pMachine );
  92. if ( FAILED( sc ) )
  93. THROW( CException( sc ) );
  94. return pQuery;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // Member: MakeMetadataICommand
  99. //
  100. // Synopsis: Evaluate the metadata query
  101. //
  102. // Arguments: [ppQuery] -- Returns the IUnknown for the command
  103. // [eType] -- Type of metadata (vroot, proot, etc)
  104. // [wcsCat] -- Catalog
  105. // [wcsMachine] -- Machine name for meta query
  106. // [pOuterUnk] -- (optional) outer unknown pointer
  107. //
  108. // Returns SCODE result
  109. //
  110. // History: 15-Apr-96 SitaramR Created header
  111. // 29-May-97 EmilyB Added aggregation support, so now
  112. // returns IUnknown ptr and caller
  113. // must now call QI to get ICommand ptr
  114. //
  115. //----------------------------------------------------------------------------
  116. SCODE MakeMetadataICommand(
  117. IUnknown ** ppQuery,
  118. CiMetaData eType,
  119. WCHAR const * wcsCat,
  120. WCHAR const * wcsMachine,
  121. IUnknown * pOuterUnk )
  122. {
  123. //
  124. // Check for invalid parameters
  125. //
  126. if ( 0 == wcsCat ||
  127. 0 == ppQuery ||
  128. ( eType != CiVirtualRoots &&
  129. eType != CiPhysicalRoots &&
  130. eType != CiProperties ) )
  131. {
  132. return E_INVALIDARG;
  133. }
  134. *ppQuery = 0;
  135. CMetadataQuerySpec * pQuery = 0;
  136. SCODE sc = S_OK;
  137. TRANSLATE_EXCEPTIONS;
  138. TRY
  139. {
  140. pQuery = new CMetadataQuerySpec( pOuterUnk, ppQuery, eType,
  141. wcsCat,
  142. wcsMachine );
  143. }
  144. CATCH( CException, e )
  145. {
  146. Win4Assert(0 == pQuery);
  147. sc = e.GetErrorCode();
  148. }
  149. END_CATCH
  150. UNTRANSLATE_EXCEPTIONS;
  151. return sc;
  152. } //MakeMetadataICommand
  153. //+---------------------------------------------------------------------------
  154. //
  155. // Method: CMetadataQuerySpec::GetProperties, public
  156. //
  157. // Synopsis: Get rowset properties
  158. //
  159. // Arguments: [cPropertySetIDs] - number of desired property set IDs or 0
  160. // [rgPropertySetIDs] - array of desired property set IDs or NULL
  161. // [pcPropertySets] - number of property sets returned
  162. // [prgPropertySets] - array of returned property sets
  163. //
  164. // Returns: SCODE - result code indicating error return status. One of
  165. // S_OK, DB_S_ERRORSOCCURRED or DB_E_ERRORSOCCURRED. Any
  166. // other errors are thrown.
  167. //
  168. // History: 12-Mayr-97 dlee Created
  169. //
  170. //----------------------------------------------------------------------------
  171. SCODE STDMETHODCALLTYPE CMetadataQuerySpec::GetProperties(
  172. ULONG const cPropertySetIDs,
  173. DBPROPIDSET const rgPropertySetIDs[],
  174. ULONG * pcPropertySets,
  175. DBPROPSET ** prgPropertySets)
  176. {
  177. _DBErrorObj.ClearErrorInfo();
  178. SCODE scParent = CRootQuerySpec::GetProperties( cPropertySetIDs,
  179. rgPropertySetIDs,
  180. pcPropertySets,
  181. prgPropertySets );
  182. if ( S_OK != scParent )
  183. _DBErrorObj.PostHResult( scParent, IID_ICommandProperties );
  184. return scParent;
  185. } //GetProperties
  186. //+---------------------------------------------------------------------------
  187. //
  188. // Method: CMetadataQuerySpec::SetProperties, public
  189. //
  190. // Synopsis: Set rowset scope properties
  191. //
  192. // Arguments: [cPropertySets] - number of property sets
  193. // [rgPropertySets] - array of property sets
  194. //
  195. // Returns: SCODE - result code indicating error return status. One of
  196. // S_OK, DB_S_ERRORSOCCURRED or DB_E_ERRORSOCCURRED. Any
  197. // other errors are thrown.
  198. //
  199. // History: 12-Mayr-97 dlee Created
  200. //
  201. //----------------------------------------------------------------------------
  202. SCODE STDMETHODCALLTYPE CMetadataQuerySpec::SetProperties(
  203. ULONG cPropertySets,
  204. DBPROPSET rgPropertySets[] )
  205. {
  206. _DBErrorObj.ClearErrorInfo();
  207. SCODE scParent = CRootQuerySpec::SetProperties( cPropertySets,
  208. rgPropertySets );
  209. if ( S_OK != scParent )
  210. _DBErrorObj.PostHResult( scParent, IID_ICommandProperties );
  211. return scParent;
  212. } //SetProperties