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.

3059 lines
121 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMI OLE DB Provider
  4. //
  5. // (C) Copyright 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. //
  7. // Schema.cpp - Schema related class implementation
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. #include "schema.h"
  11. #include "enumerat.h"
  12. extern const WCHAR szWQL[] = L"WQL";
  13. extern const WCHAR szWQL2[] = L"WQL2";
  14. #define TABLENAMEMAX 255
  15. //Bug No: NTRaid 126631
  16. // 06/13/00
  17. #define NUMBER_OF_SCHEMAS 8
  18. enum guiddata
  19. {
  20. data1_DBSCHEMA_CATALOGS = 0xc8b52211,
  21. data1_DBSCHEMA_PROVIDER_TYPES = 0xc8b5222c,
  22. data1_DBSCHEMA_COLUMNS = 0xc8b52214,
  23. data1_DBSCHEMA_TABLES = 0xc8b52229,
  24. data1_DBSCHEMA_PRIMARY_KEYS = 0xc8b522c5,
  25. data1_DBSCHEMA_TABLES_INFO = 0xc8b522e0,
  26. data1_DBSCHEMA_PROCEDURES = 0xc8b52224,
  27. data1_DBSCHEMA_PROCEDURE_PARAMETERS = 0xc8b522b8,
  28. };
  29. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. CIMTypeInfo g_ProviderTypeDetails[] = {
  31. { L"CIM_EMPTY", 0, 0, 0},
  32. { L"CIM_SINT8", DBTYPE_I1, sizeof(BYTE), 0},
  33. { L"CIM_UINT8", DBTYPE_UI1, sizeof(BYTE), 1},
  34. { L"CIM_SINT16", DBTYPE_I2, sizeof(short), 0},
  35. { L"CIM_UINT16", DBTYPE_UI2, sizeof(short), 1},
  36. { L"CIM_SINT32", DBTYPE_I4, sizeof(long), 0},
  37. { L"CIM_UINT32", DBTYPE_UI4, sizeof(long), 1},
  38. { L"CIM_SINT64", DBTYPE_I8, sizeof(__int64), 0},
  39. { L"CIM_UINT64", DBTYPE_UI8, sizeof(__int64), 1},
  40. { L"CIM_REAL32", DBTYPE_R4, sizeof(long), 0},
  41. { L"CIM_REAL64", DBTYPE_R8, sizeof(__int64), 0},
  42. { L"CIM_BOOLEAN", DBTYPE_BOOL, sizeof(short), 0},
  43. { L"CIM_STRING", DBTYPE_BSTR, ~0, 0},
  44. { L"CIM_DATETIME", DBTYPE_DBTIMESTAMP, sizeof(DBTIMESTAMP),0},
  45. // { L"CIM_REFERENCE", 0, 0, 0},
  46. { L"CIM_CHAR16", DBTYPE_UI2, sizeof(short), 1}
  47. // { L"CIM_OBJECT", DBTYPE_IUNKNOWN, sizeof(BSTR), 0},
  48. // { L"CIM_FLAG_ARRAY",0, 0, 0}
  49. };
  50. SchemaRowsetDefinition g_SourcesRowsetColumns[] = { {L"SOURCES_NAME", CIM_STRING},
  51. {L"SOURCES_PARSENAME", CIM_STRING},
  52. {L"SOURCES_DESCRIPTION",CIM_STRING},
  53. {L"SOURCES_TYPE", CIM_UINT16},
  54. {L"SOURCES_ISPARENT", CIM_BOOLEAN}};
  55. SchemaRowsetDefinition g_ProviderTypes[] = { {L"TYPE_NAME", CIM_STRING},
  56. {L"DATA_TYPE", CIM_UINT16},
  57. {L"COLUMN_SIZE", CIM_UINT32},
  58. {L"LITERAL_PREFIX", CIM_STRING},
  59. {L"LITERAL_SUFFIX", CIM_STRING},
  60. {L"CREATE_PARAMS", CIM_STRING},
  61. {L"IS_NULLABLE", CIM_BOOLEAN},
  62. {L"CASE_SENSITIVE", CIM_BOOLEAN},
  63. {L"SEARCHABLE" , CIM_UINT32},
  64. {L"UNSIGNED_ATTRIBUTE",CIM_BOOLEAN},
  65. {L"FIXED_PREC_SCALE", CIM_BOOLEAN},
  66. {L"AUTO_UNIQUE_VALUE", CIM_BOOLEAN},
  67. {L"LOCAL_TYPE_NAME", CIM_STRING},
  68. {L"MINIMUM_SCALE", CIM_SINT16},
  69. {L"MAXIMUM_SCALE", CIM_SINT16},
  70. {L"GUID", DBTYPE_GUID},
  71. {L"TYPELIB", CIM_STRING},
  72. {L"VERSION", CIM_STRING},
  73. {L"IS_LONG", CIM_BOOLEAN},
  74. {L"BEST_MATCH", CIM_BOOLEAN},
  75. {L"IS_FIXEDLENGTH", CIM_BOOLEAN} };
  76. SchemaRowsetDefinition g_CatalogRowsetColumns[] = {{L"CATALOG_NAME", CIM_STRING},
  77. {L"SOURCES_DESCRIPTION", CIM_STRING} };
  78. SchemaRowsetDefinition g_Tables[] = { {L"TABLE_CATALOG", CIM_STRING},
  79. {L"TABLE_SCHEMA", CIM_STRING},
  80. {L"TABLE_NAME", CIM_STRING},
  81. {L"TABLE_TYPE", CIM_STRING},
  82. {L"TABLE_GUID", DBTYPE_GUID},
  83. {L"DESCRIPTION", CIM_STRING},
  84. {L"TABLE_PROPID", CIM_UINT32},
  85. {L"DATE_CREATED", DBTYPE_DATE},
  86. {L"DATE_MODIFIED", DBTYPE_DATE}};
  87. SchemaRowsetDefinition g_TablesInfo[] = { {L"TABLE_CATALOG", CIM_STRING},
  88. {L"TABLE_SCHEMA", CIM_STRING},
  89. {L"TABLE_NAME", CIM_STRING},
  90. {L"TABLE_TYPE", CIM_STRING},
  91. {L"TABLE_GUID", DBTYPE_GUID},
  92. {L"BOOKMARKS", CIM_BOOLEAN},
  93. {L"BOOKMARK_TYPE", CIM_UINT32},
  94. {L"BOOKMARK_DATATYPE", CIM_UINT16},
  95. {L"BOOKMARK_MAXIMUM_LENGTH",CIM_UINT32},
  96. {L"BOOKMARK_INFORMATION", CIM_UINT32},
  97. {L"TABLE_VERSION", CIM_SINT64},
  98. {L"CARDINALITY", CIM_UINT64},
  99. {L"DESCRIPTION", CIM_STRING},
  100. {L"TABLE_PROPID", CIM_UINT32}};
  101. SchemaRowsetDefinition g_ColumnsRowsetColumns[] = { {L"TABLE_CATALOG", CIM_STRING},
  102. {L"TABLE_SCHEMA", CIM_STRING},
  103. {L"TABLE_NAME", CIM_STRING},
  104. {L"COLUMN_NAME", CIM_STRING},
  105. {L"COLUMN_GUID", DBTYPE_GUID},
  106. {L"COLUMN_PROPID", CIM_UINT32},
  107. {L"COLUMN_POSITION", CIM_UINT32},
  108. {L"COLUMN_HASDEFAULT", CIM_BOOLEAN},
  109. {L"COLUMN_DEFAULT", CIM_STRING},
  110. {L"COLUMN_FLAGS", CIM_UINT32},
  111. {L"IS_NULLABLE", CIM_BOOLEAN},
  112. {L"DATA_TYPE", CIM_UINT16},
  113. {L"TYPE_GUID", DBTYPE_GUID},
  114. {L"CHARACTER_MAXIMUM_LENGTH", CIM_UINT32},
  115. {L"CHARACTER_OCTET_LENGTH", CIM_UINT32},
  116. {L"NUMERIC_PRECISION", CIM_UINT16},
  117. {L"NUMERIC_SCALE", CIM_SINT16},
  118. {L"DATETIME_PRECISION", CIM_UINT32},
  119. {L"CHARACTER_SET_CATALOG", CIM_STRING},
  120. {L"CHARACTER_SET_SCHEMA", CIM_STRING},
  121. {L"CHARACTER_SET_NAME", CIM_STRING},
  122. {L"COLLATION_CATALOG", CIM_STRING},
  123. {L"COLLATION_SCHEMA", CIM_STRING},
  124. {L"COLLATION_NAME", CIM_STRING},
  125. {L"DOMAIN_CATALOG", CIM_STRING},
  126. {L"DOMAIN_SCHEMA", CIM_STRING},
  127. {L"DOMAIN_NAME", CIM_STRING},
  128. {L"DESCRIPTION", CIM_STRING}};
  129. SchemaRowsetDefinition g_PrimaryKeysColumns[] = { {L"TABLE_CATALOG", CIM_STRING},
  130. {L"TABLE_SCHEMA", CIM_STRING},
  131. {L"TABLE_NAME", CIM_STRING},
  132. {L"COLUMN_NAME", CIM_STRING},
  133. {L"COLUMN_GUID", DBTYPE_GUID},
  134. {L"COLUMN_PROPID", CIM_UINT32},
  135. {L"ORDINAL", CIM_UINT32},
  136. {L"PK_NAME", CIM_STRING}};
  137. SchemaRowsetDefinition g_Procedures[] = {{L"PROCEDURE_CATALOG", CIM_STRING},
  138. {L"PROCEDURE_SCHEMA", CIM_STRING},
  139. {L"PROCEDURE_NAME", CIM_STRING},
  140. {L"PROCEDURE_TYPE", CIM_SINT16},
  141. {L"PROCEDURE_DEFINITION", CIM_STRING},
  142. {L"DESCRIPTION", CIM_STRING},
  143. {L"DATE_CREATED", DBTYPE_DATE},
  144. {L"DATE_MODIFIED", DBTYPE_DATE}};
  145. SchemaRowsetDefinition g_ProcedureParameters[] = {{L"PROCEDURE_CATALOG", CIM_STRING},
  146. {L"PROCEDURE_SCHEMA", CIM_STRING},
  147. {L"PROCEDURE_NAME", CIM_STRING},
  148. {L"PARAMETER_NAME", CIM_STRING},
  149. {L"ORDINAL_POSITION", CIM_UINT16},
  150. {L"PARAMETER_TYPE", CIM_UINT16},
  151. {L"PARAMETER_HASDEFAULT", CIM_BOOLEAN},
  152. {L"PARAMETER_DEFAULT", CIM_STRING},
  153. {L"IS_NULLABLE", CIM_BOOLEAN},
  154. {L"DATATYPE", CIM_UINT16},
  155. {L"CHARACTER_MAXIMUM_LENGTH",CIM_UINT32},
  156. {L"CHARACTER_OCTECT_LENGTH", CIM_UINT32},
  157. {L"NUMERIC_PRECISION", CIM_UINT16},
  158. {L"NUMERIC_SCALE", CIM_SINT16},
  159. {L"DESCRIPTION", CIM_STRING},
  160. {L"TYPE_NAME", CIM_STRING},
  161. {L"LOCAL_TYPE_NAME", CIM_STRING}};
  162. SchemaRowsetDefinition g_ProcedureColumns[] = {{L"PROCEDURE_CATALOG", CIM_STRING},
  163. {L"PROCEDURE_SCHEMA", CIM_STRING},
  164. {L"PROCEDURE_NAME", CIM_STRING},
  165. {L"COLUMN_NAME", CIM_STRING},
  166. {L"COLUMN_GUID", DBTYPE_GUID},
  167. {L"COLUMN_PROPID", CIM_UINT32},
  168. {L"ROWSET_NUMBER", CIM_UINT32},
  169. {L"ORDINAL_POSITION", CIM_UINT32},
  170. {L"IS_NULLABLE", CIM_BOOLEAN},
  171. {L"DATA_TYPE", CIM_UINT16},
  172. {L"TYPE_GUID", DBTYPE_GUID},
  173. {L"CHARACTER_MAXIMUM_LENGTH", CIM_UINT32},
  174. {L"CHARACTER_OCTECT_LENGTH", CIM_UINT32},
  175. {L"NUMERIC_PRECISION", CIM_UINT16},
  176. {L"NUMERIC_SCALE", CIM_SINT16},
  177. {L"DESCRIPTION", CIM_STRING}};
  178. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  179. //**********************************************************************************************************
  180. //
  181. // CLASS: CSCHEMA
  182. //
  183. //**********************************************************************************************************
  184. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  185. CSchema::CSchema(LPUNKNOWN pUnkOuter, int nTableId,PCDBSESSION pObj) :
  186. CRowset(pUnkOuter,pObj)
  187. {
  188. m_nTableId = nTableId;
  189. }
  190. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. CSchema::~CSchema()
  192. {
  193. }
  194. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  195. //
  196. // Sets the rowset property corresponding to the requested interface if the requested interface is available
  197. // on a read-only rowset.
  198. //
  199. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  200. HRESULT CSchema::SetReadOnlyProperty( CUtilProp* pRowsetProps,REFIID riid )
  201. {
  202. HRESULT hr = S_OK;
  203. if (riid == IID_IRowsetChange || riid == IID_IRowsetUpdate || riid == IID_IRowsetResynch)
  204. hr = (E_NOINTERFACE);
  205. return hr;
  206. }
  207. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  208. //
  209. // Initialize a schema rowset
  210. //
  211. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  212. STDMETHODIMP CSchema::FInit( ULONG cPropertySets, DBPROPSET rgPropertySets[],
  213. REFIID riid, IUnknown *pUnkOuter,
  214. IUnknown **ppIRowset, WCHAR * wcsSpecificTable )
  215. {
  216. HRESULT hr = S_OK;
  217. HRESULT hrProp = S_OK;
  218. DWORD dwStatus = 0;
  219. PWSTR pwszBuff = NULL;
  220. LONG cCursorRows = 0;
  221. WCHAR strTableName[TABLENAMEMAX];
  222. memset(strTableName,0,TABLENAMEMAX * sizeof(WCHAR));
  223. if( SUCCEEDED(hr =GetTableName(strTableName)))
  224. {
  225. //==========================================================================
  226. // Set the Rowset Properties
  227. //==========================================================================
  228. hr = InitRowset(m_nTableId, cPropertySets,rgPropertySets,strTableName,0,wcsSpecificTable);
  229. if(SUCCEEDED(hr))
  230. {
  231. //==========================================================================
  232. // If the consumer asks for IID_IUnknown, IID_IAccessor,
  233. // IID_IColumnsInfo, or IID_IRowsetInfo, we do not need to
  234. //==========================================================================
  235. if ( riid != IID_IRowset && riid != IID_IColumnsInfo && riid != IID_IAccessor && riid != IID_IRowsetInfo
  236. && riid != IID_IUnknown && riid != IID_IMultipleResults ){
  237. hr = SetReadOnlyProperty(m_pUtilProp,riid);
  238. }
  239. if(SUCCEEDED(hr))
  240. {
  241. //==========================================================================
  242. // Execute the schema command to produce the rowset.
  243. //==========================================================================
  244. if (SUCCEEDED(hr)){
  245. if (hr == DB_E_ERRORSOCCURRED && cPropertySets > 0){
  246. m_pUtilProp->SetPropertiesArgChk(cPropertySets, rgPropertySets);
  247. }
  248. }
  249. if (DB_S_ERRORSOCCURRED == hr){
  250. hrProp = DB_S_ERRORSOCCURRED;
  251. if (cPropertySets > 0)
  252. {
  253. m_pUtilProp->SetPropertiesArgChk(cPropertySets, rgPropertySets);
  254. }
  255. }
  256. //==========================================================================
  257. // Get the requested interfaceS
  258. //==========================================================================
  259. hr = QueryInterface(riid, (LPVOID*)ppIRowset);
  260. } // if (Succeeded(hr))
  261. } // If(succeeded(hr) after initializing the rowset
  262. } // if a valid tablename
  263. hr = (hr == S_OK) ? hrProp : hr;
  264. hr = hr != S_OK ? g_pCError->PostHResult(hr, &IID_IDBSchemaRowset) : hr;
  265. return hr;
  266. }
  267. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  268. HRESULT CSchema::GetTableName(WCHAR *pTableName)
  269. {
  270. HRESULT hr = S_OK;
  271. if(pTableName != NULL)
  272. {
  273. switch(m_nTableId)
  274. {
  275. case PROCEDURES_ROWSET:
  276. wcscpy(pTableName,PROCEDURES);
  277. break;
  278. case PROCEDURE_PARAMETERS_ROWSET:
  279. wcscpy(pTableName,PROCEDURE_PARAMETERS);
  280. break;
  281. case SOURCES_ROWSET:
  282. wcscpy(pTableName,NAMESPACE);
  283. break;
  284. case PROVIDER_TYPES_ROWSET:
  285. wcscpy(pTableName,PROVIDER_TYPES);
  286. break;
  287. case CATALOGS_ROWSET:
  288. wcscpy(pTableName,CATALOGS);
  289. break;
  290. case COLUMNS_ROWSET:
  291. wcscpy(pTableName,COLUMNS);
  292. break;
  293. case TABLES_ROWSET:
  294. wcscpy(pTableName,TABLES);
  295. break;
  296. case PRIMARY_KEYS_ROWSET:
  297. wcscpy(pTableName,PRIMARY_KEYS);
  298. break;
  299. case TABLES_INFO_ROWSET:
  300. wcscpy(pTableName,TABLESINFO);
  301. break;
  302. default:
  303. hr = E_FAIL;
  304. };
  305. }
  306. else
  307. {
  308. hr = E_FAIL;
  309. }
  310. return hr;
  311. }
  312. /*
  313. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  314. //
  315. // Increments a reference count for the object.
  316. //
  317. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  318. STDMETHODIMP_(ULONG) CImpIDBSchemaRowset::AddRef(void)
  319. {
  320. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  321. return m_pCDBSession->AddRef();
  322. }
  323. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  324. //
  325. // Decrement the object's reference count and deletes the object when the new reference count is zero.
  326. //
  327. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  328. STDMETHODIMP_(ULONG) CImpIDBSchemaRowset::Release(void)
  329. {
  330. DEBUGCODE(InterlockedDecrement((long*)&m_cRef));
  331. return m_pCDBSession->Release();
  332. }
  333. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. //
  335. // Returns a pointer to a specified interface. Callers use QueryInterface to determine which interfaces the
  336. // called object supports.
  337. //
  338. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  339. STDMETHODIMP CImpIDBSchemaRowset::QueryInterface( REFIID riid, LPVOID * ppv )
  340. {
  341. return m_pCDBSession->QueryInterface(riid, ppv);
  342. }
  343. */
  344. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  345. //**********************************************************************************************************
  346. //
  347. // CLASS CImpIDBSchemaRowset
  348. //
  349. //**********************************************************************************************************
  350. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  351. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  352. //
  353. // Instantiate a rowset with schema information.
  354. //
  355. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  356. STDMETHODIMP CImpIDBSchemaRowset::GetRowset( IUnknown *pUnkOuter, REFGUID rguidSchema, ULONG cRestrictions,
  357. const VARIANT rgRestrictions[], REFIID riid,ULONG cProperties,
  358. DBPROPSET rgProperties[], IUnknown **ppIRowset )
  359. {
  360. HRESULT hr;
  361. CSchema *pCSchema = NULL;
  362. WCHAR * wcsSpecificTable = NULL;
  363. //========================================================
  364. // Serialize access to this object.
  365. //========================================================
  366. CAutoBlock cab(m_pCDBSession->GetCriticalSection());
  367. CError::ClearErrorInfo();
  368. //========================================================
  369. // Assign in case of error.
  370. //========================================================
  371. if (ppIRowset)
  372. {
  373. *ppIRowset = NULL;
  374. }
  375. //========================================================
  376. // Check per spec.
  377. //========================================================
  378. if (ppIRowset == NULL || (cRestrictions && rgRestrictions == NULL) || (cProperties && rgProperties == NULL) )
  379. {
  380. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  381. }
  382. else
  383. {
  384. //========================================================
  385. // The outer object must explicitly ask for IUnknown
  386. //========================================================
  387. if (pUnkOuter != NULL && riid != IID_IUnknown)
  388. {
  389. g_pCError->PostHResult((DB_E_NOAGGREGATION), &IID_IDBSchemaRowset);
  390. }
  391. else{
  392. //========================================================
  393. // Assume that all the pre-defined OLEDB guids differ
  394. // only by the first DWORD, Data1. We have to make a
  395. // table of constants, since the compiler can't
  396. // have non-constants in case statements.
  397. //========================================================
  398. switch ( rguidSchema.Data1 )
  399. {
  400. //===================================================
  401. // methods - the list of methods for a table
  402. //===================================================
  403. case data1_DBSCHEMA_PROCEDURES:
  404. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_PROCEDURES)
  405. {
  406. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  407. }
  408. else
  409. {
  410. //====================================================================
  411. // The specific table name is located in the 3rd restriction
  412. //====================================================================
  413. if( cRestrictions > 1 && rgRestrictions[1].vt != VT_EMPTY)
  414. {
  415. wcsSpecificTable = V_BSTR(&rgRestrictions[1]);
  416. }
  417. pCSchema = new CSchema_Procedures(pUnkOuter,m_pCDBSession);
  418. }
  419. break;
  420. //===================================================
  421. // methods - the list of parameters for a method
  422. //===================================================
  423. case data1_DBSCHEMA_PROCEDURE_PARAMETERS:
  424. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_PROCEDURE_PARAMETERS)
  425. {
  426. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  427. }
  428. else
  429. {
  430. //====================================================================
  431. // The specific table name is located in the 3rd restriction
  432. //====================================================================
  433. if( cRestrictions > 1 && rgRestrictions[1].vt != VT_EMPTY)
  434. {
  435. wcsSpecificTable = V_BSTR(&rgRestrictions[1]);
  436. }
  437. pCSchema = new CSchema_Procedure_Parameters(pUnkOuter,m_pCDBSession);
  438. }
  439. break;
  440. //===================================================
  441. // catalogs
  442. //===================================================
  443. case data1_DBSCHEMA_CATALOGS:
  444. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_CATALOGS)
  445. {
  446. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  447. }
  448. else
  449. {
  450. pCSchema = new CSchema_Catalogs(pUnkOuter,m_pCDBSession);
  451. }
  452. break;
  453. //===================================================
  454. // provider types
  455. //===================================================
  456. case data1_DBSCHEMA_PROVIDER_TYPES:
  457. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_PROVIDER_TYPES){
  458. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  459. }
  460. else{
  461. pCSchema = new CSchema_Provider_Types(pUnkOuter,m_pCDBSession);
  462. }
  463. break;
  464. //===================================================
  465. // columns
  466. //===================================================
  467. case data1_DBSCHEMA_COLUMNS:
  468. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_COLUMNS)
  469. {
  470. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  471. }
  472. else
  473. {
  474. //====================================================================
  475. // The specific table name is located in the 3rd restriction
  476. //====================================================================
  477. if( cRestrictions > 2 && rgRestrictions[2].vt != VT_EMPTY)
  478. {
  479. wcsSpecificTable = V_BSTR(&rgRestrictions[2]);
  480. }
  481. pCSchema = new CSchema_Columns(pUnkOuter,m_pCDBSession);
  482. }
  483. break;
  484. //===================================================
  485. // tables
  486. //===================================================
  487. case data1_DBSCHEMA_TABLES:
  488. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_TABLES)
  489. {
  490. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  491. }
  492. else
  493. {
  494. //====================================================================
  495. // The specific table name is located in the 3rd restriction
  496. //====================================================================
  497. if( cRestrictions > 2 && rgRestrictions[2].vt != VT_EMPTY)
  498. {
  499. wcsSpecificTable = V_BSTR(&rgRestrictions[2]);
  500. }
  501. pCSchema = new CSchema_Tables(pUnkOuter,m_pCDBSession);
  502. }
  503. break;
  504. //===================================================
  505. // primary keys
  506. //===================================================
  507. case data1_DBSCHEMA_PRIMARY_KEYS:
  508. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_TABLES_INFO)
  509. {
  510. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  511. }
  512. else
  513. {
  514. //====================================================================
  515. // The specific table name is located in the 2nd restriction
  516. //====================================================================
  517. if( cRestrictions > 1 && rgRestrictions[1].vt != VT_EMPTY)
  518. {
  519. wcsSpecificTable = V_BSTR(&rgRestrictions[1]);
  520. }
  521. pCSchema = new CSchema_Primary_Keys(pUnkOuter,m_pCDBSession);
  522. }
  523. break;
  524. //===================================================
  525. // tables info
  526. //===================================================
  527. case data1_DBSCHEMA_TABLES_INFO:
  528. if (cRestrictions > CRESTRICTIONS_DBSCHEMA_TABLES_INFO)
  529. {
  530. g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  531. }
  532. else
  533. {
  534. //====================================================================
  535. // The specific table name is located in the 3rd restriction
  536. //====================================================================
  537. if( cRestrictions > 2 && rgRestrictions[2].vt != VT_EMPTY)
  538. {
  539. wcsSpecificTable = V_BSTR(&rgRestrictions[2]);
  540. }
  541. pCSchema = new CSchema_Tables_Info(pUnkOuter,m_pCDBSession);
  542. }
  543. break;
  544. default:
  545. //===================================================
  546. // check for provider-specific schema rowsets
  547. //===================================================
  548. return g_pCError->PostHResult(E_INVALIDARG, &IID_IDBSchemaRowset);
  549. break;
  550. }
  551. //===================================================
  552. // At this point, pCSchema contains the uninitialized
  553. // object, derived from CSchema
  554. //===================================================
  555. if (!pCSchema)
  556. {
  557. g_pCError->PostHResult((E_OUTOFMEMORY), &IID_IDBSchemaRowset);
  558. }
  559. }
  560. }
  561. //===================================================
  562. // Initialize. Creates the rowset.
  563. //===================================================
  564. if( pCSchema )
  565. {
  566. hr = pCSchema->FInit(cProperties, rgProperties, riid, pUnkOuter, ppIRowset,wcsSpecificTable);
  567. if( S_OK == hr )
  568. {
  569. (*ppIRowset)->AddRef();
  570. }
  571. //===================================================
  572. // Release our reference.
  573. //===================================================
  574. pCSchema->Release();
  575. }
  576. else
  577. {
  578. hr = E_OUTOFMEMORY;
  579. }
  580. return hr;
  581. }
  582. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  583. //
  584. // Return an array of guids for supported schemas.
  585. //
  586. //Bug No: NTRaid 126631
  587. // 06/13/00
  588. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  589. STDMETHODIMP CImpIDBSchemaRowset::GetSchemas( ULONG *pcSchemas, GUID **ppSchemas, ULONG **prgRestrictionSupport )
  590. {
  591. GUID *pSchemas;
  592. ULONG *pRestrictionSupport;
  593. ULONG cSchemas;
  594. //===================================================
  595. // Serialize access to this object.
  596. //===================================================
  597. // m_pCDBSession->GetCriticalSection();
  598. g_pCError->ClearErrorInfo();
  599. if (pcSchemas)
  600. *pcSchemas = 0;
  601. if (ppSchemas)
  602. *ppSchemas = NULL;
  603. if (prgRestrictionSupport)
  604. *prgRestrictionSupport = NULL;
  605. //===================================================
  606. // Check per spec.
  607. //===================================================
  608. if (pcSchemas == NULL || ppSchemas == NULL || prgRestrictionSupport == NULL)
  609. {
  610. return g_pCError->PostHResult((E_INVALIDARG), &IID_IDBSchemaRowset);
  611. }
  612. cSchemas = NUMBER_OF_SCHEMAS;
  613. pSchemas = (GUID*) g_pIMalloc->Alloc(sizeof(GUID) * cSchemas);
  614. if (NULL == pSchemas)
  615. {
  616. return g_pCError->PostHResult((E_OUTOFMEMORY),&IID_IDBSchemaRowset);
  617. }
  618. pRestrictionSupport = (ULONG*)g_pIMalloc->Alloc(sizeof(ULONG) * cSchemas);
  619. if (NULL == pRestrictionSupport)
  620. {
  621. g_pIMalloc->Free(pSchemas);
  622. return g_pCError->PostHResult((E_OUTOFMEMORY),&IID_IDBSchemaRowset);
  623. }
  624. *ppSchemas = pSchemas;
  625. *pSchemas++ = DBSCHEMA_CATALOGS;
  626. *pSchemas++ = DBSCHEMA_PROVIDER_TYPES;
  627. *pSchemas++ = DBSCHEMA_COLUMNS;
  628. *pSchemas++ = DBSCHEMA_TABLES;
  629. *pSchemas++ = DBSCHEMA_PRIMARY_KEYS;
  630. *pSchemas++ = DBSCHEMA_TABLES_INFO;
  631. *pSchemas++ = DBSCHEMA_PROCEDURES;
  632. *pSchemas++ = DBSCHEMA_PROCEDURE_PARAMETERS;
  633. if( prgRestrictionSupport != NULL)
  634. {
  635. *prgRestrictionSupport = pRestrictionSupport;
  636. *pRestrictionSupport++ = eSup_CATALOGS;
  637. *pRestrictionSupport++ = eSup_PROVIDER_TYPES;
  638. *pRestrictionSupport++ = eSup_COLUMNS;
  639. *pRestrictionSupport++ = eSup_TABLES;
  640. *pRestrictionSupport++ = eSup_PRIMARY_KEYS;
  641. *pRestrictionSupport++ = eSup_TABLES_INFO;
  642. *pRestrictionSupport++ = eSup_PROCEDURES;
  643. *pRestrictionSupport++ = eSup_PROCEDURE_PARAMETERS;
  644. }
  645. //===================================================
  646. // Set the number of schemas we have recorded.
  647. //===================================================
  648. *pcSchemas = cSchemas;
  649. return S_OK;
  650. }
  651. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  652. //***********************************************************************************************************
  653. //
  654. // Class Schema definition
  655. //
  656. //***********************************************************************************************************
  657. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  658. CWbemSchemaClassDefinitionWrapper::CWbemSchemaClassDefinitionWrapper(CWbemClassParameters * p) :
  659. CWbemClassDefinitionWrapper(p)
  660. {
  661. m_nSchemaClassIndex = 0;
  662. m_nMaxColumns = 0;
  663. m_bSchema = TRUE;
  664. }
  665. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  666. CWbemSchemaClassDefinitionWrapper::~CWbemSchemaClassDefinitionWrapper()
  667. {
  668. }
  669. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  670. HRESULT CWbemSchemaClassDefinitionWrapper::ValidClass( )
  671. {
  672. return S_OK;
  673. }
  674. //////////////////////////////////////////////////////////////////////////////////////////////////
  675. HRESULT CWbemSchemaClassDefinitionWrapper::TotalPropertiesInClass(ULONG & ulPropCount, ULONG & ulSysPropCount )
  676. {
  677. ulPropCount = m_nMaxColumns;
  678. ulSysPropCount = 0;
  679. return S_OK;
  680. }
  681. //////////////////////////////////////////////////////////////////////////////////////////////////
  682. HRESULT CWbemSchemaClassDefinitionWrapper::BeginPropertyEnumeration()
  683. {
  684. m_nSchemaClassIndex = 0;
  685. return S_OK;
  686. }
  687. //////////////////////////////////////////////////////////////////////////////////////////////////
  688. HRESULT CWbemSchemaClassDefinitionWrapper::EndPropertyEnumeration()
  689. {
  690. m_nSchemaClassIndex = 0;
  691. return S_OK;
  692. }
  693. //////////////////////////////////////////////////////////////////////////////////////////////////
  694. // return failed, because we don't support the property qualifier enumeration
  695. HRESULT CWbemSchemaClassDefinitionWrapper::BeginPropertyQualifierEnumeration(BSTR strPropName)
  696. {
  697. return WBEM_S_NO_MORE_DATA;
  698. }
  699. //////////////////////////////////////////////////////////////////////////////////////////////////
  700. //************************************************************************************************
  701. //
  702. // Deal with a Schema class instance
  703. //
  704. //************************************************************************************************
  705. //////////////////////////////////////////////////////////////////////////////////////////////////
  706. CWbemSchemaClassInstanceWrapper::CWbemSchemaClassInstanceWrapper( CWbemClassParameters * p ): CWbemClassInstanceWrapper(p)
  707. {
  708. m_uCurrentIndex = 0;
  709. m_nMaxColumns = 0;
  710. }
  711. //////////////////////////////////////////////////////////////////////////////////////////////////
  712. CWbemSchemaClassInstanceWrapper::~CWbemSchemaClassInstanceWrapper( )
  713. {
  714. }
  715. //////////////////////////////////////////////////////////////////////////////////////////////////
  716. HRESULT CWbemSchemaClassInstanceWrapper::GetClassProperty(WCHAR * wcsProperty, VARIANT * v, CIMTYPE * pType , LONG * plFlavor )
  717. {
  718. HRESULT hr;
  719. BSTR bProp;
  720. bProp = Wmioledb_SysAllocString(wcsProperty);
  721. hr = GetProperty(bProp,v,pType,plFlavor);
  722. SysFreeString(bProp);
  723. return hr;
  724. }
  725. //////////////////////////////////////////////////////////////////////////////////////////////////
  726. void CWbemSchemaClassInstanceWrapper::AddToKeyList(WCHAR *& pwcsKeyList, WCHAR * wcsKey )
  727. {
  728. WCHAR * pTmp = NULL;
  729. if( !pwcsKeyList ){
  730. pwcsKeyList = new WCHAR[wcslen(wcsKey) + 1];
  731. wcscpy(pwcsKeyList,wcsKey);
  732. }
  733. else{
  734. pTmp = new WCHAR[wcslen(pwcsKeyList) + wcslen(wcsKey) + 10];
  735. swprintf(pTmp,L"%s,%s",pwcsKeyList,wcsKey);
  736. SAFE_DELETE_PTR(pwcsKeyList);
  737. pwcsKeyList = pTmp;
  738. }
  739. }
  740. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  741. //***********************************************************************************************************
  742. // Class Schema Instance List
  743. //***********************************************************************************************************
  744. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  745. CWbemSchemaInstanceList::CWbemSchemaInstanceList(CWbemClassParameters * p) : CWbemInstanceList(p)
  746. {
  747. m_ulMaxRow = 0;
  748. m_fGotThemAll = FALSE;
  749. m_pSpecificClass = NULL;
  750. m_pwcsSpecificClass = NULL;
  751. }
  752. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  753. CWbemSchemaInstanceList::CWbemSchemaInstanceList(CWbemClassParameters * p,WCHAR * pSpecific) : CWbemInstanceList(p)
  754. {
  755. m_pSpecificClass = NULL;
  756. m_ulMaxRow = 0;
  757. m_fGotThemAll = FALSE;
  758. m_pwcsSpecificClass = pSpecific;
  759. }
  760. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  761. CWbemSchemaInstanceList::~CWbemSchemaInstanceList()
  762. {
  763. ResetTheSpecificClass();
  764. }
  765. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  766. HRESULT CWbemSchemaInstanceList::ResetTheSpecificClass()
  767. {
  768. m_fGotThemAll = FALSE;
  769. SAFE_RELEASE_PTR(m_pSpecificClass);
  770. return S_OK;
  771. }
  772. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  773. HRESULT CWbemSchemaInstanceList::GetTheSpecificClass()
  774. {
  775. HRESULT hr = WBEM_S_NO_MORE_DATA;
  776. if( !m_fGotThemAll )
  777. {
  778. hr = (m_pParms->GetServicesPtr())->GetObject(m_pwcsSpecificClass, 0, NULL, &m_pSpecificClass, NULL);
  779. m_fGotThemAll = TRUE;
  780. }
  781. return hr;
  782. }
  783. //********************************************************************************************
  784. //////////////////////////////////////////////////////////////////////////////////////////////
  785. //
  786. // Classes for the Sources schema rowset
  787. //
  788. //********************************************************************************************
  789. //////////////////////////////////////////////////////////////////////////////////////////////
  790. CWbemSchemaSourcesClassDefinitionWrapper::CWbemSchemaSourcesClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  791. {
  792. m_nMaxColumns = sizeof(g_SourcesRowsetColumns)/sizeof(SchemaRowsetDefinition);
  793. }
  794. //////////////////////////////////////////////////////////////////////////////////////////////
  795. HRESULT CWbemSchemaSourcesClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  796. {
  797. HRESULT hr = S_OK;
  798. //===============================================================================
  799. // See if we got all of the column info
  800. //===============================================================================
  801. if( m_nSchemaClassIndex == m_nMaxColumns )
  802. {
  803. return WBEM_S_NO_MORE_DATA;
  804. }
  805. //===============================================================================
  806. // Get the column name and data type
  807. //===============================================================================
  808. *pType = g_SourcesRowsetColumns[m_nSchemaClassIndex].Type;
  809. *pProperty = Wmioledb_SysAllocString(g_SourcesRowsetColumns[m_nSchemaClassIndex].wcsColumnName);
  810. m_nSchemaClassIndex++;
  811. return hr;
  812. }
  813. //////////////////////////////////////////////////////////////////////////////////////////////////
  814. HRESULT CWbemSchemaSourcesInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  815. {
  816. HRESULT hr = S_OK;
  817. ((CVARIANT*)v)->Clear();
  818. *plFlavor = 0;
  819. int i = 0;
  820. //=============================================================
  821. // SOURCES_NAME
  822. //=============================================================
  823. if( _wcsicmp(pProperty,g_SourcesRowsetColumns[0].wcsColumnName) == 0 )
  824. {
  825. hr = GetClassProperty(L"Name",v,pType,plFlavor);
  826. }
  827. //=============================================================
  828. // SOURCES_PARSENAME
  829. //=============================================================
  830. else if( _wcsicmp(pProperty,g_SourcesRowsetColumns[1].wcsColumnName) == 0 )
  831. {
  832. hr = GetClassProperty(L"__PATH",v,pType,plFlavor);
  833. }
  834. else
  835. {
  836. //=============================================================
  837. // Initialize the common stuff for these last column types
  838. //=============================================================
  839. *plFlavor = 0;
  840. //=============================================================
  841. // SOURCES_DESCRIPTION
  842. //=============================================================
  843. if( _wcsicmp(pProperty,g_SourcesRowsetColumns[2].wcsColumnName) == 0 ){
  844. *pType = CIM_STRING;
  845. ((CVARIANT*)v)->SetStr(L"N/A");
  846. }
  847. //=============================================================
  848. // SOURCES_TYPE
  849. //=============================================================
  850. else if( _wcsicmp(pProperty,g_SourcesRowsetColumns[3].wcsColumnName) == 0 ){
  851. *pType = CIM_UINT16;
  852. ((CVARIANT*)v)->SetShort(DBSOURCETYPE_DATASOURCE);
  853. }
  854. //=============================================================
  855. // SOURCES_ISPARENT
  856. //=============================================================
  857. else if( _wcsicmp(pProperty,g_SourcesRowsetColumns[4].wcsColumnName) == 0 ){
  858. *pType = CIM_BOOLEAN;
  859. ((CVARIANT*)v)->SetBool(VARIANT_FALSE);
  860. }
  861. else{
  862. hr = E_INVALIDARG;
  863. }
  864. }
  865. return MapWbemErrorToOLEDBError(hr);
  866. }
  867. ///////////////////////////////////////////////////////////////////////////////////////////////////
  868. HRESULT CWbemSchemaSourcesInstanceList::Reset()
  869. {
  870. HRESULT hr = E_UNEXPECTED;
  871. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  872. //============================================================
  873. // Send off the query for "Select Name from __Namespace
  874. //============================================================
  875. if( m_ppEnum )
  876. {
  877. hr = m_ppEnum->Reset();
  878. ReleaseAllInstances();
  879. }
  880. else
  881. {
  882. hr = (m_pParms->GetServicesPtr())->ExecQuery(CBSTR((WCHAR *)szWQL),CBSTR(L"select * from __Namespace"), WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  883. }
  884. m_lCurrentPos = 0;
  885. return MapWbemErrorToOLEDBError(hr);
  886. }
  887. //********************************************************************************************
  888. //////////////////////////////////////////////////////////////////////////////////////////////
  889. //
  890. // Classes for the Provider Types schema rowset
  891. //
  892. //////////////////////////////////////////////////////////////////////////////////////////////
  893. //********************************************************************************************
  894. CWbemSchemaProviderTypesClassDefinitionWrapper::CWbemSchemaProviderTypesClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  895. {
  896. m_nMaxColumns = sizeof(g_ProviderTypes)/sizeof(SchemaRowsetDefinition);
  897. }
  898. //////////////////////////////////////////////////////////////////////////////////////////////
  899. HRESULT CWbemSchemaProviderTypesClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  900. {
  901. HRESULT hr = S_OK;
  902. //===============================================================================
  903. // See if we got all of the column info
  904. //===============================================================================
  905. if( m_nSchemaClassIndex == m_nMaxColumns )
  906. {
  907. return WBEM_S_NO_MORE_DATA;
  908. }
  909. //===============================================================================
  910. // Get the column name and data type
  911. //===============================================================================
  912. *pType = g_ProviderTypes[m_nSchemaClassIndex].Type;
  913. *pProperty = Wmioledb_SysAllocString(g_ProviderTypes[m_nSchemaClassIndex].wcsColumnName);
  914. m_nSchemaClassIndex++;
  915. return hr;
  916. }
  917. //////////////////////////////////////////////////////////////////////////////////////////////////
  918. HRESULT CWbemSchemaProviderTypesInstanceWrapper::ResetInstanceFromKey(CBSTR Key)
  919. {
  920. return S_OK;
  921. }
  922. //////////////////////////////////////////////////////////////////////////////////////////////////
  923. HRESULT CWbemSchemaProviderTypesInstanceWrapper::RefreshInstance()
  924. {
  925. return S_OK;
  926. }
  927. //////////////////////////////////////////////////////////////////////////////////////////////////
  928. WCHAR * CWbemSchemaProviderTypesInstanceWrapper::GetClassName()
  929. {
  930. return L"PROVIDER_TYPES";
  931. }
  932. //////////////////////////////////////////////////////////////////////////////////////////////
  933. HRESULT CWbemSchemaProviderTypesInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * vVar,CIMTYPE * pType , LONG * plFlavor)
  934. {
  935. HRESULT hr = S_OK;
  936. ((CVARIANT*)vVar)->Clear();
  937. *plFlavor = 0;
  938. ULONG_PTR i = GetPos();
  939. //=============================================================
  940. // TYPE_NAME
  941. //=============================================================
  942. if( _wcsicmp(pProperty,g_ProviderTypes[0].wcsColumnName) == 0 ){
  943. *pType = CIM_STRING;
  944. ((CVARIANT*)vVar)->SetStr(g_ProviderTypeDetails[i].wcsTypeName);
  945. }
  946. //=============================================================
  947. // DATA_TYPE
  948. //=============================================================
  949. else if( _wcsicmp(pProperty,g_ProviderTypes[1].wcsColumnName) == 0 ){
  950. *pType = CIM_UINT16;
  951. ((CVARIANT*)vVar)->SetShort(g_ProviderTypeDetails[i].DataType);
  952. }
  953. //=============================================================
  954. // COLUMN_SIZE
  955. //=============================================================
  956. else if( _wcsicmp(pProperty,g_ProviderTypes[2].wcsColumnName) == 0 ){
  957. *pType = CIM_SINT32;
  958. ((CVARIANT*)vVar)->SetLONG(g_ProviderTypeDetails[i].ColumnSize);
  959. }
  960. //=============================================================
  961. // LITERAL_PREFIX, LITERAL_SUFFIX, CREATE_PARAMS
  962. //=============================================================
  963. else if(( _wcsicmp(pProperty,g_ProviderTypes[3].wcsColumnName) == 0 ) ||
  964. ( _wcsicmp(pProperty,g_ProviderTypes[4].wcsColumnName) == 0 ) ||
  965. ( _wcsicmp(pProperty,g_ProviderTypes[5].wcsColumnName) == 0 ) ){
  966. *pType = CIM_STRING;
  967. ((CVARIANT*)vVar)->SetStr(L"");
  968. }
  969. //=============================================================
  970. // IS_NULLABLE,CASE_SENSITIVE
  971. //=============================================================
  972. else if(( _wcsicmp(pProperty,g_ProviderTypes[6].wcsColumnName) == 0 ) ||
  973. ( _wcsicmp(pProperty,g_ProviderTypes[7].wcsColumnName) == 0 ) ){
  974. *pType = CIM_BOOLEAN;
  975. ((CVARIANT*)vVar)->SetBool(VARIANT_FALSE);
  976. }
  977. //=============================================================
  978. // SEARCHABLE
  979. //=============================================================
  980. else if( _wcsicmp(pProperty,g_ProviderTypes[8].wcsColumnName) == 0 ){
  981. *pType = CIM_UINT32;
  982. ((CVARIANT*)vVar)->SetLONG(0);
  983. }
  984. //=============================================================
  985. // UNSIGNED_ATTRIBUTE
  986. //=============================================================
  987. else if( _wcsicmp(pProperty,g_ProviderTypes[9].wcsColumnName) == 0 ){
  988. *pType = CIM_BOOLEAN;
  989. ((CVARIANT*)vVar)->SetShort((short)g_ProviderTypeDetails[i].UnsignedAttribute);
  990. }
  991. //=============================================================
  992. // FIXED_PREC_SCALE, AUTO_UNIQUE_VALUE
  993. //=============================================================
  994. else if(( _wcsicmp(pProperty,g_ProviderTypes[10].wcsColumnName) == 0 ) ||
  995. ( _wcsicmp(pProperty,g_ProviderTypes[11].wcsColumnName) == 0 ) ){
  996. *pType = CIM_BOOLEAN;
  997. ((CVARIANT*)vVar)->SetBool(VARIANT_FALSE);
  998. }
  999. //=============================================================
  1000. // LOCAL_TYPE_NAME
  1001. //=============================================================
  1002. else if( _wcsicmp(pProperty,g_ProviderTypes[12].wcsColumnName) == 0 ){
  1003. *pType = CIM_STRING;
  1004. ((CVARIANT*)vVar)->SetStr(L"");
  1005. }
  1006. //=============================================================
  1007. // MINIMUM_SCALE, MAXIMUM_SCALE
  1008. //=============================================================
  1009. else if(( _wcsicmp(pProperty,g_ProviderTypes[13].wcsColumnName) == 0 ) ||
  1010. ( _wcsicmp(pProperty,g_ProviderTypes[14].wcsColumnName) == 0 )){
  1011. *pType = CIM_SINT16;
  1012. ((CVARIANT*)vVar)->SetShort(0);
  1013. }
  1014. //=============================================================
  1015. // GUID
  1016. //=============================================================
  1017. else if( _wcsicmp(pProperty,g_ProviderTypes[15].wcsColumnName) == 0 ){
  1018. *pType = DBTYPE_GUID;
  1019. ((CVARIANT*)vVar)->Clear();
  1020. }
  1021. //=============================================================
  1022. // TYPELIB
  1023. //=============================================================
  1024. else if( _wcsicmp(pProperty,g_ProviderTypes[16].wcsColumnName) == 0 ){
  1025. *pType = CIM_STRING;
  1026. ((CVARIANT*)vVar)->SetStr(L"");
  1027. }
  1028. //=============================================================
  1029. // VERSION
  1030. //=============================================================
  1031. else if( _wcsicmp(pProperty,g_ProviderTypes[17].wcsColumnName) == 0 ){
  1032. *pType = CIM_STRING;
  1033. ((CVARIANT*)vVar)->SetStr(L"");
  1034. }
  1035. //=============================================================
  1036. // IS_LONG for CIM_STRING which will be BSTR
  1037. //=============================================================
  1038. else if( ( _wcsicmp(pProperty,g_ProviderTypes[18].wcsColumnName) == 0 ) &&
  1039. g_ProviderTypeDetails[i].DataType == DBTYPE_BSTR)
  1040. {
  1041. *pType = CIM_BOOLEAN;
  1042. ((CVARIANT*)vVar)->SetBool(TRUE);
  1043. }
  1044. //=============================================================
  1045. // IS_FIXEDLENGTH for CIM_STRING be FALSE
  1046. //=============================================================
  1047. else if( ( _wcsicmp(pProperty,g_ProviderTypes[20].wcsColumnName) == 0 ) &&
  1048. g_ProviderTypeDetails[i].DataType == DBTYPE_BSTR)
  1049. {
  1050. *pType = CIM_BOOLEAN;
  1051. ((CVARIANT*)vVar)->SetBool(FALSE);
  1052. }
  1053. //=============================================================
  1054. // IS_FIXEDLENGTH for all types apart from CIM_STRING TRUE
  1055. //=============================================================
  1056. else if( ( _wcsicmp(pProperty,g_ProviderTypes[20].wcsColumnName) == 0 ) &&
  1057. g_ProviderTypeDetails[i].DataType != DBTYPE_BSTR )
  1058. {
  1059. *pType = CIM_BOOLEAN;
  1060. ((CVARIANT*)vVar)->SetBool(TRUE);
  1061. }
  1062. //=============================================================
  1063. // IS_LONG, BEST_MATCH
  1064. //=============================================================
  1065. else if(( _wcsicmp(pProperty,g_ProviderTypes[18].wcsColumnName) == 0 ) ||
  1066. ( _wcsicmp(pProperty,g_ProviderTypes[19].wcsColumnName) == 0 ) ) {
  1067. *pType = CIM_BOOLEAN;
  1068. ((CVARIANT*)vVar)->SetBool(FALSE);
  1069. }
  1070. /* //=============================================================
  1071. // IS_LONG, BEST_MATCH, IS_FIXEDLENGTH
  1072. //=============================================================
  1073. else if(( _wcsicmp(pProperty,g_ProviderTypes[18].wcsColumnName) == 0 ) ||
  1074. ( _wcsicmp(pProperty,g_ProviderTypes[19].wcsColumnName) == 0 ) ||
  1075. ( _wcsicmp(pProperty,g_ProviderTypes[20].wcsColumnName) == 0 )) {
  1076. *pType = CIM_BOOLEAN;
  1077. ((CVARIANT*)vVar)->SetBool(VARIANT_FALSE);
  1078. }
  1079. */
  1080. //=============================================================
  1081. // INVALID_ARG
  1082. //=============================================================
  1083. else{
  1084. hr = E_INVALIDARG;
  1085. }
  1086. return MapWbemErrorToOLEDBError(hr);
  1087. }
  1088. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1089. HRESULT CWbemSchemaProviderTypesInstanceWrapper::GetKey(CBSTR & Key)
  1090. {
  1091. HRESULT hr = S_OK;
  1092. Key.SetStr(g_ProviderTypeDetails[GetPos()].wcsTypeName);
  1093. return hr;
  1094. }
  1095. //////////////////////////////////////////////////////////////////////////////////////////////////
  1096. HRESULT CWbemSchemaProviderTypesInstanceList::Reset()
  1097. {
  1098. HRESULT hr = E_UNEXPECTED;
  1099. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  1100. //============================================================
  1101. // Send off the query for "Select Name from __Namespace
  1102. //============================================================
  1103. if( m_ppEnum ){
  1104. hr = m_ppEnum->Reset();
  1105. ReleaseAllInstances();
  1106. }
  1107. else
  1108. {
  1109. m_ulMaxRow = sizeof(g_ProviderTypeDetails)/sizeof(CIMTypeInfo);
  1110. hr = S_OK; // hardcoded rowset
  1111. }
  1112. m_lCurrentPos = 0;
  1113. return MapWbemErrorToOLEDBError(hr);
  1114. }
  1115. ////////////////////////////////////////////////////////////////////////////////////////////////
  1116. HRESULT CWbemSchemaProviderTypesInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  1117. {
  1118. HRESULT hr = E_FAIL;
  1119. if( m_lCurrentPos < m_ulMaxRow )
  1120. {
  1121. *pInst = new CWbemSchemaProviderTypesInstanceWrapper(m_pParms);
  1122. // NTRaid:136533
  1123. // 07/05/00
  1124. if(*pInst)
  1125. {
  1126. (*pInst)->SetPos(++m_lCurrentPos);
  1127. AddInstance(*pInst);
  1128. (*pInst)->GetKey(Key);
  1129. hr = S_OK;
  1130. }
  1131. else
  1132. {
  1133. hr = E_OUTOFMEMORY;
  1134. }
  1135. }
  1136. else
  1137. {
  1138. hr = WBEM_S_NO_MORE_DATA;
  1139. }
  1140. return hr;
  1141. }
  1142. //********************************************************************************************
  1143. //////////////////////////////////////////////////////////////////////////////////////////////
  1144. //
  1145. // Classes for the Catalogs schema rowset
  1146. //
  1147. //********************************************************************************************
  1148. //////////////////////////////////////////////////////////////////////////////////////////////
  1149. CWbemSchemaCatalogsClassDefinitionWrapper::CWbemSchemaCatalogsClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  1150. {
  1151. m_nMaxColumns = sizeof(g_CatalogRowsetColumns)/sizeof(SchemaRowsetDefinition);
  1152. }
  1153. //////////////////////////////////////////////////////////////////////////////////////////////
  1154. HRESULT CWbemSchemaCatalogsClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1155. {
  1156. HRESULT hr = S_OK;
  1157. //===============================================================================
  1158. // See if we got all of the column info
  1159. //===============================================================================
  1160. if( m_nSchemaClassIndex == m_nMaxColumns )
  1161. {
  1162. return WBEM_S_NO_MORE_DATA;
  1163. }
  1164. *pType = g_CatalogRowsetColumns[m_nSchemaClassIndex].Type;
  1165. *pProperty = Wmioledb_SysAllocString(g_CatalogRowsetColumns[m_nSchemaClassIndex].wcsColumnName);
  1166. m_nSchemaClassIndex++;
  1167. return hr;
  1168. }
  1169. //////////////////////////////////////////////////////////////////////////////////////////////
  1170. HRESULT CWbemSchemaCatalogsInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  1171. {
  1172. HRESULT hr = S_OK;
  1173. ((CVARIANT*)v)->Clear();
  1174. *plFlavor = 0;
  1175. //=============================================================
  1176. // CATALOG_NAME
  1177. //=============================================================
  1178. if( _wcsicmp(pProperty,g_CatalogRowsetColumns[0].wcsColumnName) == 0 ){
  1179. hr = m_pClass->Get(CBSTR(L"Name"),0,(VARIANT *)v,pType,plFlavor);
  1180. }
  1181. //=============================================================
  1182. // SOURCES_DESCRIPTION
  1183. //=============================================================
  1184. else if( _wcsicmp(pProperty,g_CatalogRowsetColumns[1].wcsColumnName) == 0 ){
  1185. *plFlavor = 0;
  1186. *pType = CIM_STRING;
  1187. ((CVARIANT*)v)->SetStr(L"N/A");
  1188. }
  1189. return MapWbemErrorToOLEDBError(hr);
  1190. }
  1191. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1192. HRESULT CWbemSchemaCatalogsInstanceList::Reset()
  1193. {
  1194. HRESULT hr = E_UNEXPECTED;
  1195. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  1196. //============================================================
  1197. // Send off the query for "Select Name from __Namespace
  1198. //============================================================
  1199. if( m_ppEnum )
  1200. {
  1201. hr = m_ppEnum->Reset();
  1202. ReleaseAllInstances();
  1203. }
  1204. else
  1205. {
  1206. hr = (m_pParms->GetServicesPtr())->ExecQuery(CBSTR((WCHAR *)szWQL),CBSTR(L"select * from __Namespace"), WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  1207. }
  1208. m_lCurrentPos = 0;
  1209. return MapWbemErrorToOLEDBError(hr);
  1210. }
  1211. //********************************************************************************************
  1212. //////////////////////////////////////////////////////////////////////////////////////////////
  1213. //
  1214. // Classes for the COlumns schema rowset
  1215. //
  1216. //********************************************************************************************
  1217. //////////////////////////////////////////////////////////////////////////////////////////////
  1218. CWbemSchemaColumnsClassDefinitionWrapper::CWbemSchemaColumnsClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  1219. {
  1220. m_nMaxColumns = sizeof(g_ColumnsRowsetColumns)/sizeof(SchemaRowsetDefinition);
  1221. }
  1222. //////////////////////////////////////////////////////////////////////////////////////////////
  1223. HRESULT CWbemSchemaColumnsClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1224. {
  1225. HRESULT hr = S_OK;
  1226. //===============================================================================
  1227. // See if we got all of the column info
  1228. //===============================================================================
  1229. if( m_nSchemaClassIndex == m_nMaxColumns )
  1230. {
  1231. return WBEM_S_NO_MORE_DATA;
  1232. }
  1233. *pType = g_ColumnsRowsetColumns[m_nSchemaClassIndex].Type;
  1234. *pProperty = Wmioledb_SysAllocString(g_ColumnsRowsetColumns[m_nSchemaClassIndex].wcsColumnName);
  1235. m_nSchemaClassIndex++;
  1236. return hr;
  1237. }
  1238. //////////////////////////////////////////////////////////////////////////////////////////////
  1239. HRESULT CWbemSchemaColumnsInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  1240. {
  1241. HRESULT hr = S_OK;
  1242. ((CVARIANT*)v)->Clear();
  1243. *plFlavor = 0;
  1244. //=============================================================
  1245. // TABLE_CATALOG
  1246. //=============================================================
  1247. if( wcscmp(pProperty,g_ColumnsRowsetColumns[0].wcsColumnName) == 0 ){
  1248. *pType = CIM_STRING;
  1249. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  1250. }
  1251. //=============================================================
  1252. // TABLE_SCHEMA
  1253. //=============================================================
  1254. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[1].wcsColumnName) == 0 ){
  1255. *pType = CIM_STRING;
  1256. }
  1257. //=============================================================
  1258. // TABLE_NAME
  1259. //=============================================================
  1260. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[2].wcsColumnName) == 0 ){
  1261. ((CVARIANT*)v)->SetStr(m_pParms->m_pwcsParentClassName);
  1262. }
  1263. //=============================================================
  1264. // COLUMN_NAME
  1265. //=============================================================
  1266. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[3].wcsColumnName) == 0 ){
  1267. *pType = CIM_STRING;
  1268. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1269. ((CVARIANT*)v)->SetStr(pCol->pwszName);
  1270. }
  1271. //=============================================================
  1272. // COLUMN_GUID
  1273. //=============================================================
  1274. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[4].wcsColumnName) == 0 ){
  1275. *pType = DBTYPE_GUID;
  1276. }
  1277. //=============================================================
  1278. // COLUMN_PROPID
  1279. //=============================================================
  1280. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[5].wcsColumnName) == 0 ){
  1281. *pType = CIM_UINT32;
  1282. }
  1283. //=============================================================
  1284. // ORDINAL_POSITION
  1285. //=============================================================
  1286. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[6].wcsColumnName) == 0 ){
  1287. *pType = CIM_UINT32;
  1288. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1289. ((CVARIANT*)v)->SetLONG((LONG)pCol->iOrdinal);
  1290. }
  1291. //=============================================================
  1292. // COLUMN_HASDEFAULT
  1293. //=============================================================
  1294. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[7].wcsColumnName) == 0 ){
  1295. *pType = CIM_BOOLEAN;
  1296. ((CVARIANT*)v)->SetBool(VARIANT_FALSE);
  1297. }
  1298. //=============================================================
  1299. // COLUMN_DEFAULT
  1300. //=============================================================
  1301. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[8].wcsColumnName) == 0 ){
  1302. *pType = CIM_STRING;
  1303. }
  1304. //=============================================================
  1305. // COLUMN_FLAGS
  1306. //=============================================================
  1307. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[9].wcsColumnName) == 0 ){
  1308. *pType = CIM_UINT32;
  1309. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1310. ((CVARIANT*)v)->SetLONG(pCol->dwFlags);
  1311. }
  1312. //=============================================================
  1313. // IS_NULLABLE
  1314. //=============================================================
  1315. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[10].wcsColumnName) == 0 ){
  1316. *pType = CIM_BOOLEAN;
  1317. ((CVARIANT*)v)->SetBool(VARIANT_TRUE);
  1318. }
  1319. //=============================================================
  1320. // DATA_TYPE
  1321. //=============================================================
  1322. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[11].wcsColumnName) == 0 ){
  1323. *pType = CIM_UINT16;
  1324. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1325. ((CVARIANT*)v)->SetLONG(pCol->wType);
  1326. }
  1327. //=============================================================
  1328. // TYPE_GUID
  1329. //=============================================================
  1330. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[12].wcsColumnName) == 0 ){
  1331. *pType = DBTYPE_GUID;
  1332. }
  1333. //=============================================================
  1334. // CHARACTER_MAXIMUM_LENGTH
  1335. //=============================================================
  1336. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[13].wcsColumnName) == 0 )
  1337. {
  1338. *pType = CIM_UINT32;
  1339. }
  1340. //=============================================================
  1341. // CHARACTER_OCTET_LENGTH
  1342. //=============================================================
  1343. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[14].wcsColumnName) == 0 ){
  1344. *pType = CIM_UINT32;
  1345. }
  1346. //=============================================================
  1347. // NUMERIC_PRECISION
  1348. //=============================================================
  1349. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[15].wcsColumnName) == 0 ){
  1350. *pType = CIM_UINT16;
  1351. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1352. ((CVARIANT*)v)->SetShort(pCol->bPrecision);
  1353. }
  1354. //=============================================================
  1355. // NUMERIC_SCALE
  1356. //=============================================================
  1357. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[16].wcsColumnName) == 0 ){
  1358. *pType = CIM_SINT16;
  1359. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1360. ((CVARIANT*)v)->SetShort(pCol->bScale);
  1361. }
  1362. //=============================================================
  1363. // DATETIME_PRECISION
  1364. //=============================================================
  1365. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[17].wcsColumnName) == 0 ){
  1366. *pType = CIM_UINT32;
  1367. }
  1368. //=============================================================
  1369. // CHARACTER_SET_CATALOG
  1370. //=============================================================
  1371. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[18].wcsColumnName) == 0 ){
  1372. *pType = CIM_STRING;
  1373. }
  1374. //=============================================================
  1375. // CHARACTER_SET_SCHEMA
  1376. //=============================================================
  1377. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[19].wcsColumnName) == 0 ){
  1378. *pType = CIM_STRING;
  1379. }
  1380. //=============================================================
  1381. // CHARACTER_SET_NAME
  1382. //=============================================================
  1383. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[20].wcsColumnName) == 0 ){
  1384. *pType = CIM_STRING;
  1385. }
  1386. //=============================================================
  1387. // COLLATION_CATALOG
  1388. //=============================================================
  1389. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[21].wcsColumnName) == 0 ){
  1390. *pType = CIM_STRING;
  1391. }
  1392. //=============================================================
  1393. // COLLATION_SCHEMA
  1394. //=============================================================
  1395. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[22].wcsColumnName) == 0 ){
  1396. *pType = CIM_STRING;
  1397. }
  1398. //=============================================================
  1399. // COLLATION_NAME
  1400. //=============================================================
  1401. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[23].wcsColumnName) == 0 ){
  1402. *pType = CIM_STRING;
  1403. }
  1404. //=============================================================
  1405. // DOMAIN_CATALOG
  1406. //=============================================================
  1407. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[24].wcsColumnName) == 0 ){
  1408. *pType = CIM_STRING;
  1409. }
  1410. //=============================================================
  1411. // DOMAIN_SCHEMA
  1412. //=============================================================
  1413. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[25].wcsColumnName) == 0 ){
  1414. *pType = CIM_STRING;
  1415. }
  1416. //=============================================================
  1417. // DOMAIN_NAME
  1418. //=============================================================
  1419. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[26].wcsColumnName) == 0 ){
  1420. *pType = CIM_STRING;
  1421. }
  1422. //=============================================================
  1423. // DESCRIPTION
  1424. //=============================================================
  1425. else if( _wcsicmp(pProperty,g_ColumnsRowsetColumns[27].wcsColumnName) == 0 ){
  1426. *pType = CIM_STRING;
  1427. }
  1428. return MapWbemErrorToOLEDBError(hr);
  1429. }
  1430. //////////////////////////////////////////////////////////////////////////////////////////////////
  1431. HRESULT CWbemSchemaColumnsInstanceWrapper::GetKey(CBSTR & Key)
  1432. {
  1433. HRESULT hr = S_OK;
  1434. if( m_pColumns )
  1435. {
  1436. //============================================================
  1437. // the key is the combo of the table name and column name
  1438. //============================================================
  1439. DBCOLUMNINFO * pCol = m_pColumns->GetColInfo(m_uCurrentIndex);
  1440. if( pCol )
  1441. {
  1442. WCHAR * p = new WCHAR [wcslen(pCol->pwszName) + wcslen(m_pParms->m_pwcsParentClassName) + 4 ];
  1443. if( p )
  1444. {
  1445. swprintf(p, L"%s:%s", m_pParms->m_pwcsParentClassName,pCol->pwszName);
  1446. Key.SetStr(p);
  1447. delete p;
  1448. }
  1449. }
  1450. }
  1451. return hr;
  1452. }
  1453. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1454. HRESULT CWbemSchemaColumnsInstanceList::Reset()
  1455. {
  1456. HRESULT hr = E_UNEXPECTED;
  1457. //============================================================
  1458. // If we are working with just one class, then get the one
  1459. // class, otherwise enumerate all
  1460. //============================================================
  1461. if( m_pwcsSpecificClass)
  1462. {
  1463. hr = ResetTheSpecificClass();
  1464. }
  1465. else
  1466. {
  1467. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  1468. //============================================================
  1469. // Send off the query for "Select Name from __Namespace
  1470. //============================================================
  1471. if( m_ppEnum )
  1472. {
  1473. hr = m_ppEnum->Reset();
  1474. ReleaseAllInstances();
  1475. }
  1476. else
  1477. {
  1478. hr = (m_pParms->GetServicesPtr())->CreateClassEnum(NULL, WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  1479. }
  1480. }
  1481. m_lCurrentPos = 0;
  1482. return MapWbemErrorToOLEDBError(hr);
  1483. }
  1484. ////////////////////////////////////////////////////////////////////////////////////////////////
  1485. HRESULT CWbemSchemaColumnsInstanceList::GetColumnInformation(CWbemClassInstanceWrapper * p )
  1486. {
  1487. HRESULT hr = E_FAIL;
  1488. DBCOUNTITEM cTotalCols, cCols, cNestedCols;
  1489. FreeColumns();
  1490. CWmiOleDBMap Map;
  1491. if(SUCCEEDED(hr = Map.FInit(m_pParms->m_dwFlags,p->GetClassName(),m_pParms->m_pConnection)))
  1492. {
  1493. hr = Map.GetColumnCount(cTotalCols,cCols,cNestedCols);
  1494. if( S_OK == hr ){
  1495. if( S_OK == (hr = m_Columns.AllocColumnNameList(cTotalCols))){
  1496. //===============================================================================
  1497. // Allocate the DBCOLUMNINFO structs to match the number of columns
  1498. //===============================================================================
  1499. if( S_OK == (hr = m_Columns.AllocColumnInfoList(cTotalCols))){
  1500. hr = Map.GetColumnInfoForParentColumns(&m_Columns);
  1501. if( hr == S_OK ){
  1502. //==============================================================
  1503. // Increment past the bookmark column
  1504. //==============================================================
  1505. m_lColumnIndex = 1;
  1506. ((CWbemSchemaColumnsInstanceWrapper*)p)->SetColumnsPtr(&m_Columns);
  1507. ((CWbemSchemaColumnsInstanceWrapper*)p)->SetIndex(m_lColumnIndex);
  1508. }
  1509. }
  1510. }
  1511. }
  1512. }
  1513. return hr;
  1514. }
  1515. ////////////////////////////////////////////////////////////////////////////////////////////////
  1516. HRESULT CWbemSchemaColumnsInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  1517. {
  1518. HRESULT hr = E_FAIL;
  1519. long ulTotal;
  1520. ulTotal = (LONG)m_Columns.GetTotalNumberOfColumns();
  1521. m_lColumnIndex++;
  1522. if( m_lColumnIndex >= ulTotal )
  1523. {
  1524. //================================================================
  1525. // If we are working with a specific class, then use it, other
  1526. // wise, enumerate the next one
  1527. //================================================================
  1528. if( !m_pwcsSpecificClass)
  1529. {
  1530. hr = CWbemInstanceList::NextInstance(Key,pInst);
  1531. if( S_OK == hr )
  1532. {
  1533. CVARIANT v;
  1534. CIMTYPE Type;
  1535. LONG lFlavor;
  1536. if( S_OK == (hr = ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->GetClassProperty(L"__CLASS",&v,&Type,&lFlavor)))
  1537. {
  1538. // Now, save it in Parameters for the generated ones
  1539. m_pParms->SetParentClassName(v.GetStr());
  1540. hr = GetColumnInformation(*pInst);
  1541. if( S_OK == hr )
  1542. {
  1543. //==========================================
  1544. // We don't want to display the bookmark
  1545. // column.
  1546. //==========================================
  1547. ulTotal = (LONG)m_Columns.GetTotalNumberOfColumns();
  1548. if( m_lColumnIndex == ulTotal )
  1549. {
  1550. hr = NextInstance(Key,pInst);
  1551. }
  1552. }
  1553. hr = ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->GetKey(Key);
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. hr = GetTheSpecificClass();
  1560. if( S_OK == hr )
  1561. {
  1562. *pInst = (CWbemSchemaClassInstanceWrapper *) new CWbemSchemaColumnsInstanceWrapper(m_pParms);
  1563. if( *pInst )
  1564. {
  1565. ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->SetClass(m_pSpecificClass);
  1566. CVARIANT v;
  1567. CIMTYPE Type;
  1568. LONG lFlavor;
  1569. if( S_OK == (hr = ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->GetClassProperty(L"__CLASS",&v,&Type,&lFlavor)))
  1570. {
  1571. m_pParms->SetParentClassName(v.GetStr());
  1572. if( SUCCEEDED(hr))
  1573. {
  1574. hr = GetColumnInformation(*pInst);
  1575. ulTotal = (LONG)m_Columns.GetTotalNumberOfColumns();
  1576. //===================================================================
  1577. // This class does't have any columns
  1578. //===================================================================
  1579. if( m_lColumnIndex == ulTotal )
  1580. {
  1581. hr = WBEM_S_NO_MORE_DATA;
  1582. }
  1583. if( S_OK == hr)
  1584. {
  1585. hr = ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->GetKey(Key);
  1586. (*pInst)->SetPos(++m_lCurrentPos);
  1587. ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->SetColumnsPtr(&m_Columns);
  1588. ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->SetIndex(m_lColumnIndex);
  1589. AddInstance(*pInst);
  1590. }
  1591. }
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. *pInst = (CWbemSchemaClassInstanceWrapper *) new CWbemSchemaColumnsInstanceWrapper(m_pParms);
  1600. if( *pInst )
  1601. {
  1602. (*pInst)->SetPos(++m_lCurrentPos);
  1603. ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->SetColumnsPtr(&m_Columns);
  1604. ((CWbemSchemaColumnsInstanceWrapper*)*pInst)->SetIndex(m_lColumnIndex);
  1605. (*pInst)->GetKey(Key);
  1606. AddInstance(*pInst);
  1607. hr = S_OK;
  1608. }
  1609. }
  1610. return hr;
  1611. }
  1612. //********************************************************************************************
  1613. //////////////////////////////////////////////////////////////////////////////////////////////
  1614. //
  1615. // Classes for the Tables schema rowset
  1616. //
  1617. //********************************************************************************************
  1618. //////////////////////////////////////////////////////////////////////////////////////////////
  1619. CWbemSchemaTablesClassDefinitionWrapper::CWbemSchemaTablesClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  1620. {
  1621. m_nMaxColumns = sizeof(g_Tables)/sizeof(SchemaRowsetDefinition);
  1622. }
  1623. //////////////////////////////////////////////////////////////////////////////////////////////
  1624. HRESULT CWbemSchemaTablesClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1625. {
  1626. HRESULT hr = S_OK;
  1627. //===============================================================================
  1628. // See if we got all of the column info
  1629. //===============================================================================
  1630. if( m_nSchemaClassIndex == m_nMaxColumns )
  1631. {
  1632. return WBEM_S_NO_MORE_DATA;
  1633. }
  1634. *pType = g_Tables[m_nSchemaClassIndex].Type;
  1635. *pProperty = Wmioledb_SysAllocString(g_Tables[m_nSchemaClassIndex].wcsColumnName);
  1636. m_nSchemaClassIndex++;
  1637. return hr;
  1638. }
  1639. //////////////////////////////////////////////////////////////////////////////////////////////
  1640. HRESULT CWbemSchemaTablesInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  1641. {
  1642. HRESULT hr = S_OK;
  1643. ((CVARIANT*)v)->Clear();
  1644. *plFlavor = 0;
  1645. //=============================================================
  1646. // TABLE_CATALOG
  1647. //=============================================================
  1648. if( _wcsicmp(pProperty,g_Tables[0].wcsColumnName) == 0 ){
  1649. *pType = CIM_STRING;
  1650. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  1651. }
  1652. //=============================================================
  1653. // TABLE_SCHEMA
  1654. //=============================================================
  1655. else if( _wcsicmp(pProperty,g_Tables[1].wcsColumnName) == 0 ){
  1656. *pType = CIM_STRING;
  1657. }
  1658. //=============================================================
  1659. // TABLE_NAME
  1660. //=============================================================
  1661. else if( _wcsicmp(pProperty,g_Tables[2].wcsColumnName) == 0 ){
  1662. *pType = CIM_STRING;
  1663. hr = GetClassProperty(L"__CLASS",v,pType,plFlavor);
  1664. }
  1665. //=============================================================
  1666. // TABLE_TYPE
  1667. // This is either "TABLE" or "SYSTEM TABLE"
  1668. //=============================================================
  1669. else if( _wcsicmp(pProperty,g_Tables[3].wcsColumnName) == 0 ){
  1670. *pType = CIM_STRING;
  1671. CVARIANT Var;
  1672. hr = GetClassProperty(L"__CLASS",&Var,pType,plFlavor);
  1673. if( S_OK == hr ){
  1674. WCHAR * p = NULL;
  1675. p = Var.GetStr();
  1676. // NTRaid:136462 & 136466
  1677. // 07/05/00
  1678. if(p != NULL || VT_BSTR != Var.GetType())
  1679. {
  1680. if( wcsncmp( p, L"__",2) == 0 ){
  1681. ((CVARIANT*)v)->SetStr(L"SYSTEM TABLE");
  1682. }
  1683. else{
  1684. ((CVARIANT*)v)->SetStr(L"TABLE");
  1685. }
  1686. }
  1687. else
  1688. {
  1689. hr = E_UNEXPECTED;
  1690. }
  1691. }
  1692. }
  1693. //=============================================================
  1694. // TABLE_GUID
  1695. //=============================================================
  1696. else if( _wcsicmp(pProperty,g_Tables[4].wcsColumnName) == 0 ){
  1697. *pType = DBTYPE_GUID;
  1698. }
  1699. //=============================================================
  1700. // TABLE_DESCRIPTION
  1701. //=============================================================
  1702. else if( _wcsicmp(pProperty,g_Tables[5].wcsColumnName) == 0 ){
  1703. *pType = CIM_STRING;
  1704. hr = GetClassQualifier(L"Description",v,pType,plFlavor);
  1705. }
  1706. //=============================================================
  1707. // TABLE_PROPID
  1708. //=============================================================
  1709. else if( _wcsicmp(pProperty,g_Tables[6].wcsColumnName) == 0 ){
  1710. *pType = CIM_UINT32;
  1711. }
  1712. //=============================================================
  1713. // DATE_CREATED, DATE_MODIFIED
  1714. //=============================================================
  1715. else if( _wcsicmp(pProperty,g_Tables[7].wcsColumnName) == 0 ){
  1716. *pType = DBTYPE_DATE;
  1717. }
  1718. return MapWbemErrorToOLEDBError(hr);
  1719. }
  1720. ////////////////////////////////////////////////////////////////////////////////////////////////
  1721. HRESULT CWbemSchemaTablesInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  1722. {
  1723. HRESULT hr = S_OK;
  1724. if( !m_pwcsSpecificClass )
  1725. {
  1726. return CWbemInstanceList::NextInstance(Key,pInst);
  1727. }
  1728. hr = GetTheSpecificClass();
  1729. if( S_OK == hr )
  1730. {
  1731. *pInst = (CWbemSchemaTablesInstanceWrapper *) new CWbemSchemaTablesInstanceWrapper(m_pParms);
  1732. // NTRaid:136526 , 136530
  1733. // 07/05/00
  1734. if(*pInst)
  1735. {
  1736. (*pInst)->SetClass(m_pSpecificClass);
  1737. (*pInst)->SetPos(++m_lCurrentPos);
  1738. AddInstance(*pInst);
  1739. (*pInst)->GetKey(Key);
  1740. }
  1741. else
  1742. {
  1743. hr = E_OUTOFMEMORY;
  1744. }
  1745. }
  1746. return hr;
  1747. }
  1748. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1749. HRESULT CWbemSchemaTablesInstanceList::Reset()
  1750. {
  1751. HRESULT hr = E_UNEXPECTED;
  1752. if( m_pwcsSpecificClass)
  1753. {
  1754. hr = ResetTheSpecificClass();
  1755. }
  1756. else
  1757. {
  1758. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  1759. //============================================================
  1760. // Send off the query for "Select Name from __Namespace
  1761. //============================================================
  1762. if( m_ppEnum )
  1763. {
  1764. hr = m_ppEnum->Reset();
  1765. ReleaseAllInstances();
  1766. }
  1767. else
  1768. {
  1769. hr = (m_pParms->GetServicesPtr())->CreateClassEnum(NULL, WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  1770. }
  1771. }
  1772. m_lCurrentPos = 0;
  1773. return MapWbemErrorToOLEDBError(hr);
  1774. }
  1775. //********************************************************************************************
  1776. //////////////////////////////////////////////////////////////////////////////////////////////
  1777. //
  1778. // Classes for the Primary Keys schema rowset
  1779. //
  1780. //********************************************************************************************
  1781. //////////////////////////////////////////////////////////////////////////////////////////////
  1782. CWbemSchemaPrimaryKeysClassDefinitionWrapper::CWbemSchemaPrimaryKeysClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  1783. {
  1784. m_nMaxColumns = sizeof(g_PrimaryKeysColumns)/sizeof(SchemaRowsetDefinition);
  1785. }
  1786. //////////////////////////////////////////////////////////////////////////////////////////////
  1787. HRESULT CWbemSchemaPrimaryKeysClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1788. {
  1789. HRESULT hr = S_OK;
  1790. //===============================================================================
  1791. // See if we got all of the column info
  1792. //===============================================================================
  1793. if( m_nSchemaClassIndex == m_nMaxColumns )
  1794. {
  1795. return WBEM_S_NO_MORE_DATA;
  1796. }
  1797. *pType = g_PrimaryKeysColumns[m_nSchemaClassIndex].Type;
  1798. *pProperty = Wmioledb_SysAllocString(g_PrimaryKeysColumns[m_nSchemaClassIndex].wcsColumnName);
  1799. m_nSchemaClassIndex++;
  1800. return hr;
  1801. }
  1802. //////////////////////////////////////////////////////////////////////////////////////////////
  1803. HRESULT CWbemSchemaPrimaryKeysInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  1804. {
  1805. HRESULT hr = S_OK;
  1806. ((CVARIANT*)v)->Clear();
  1807. *plFlavor = 0;
  1808. //=============================================================
  1809. // TABLE_CATALOG
  1810. //=============================================================
  1811. if( _wcsicmp(pProperty,g_PrimaryKeysColumns[0].wcsColumnName) == 0 )
  1812. {
  1813. *pType = CIM_STRING;
  1814. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  1815. }
  1816. //=============================================================
  1817. // TABLE_SCHEMA
  1818. //=============================================================
  1819. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[1].wcsColumnName) == 0 )
  1820. {
  1821. *pType = CIM_STRING;
  1822. }
  1823. //=============================================================
  1824. // TABLE_NAME
  1825. //=============================================================
  1826. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[2].wcsColumnName) == 0 ){
  1827. *pType = CIM_STRING;
  1828. hr = GetClassProperty(L"__CLASS",v,pType,plFlavor);
  1829. }
  1830. //=============================================================
  1831. // COLUMN_NAME
  1832. //=============================================================
  1833. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[3].wcsColumnName) == 0 ){
  1834. *pType = CIM_STRING;
  1835. LONG lFlavor = 0, lType = 0;
  1836. CBSTR bstrPropQual(L"key");
  1837. WCHAR * pList = NULL;
  1838. if( S_OK == (hr = BeginPropertyEnumeration())){
  1839. CBSTR bstrProperty;
  1840. CVARIANT vValue;
  1841. while( S_OK == (hr = GetNextProperty((BSTR*)&bstrProperty,(VARIANT *)&vValue, &lType, &lFlavor))){
  1842. CVARIANT vKey;
  1843. hr = CWbemClassWrapper::GetPropertyQualifier(bstrProperty,bstrPropQual,(VARIANT *)&vKey,&lType,&lFlavor);
  1844. if( S_OK == hr ){
  1845. //===========================================================
  1846. // Ok, we found a key, so start adding it. There could be
  1847. // multiple keys, so we still
  1848. //===========================================================
  1849. AddToKeyList(pList,(WCHAR *)bstrProperty);
  1850. }
  1851. }
  1852. }
  1853. if ( WBEM_S_NO_MORE_DATA == hr ){
  1854. hr = S_OK;
  1855. }
  1856. ((CVARIANT*)v)->SetStr(pList);
  1857. SAFE_DELETE_PTR(pList);
  1858. EndPropertyEnumeration();
  1859. }
  1860. //=============================================================
  1861. // COLUMN_GUID
  1862. //=============================================================
  1863. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[4].wcsColumnName) == 0 ){
  1864. *pType = DBTYPE_GUID;
  1865. }
  1866. //=============================================================
  1867. // COLUMN_PROPID
  1868. //=============================================================
  1869. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[5].wcsColumnName) == 0 ){
  1870. *pType = CIM_UINT32;
  1871. }
  1872. //=============================================================
  1873. // ORDINAL
  1874. //=============================================================
  1875. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[6].wcsColumnName) == 0 ){
  1876. *pType = CIM_UINT32;
  1877. }
  1878. //=============================================================
  1879. // PK_NAME
  1880. //=============================================================
  1881. else if( _wcsicmp(pProperty,g_PrimaryKeysColumns[7].wcsColumnName) == 0 ){
  1882. *pType = CIM_STRING;
  1883. }
  1884. return MapWbemErrorToOLEDBError(hr);
  1885. }
  1886. ////////////////////////////////////////////////////////////////////////////////////////////////
  1887. HRESULT CWbemSchemaPrimaryKeysInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  1888. {
  1889. HRESULT hr = S_OK;
  1890. if( !m_pwcsSpecificClass )
  1891. {
  1892. return CWbemInstanceList::NextInstance(Key,pInst);
  1893. }
  1894. hr = GetTheSpecificClass();
  1895. if( S_OK == hr )
  1896. {
  1897. *pInst = (CWbemSchemaPrimaryKeysInstanceWrapper *) new CWbemSchemaPrimaryKeysInstanceWrapper(m_pParms);
  1898. // NTRaid:136519 , 136522
  1899. // 07/05/00
  1900. if(*pInst)
  1901. {
  1902. (*pInst)->SetClass(m_pSpecificClass);
  1903. (*pInst)->SetPos(++m_lCurrentPos);
  1904. AddInstance(*pInst);
  1905. (*pInst)->GetKey(Key);
  1906. }
  1907. else
  1908. {
  1909. hr = E_OUTOFMEMORY;
  1910. }
  1911. }
  1912. return hr;
  1913. }
  1914. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1915. HRESULT CWbemSchemaPrimaryKeysInstanceList::Reset()
  1916. {
  1917. HRESULT hr = E_UNEXPECTED;
  1918. if( m_pwcsSpecificClass)
  1919. {
  1920. hr = ResetTheSpecificClass();
  1921. }
  1922. else
  1923. {
  1924. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  1925. //============================================================
  1926. // Send off the query for "Select Name from __Namespace
  1927. //============================================================
  1928. if( m_ppEnum )
  1929. {
  1930. hr = m_ppEnum->Reset();
  1931. ReleaseAllInstances();
  1932. }
  1933. else
  1934. {
  1935. hr = (m_pParms->GetServicesPtr())->CreateClassEnum(NULL, WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  1936. }
  1937. }
  1938. m_lCurrentPos = 0;
  1939. return MapWbemErrorToOLEDBError(hr);
  1940. }
  1941. //********************************************************************************************
  1942. //////////////////////////////////////////////////////////////////////////////////////////////
  1943. //
  1944. // Classes for the Tables Info schema rowset
  1945. //
  1946. //********************************************************************************************
  1947. //////////////////////////////////////////////////////////////////////////////////////////////
  1948. CWbemSchemaTablesInfoClassDefinitionWrapper::CWbemSchemaTablesInfoClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  1949. {
  1950. m_nMaxColumns = sizeof(g_TablesInfo)/sizeof(SchemaRowsetDefinition);
  1951. }
  1952. //////////////////////////////////////////////////////////////////////////////////////////////
  1953. HRESULT CWbemSchemaTablesInfoClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1954. {
  1955. HRESULT hr = S_OK;
  1956. //===============================================================================
  1957. // See if we got all of the column info
  1958. //===============================================================================
  1959. if( m_nSchemaClassIndex == m_nMaxColumns )
  1960. {
  1961. return WBEM_S_NO_MORE_DATA;
  1962. }
  1963. *pType = g_TablesInfo[m_nSchemaClassIndex].Type;
  1964. *pProperty = Wmioledb_SysAllocString(g_TablesInfo[m_nSchemaClassIndex].wcsColumnName);
  1965. m_nSchemaClassIndex++;
  1966. return hr;
  1967. }
  1968. //////////////////////////////////////////////////////////////////////////////////////////////
  1969. HRESULT CWbemSchemaTablesInfoInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  1970. {
  1971. HRESULT hr = S_OK;
  1972. ((CVARIANT*)v)->Clear();
  1973. *plFlavor = 0;
  1974. //=============================================================
  1975. // TABLE_CATALOG
  1976. //=============================================================
  1977. if( _wcsicmp(pProperty,g_TablesInfo[0].wcsColumnName) == 0 ){
  1978. *pType = CIM_STRING;
  1979. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  1980. }
  1981. //=============================================================
  1982. // TABLE_SCHEMA
  1983. //=============================================================
  1984. else if( _wcsicmp(pProperty,g_TablesInfo[1].wcsColumnName) == 0 ){
  1985. *pType = CIM_STRING;
  1986. }
  1987. //=============================================================
  1988. // TABLE_NAME
  1989. //=============================================================
  1990. else if( _wcsicmp(pProperty,g_TablesInfo[2].wcsColumnName) == 0 ){
  1991. *pType = CIM_STRING;
  1992. hr = GetClassProperty(L"__CLASS",v,pType,plFlavor);
  1993. }
  1994. //=============================================================
  1995. // TABLE_TYPE
  1996. // This is either "TABLE" or "SYSTEM TABLE"
  1997. //=============================================================
  1998. else if( _wcsicmp(pProperty,g_TablesInfo[3].wcsColumnName) == 0 ){
  1999. *pType = CIM_STRING;
  2000. CVARIANT Var;
  2001. hr = GetClassProperty(L"__CLASS",&Var,pType,plFlavor);
  2002. // NT Raid 136462
  2003. // 07/12/00
  2004. if( S_OK == hr ){
  2005. WCHAR * p = Var.GetStr();
  2006. if (p != NULL){
  2007. if( wcsncmp( p, L"__",2) == 0 ){
  2008. ((CVARIANT*)v)->SetStr(L"SYSTEM TABLE");
  2009. }
  2010. else{
  2011. ((CVARIANT*)v)->SetStr(L"TABLE");
  2012. }
  2013. }
  2014. else{
  2015. hr = E_UNEXPECTED;
  2016. }
  2017. }
  2018. }
  2019. //=============================================================
  2020. // TABLE_GUID
  2021. //=============================================================
  2022. else if( _wcsicmp(pProperty,g_TablesInfo[4].wcsColumnName) == 0 ){
  2023. *pType = DBTYPE_GUID;
  2024. }
  2025. //=============================================================
  2026. // BOOKMARKS
  2027. //=============================================================
  2028. else if( _wcsicmp(pProperty,g_TablesInfo[5].wcsColumnName) == 0 ){
  2029. *pType = CIM_BOOLEAN;
  2030. ((CVARIANT*)v)->SetBool(TRUE);
  2031. }
  2032. //=============================================================
  2033. // BOOKMARK_TYPE
  2034. //=============================================================
  2035. else if( _wcsicmp(pProperty,g_TablesInfo[6].wcsColumnName) == 0 ){
  2036. *pType = CIM_SINT32;
  2037. ((CVARIANT*)v)->SetLONG(DBPROPVAL_BMK_NUMERIC);
  2038. }
  2039. //=============================================================
  2040. // BOOKMARK_DATATYPE
  2041. //=============================================================
  2042. else if( _wcsicmp(pProperty,g_TablesInfo[7].wcsColumnName) == 0 ){
  2043. *pType = CIM_UINT16;
  2044. ((CVARIANT*)v)->SetShort(DBTYPE_UI4);
  2045. }
  2046. //=============================================================
  2047. // BOOKMARK_MAXIMUM_LENGTH
  2048. //=============================================================
  2049. else if( _wcsicmp(pProperty,g_TablesInfo[8].wcsColumnName) == 0 )
  2050. {
  2051. *pType = CIM_UINT32;
  2052. ((CVARIANT*)v)->SetLONG(sizeof(ULONG));
  2053. }
  2054. //=============================================================
  2055. // BOOKMARK_INFORMATION
  2056. //=============================================================
  2057. else if( _wcsicmp(pProperty,g_TablesInfo[9].wcsColumnName) == 0 ){
  2058. *pType = CIM_UINT32;
  2059. }
  2060. //=============================================================
  2061. // BOOKMARK_TABLE_VERSION
  2062. //=============================================================
  2063. else if( _wcsicmp(pProperty,g_TablesInfo[10].wcsColumnName) == 0 ){
  2064. *pType = CIM_STRING;
  2065. }
  2066. //=============================================================
  2067. // CARDINALITY
  2068. //=============================================================
  2069. else if( _wcsicmp(pProperty,g_TablesInfo[11].wcsColumnName) == 0 ){
  2070. *pType = CIM_STRING;
  2071. }
  2072. //=============================================================
  2073. // DESCRIPTION
  2074. //=============================================================
  2075. else if( _wcsicmp(pProperty,g_TablesInfo[12].wcsColumnName) == 0 ){
  2076. *pType = CIM_STRING;
  2077. hr = GetClassQualifier(L"Description",v,pType,plFlavor);
  2078. }
  2079. //=============================================================
  2080. // TABLE_PROPID
  2081. //=============================================================
  2082. else if( _wcsicmp(pProperty,g_TablesInfo[13].wcsColumnName) == 0 ){
  2083. *pType = CIM_UINT32;
  2084. }
  2085. return MapWbemErrorToOLEDBError(hr);
  2086. }
  2087. ////////////////////////////////////////////////////////////////////////////////////////////////
  2088. HRESULT CWbemSchemaTablesInfoInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  2089. {
  2090. HRESULT hr = S_OK;
  2091. if( !m_pwcsSpecificClass )
  2092. {
  2093. return CWbemInstanceList::NextInstance(Key,pInst);
  2094. }
  2095. hr = GetTheSpecificClass();
  2096. if( S_OK == hr )
  2097. {
  2098. *pInst = (CWbemSchemaTablesInfoInstanceWrapper *) new CWbemSchemaTablesInfoInstanceWrapper(m_pParms);
  2099. // NTRaid:136512 , 136514
  2100. // 07/05/00
  2101. if(*pInst)
  2102. {
  2103. (*pInst)->SetClass(m_pSpecificClass);
  2104. (*pInst)->SetPos(++m_lCurrentPos);
  2105. AddInstance(*pInst);
  2106. (*pInst)->GetKey(Key);
  2107. }
  2108. else
  2109. {
  2110. hr = E_OUTOFMEMORY;
  2111. }
  2112. }
  2113. return hr;
  2114. }
  2115. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2116. HRESULT CWbemSchemaTablesInfoInstanceList::Reset()
  2117. {
  2118. HRESULT hr = E_UNEXPECTED;
  2119. if( m_pwcsSpecificClass)
  2120. {
  2121. hr = ResetTheSpecificClass();
  2122. }
  2123. else
  2124. {
  2125. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  2126. //============================================================
  2127. // Send off the query for "Select Name from __Namespace
  2128. //============================================================
  2129. if( m_ppEnum )
  2130. {
  2131. hr = m_ppEnum->Reset();
  2132. ReleaseAllInstances();
  2133. }
  2134. else
  2135. {
  2136. hr = (m_pParms->GetServicesPtr())->CreateClassEnum(NULL, WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  2137. }
  2138. }
  2139. m_lCurrentPos = 0;
  2140. return MapWbemErrorToOLEDBError(hr);
  2141. }
  2142. //********************************************************************************************
  2143. //////////////////////////////////////////////////////////////////////////////////////////////
  2144. //
  2145. // Classes for the Procedures schema rowset
  2146. //
  2147. //********************************************************************************************
  2148. //////////////////////////////////////////////////////////////////////////////////////////////
  2149. CWbemSchemaProceduresClassDefinitionWrapper::CWbemSchemaProceduresClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  2150. {
  2151. m_nMaxColumns = sizeof(g_Procedures)/sizeof(SchemaRowsetDefinition);
  2152. }
  2153. //////////////////////////////////////////////////////////////////////////////////////////////
  2154. HRESULT CWbemSchemaProceduresClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  2155. {
  2156. HRESULT hr = S_OK;
  2157. //===============================================================================
  2158. // See if we got all of the column info
  2159. //===============================================================================
  2160. if( m_nSchemaClassIndex == m_nMaxColumns )
  2161. {
  2162. return WBEM_S_NO_MORE_DATA;
  2163. }
  2164. *pType = g_Procedures[m_nSchemaClassIndex].Type;
  2165. *pProperty = Wmioledb_SysAllocString(g_Procedures[m_nSchemaClassIndex].wcsColumnName);
  2166. m_nSchemaClassIndex++;
  2167. return hr;
  2168. }
  2169. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2170. HRESULT CWbemSchemaProceduresInstanceWrapper::GetKey(CBSTR & Key)
  2171. {
  2172. HRESULT hr = S_OK;
  2173. //===========================================================
  2174. // The key is going to the be the class name.method name
  2175. //===========================================================
  2176. CVARIANT v;
  2177. CIMTYPE Type;
  2178. LONG lFlavor;
  2179. hr = GetClassProperty(L"__CLASS",&v,&Type,&lFlavor);
  2180. if( SUCCEEDED(hr))
  2181. {
  2182. WCHAR * p = new WCHAR [wcslen(v.GetStr()) + wcslen(m_bstrCurrentMethodName) + 4 ];
  2183. if( p )
  2184. {
  2185. swprintf(p, L"%s:%s", v.GetStr(),m_bstrCurrentMethodName);
  2186. Key.SetStr(p);
  2187. delete p;
  2188. }
  2189. }
  2190. return hr;
  2191. }
  2192. //////////////////////////////////////////////////////////////////////////////////////////////
  2193. HRESULT CWbemSchemaProceduresInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  2194. {
  2195. HRESULT hr = S_OK;
  2196. ((CVARIANT*)v)->Clear();
  2197. *plFlavor = 0;
  2198. //=============================================================
  2199. // PROCEDURE_CATALOG
  2200. //=============================================================
  2201. if( _wcsicmp(pProperty,g_Procedures[0].wcsColumnName) == 0 )
  2202. {
  2203. *pType = CIM_STRING;
  2204. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  2205. }
  2206. //=============================================================
  2207. // PROCEDURE_SCHEMA
  2208. //=============================================================
  2209. else if( _wcsicmp(pProperty,g_Procedures[1].wcsColumnName) == 0 )
  2210. {
  2211. *pType = CIM_STRING;
  2212. hr = GetClassProperty(L"__CLASS",v,pType,plFlavor);
  2213. }
  2214. //=============================================================
  2215. // PROCEDURE_NAME
  2216. //=============================================================
  2217. else if( _wcsicmp(pProperty,g_Procedures[2].wcsColumnName) == 0 )
  2218. {
  2219. *pType = CIM_STRING;
  2220. ((CVARIANT*)v)->SetStr(m_bstrCurrentMethodName);
  2221. }
  2222. //=============================================================
  2223. // PROCEDURE_TYPE
  2224. //=============================================================
  2225. else if( _wcsicmp(pProperty,g_Procedures[3].wcsColumnName) == 0 )
  2226. {
  2227. *pType = CIM_SINT16;
  2228. //=========================================================
  2229. //
  2230. // If there is an output class, then the type is
  2231. // DB_PT_FUNCTION
  2232. // If there is not an output class, then the type is
  2233. // DB_PT_PROCEDURE
  2234. //=========================================================
  2235. if( m_pOutClass )
  2236. {
  2237. ((CVARIANT*)v)->SetShort(DB_PT_FUNCTION);
  2238. }
  2239. else
  2240. {
  2241. ((CVARIANT*)v)->SetShort(DB_PT_PROCEDURE);
  2242. }
  2243. }
  2244. //=============================================================
  2245. // PROCEDURE_DEFINITION
  2246. //=============================================================
  2247. else if( _wcsicmp(pProperty,g_Procedures[4].wcsColumnName) == 0 )
  2248. {
  2249. *pType = CIM_STRING;
  2250. }
  2251. //=============================================================
  2252. // PROCEDURE_DESCRIPTION
  2253. //=============================================================
  2254. else if( _wcsicmp(pProperty,g_Procedures[5].wcsColumnName) == 0 )
  2255. {
  2256. *pType = CIM_STRING;
  2257. }
  2258. //=============================================================
  2259. // DATE_CREATED
  2260. //=============================================================
  2261. else if( _wcsicmp(pProperty,g_Procedures[6].wcsColumnName) == 0 )
  2262. {
  2263. *pType = DBTYPE_DATE;
  2264. }
  2265. //=============================================================
  2266. // DATE_MODIFIED
  2267. //=============================================================
  2268. else if( _wcsicmp(pProperty,g_Procedures[7].wcsColumnName) == 0 )
  2269. {
  2270. *pType = DBTYPE_DATE;
  2271. }
  2272. return MapWbemErrorToOLEDBError(hr);
  2273. }
  2274. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2275. void CWbemSchemaProceduresInstanceList::ResetMethodPtrs()
  2276. {
  2277. m_bstrCurrentMethodName.Clear();
  2278. SAFE_RELEASE_PTR(m_pCurrentMethodInClass);
  2279. SAFE_RELEASE_PTR(m_pCurrentMethodOutClass);
  2280. }
  2281. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2282. HRESULT CWbemSchemaProceduresInstanceList::Reset()
  2283. {
  2284. HRESULT hr = E_UNEXPECTED;
  2285. if( m_pwcsSpecificClass)
  2286. {
  2287. hr = ResetTheSpecificClass();
  2288. }
  2289. else
  2290. {
  2291. LONG lFlags = WBEM_FLAG_SHALLOW | WBEM_FLAG_FORWARD_ONLY;
  2292. //============================================================
  2293. // Send off the query for "Select Name from __Namespace
  2294. //============================================================
  2295. if( m_ppEnum )
  2296. {
  2297. hr = m_ppEnum->Reset();
  2298. ReleaseAllInstances();
  2299. }
  2300. else
  2301. {
  2302. hr = (m_pParms->GetServicesPtr())->CreateClassEnum(NULL, WBEM_FLAG_FORWARD_ONLY,m_pParms->m_pConnection->GetContext(),&m_ppEnum);
  2303. }
  2304. }
  2305. m_lCurrentPos = 0;
  2306. m_fContinueWithSameClass = FALSE;
  2307. SAFE_RELEASE_PTR(m_pCurrentMethodClass);
  2308. return MapWbemErrorToOLEDBError(hr);
  2309. }
  2310. ////////////////////////////////////////////////////////////////////////////////////////////////
  2311. HRESULT CWbemSchemaProceduresInstanceList::GetTheNextClassThatHasMethods()
  2312. {
  2313. HRESULT hr = S_OK;
  2314. //==================================================================
  2315. // Does the existing class have methods in it?
  2316. //==================================================================
  2317. while( S_OK == hr )
  2318. {
  2319. //==============================================================
  2320. // It does, then set all the current info and return so we
  2321. // can process the columns
  2322. //==============================================================
  2323. unsigned long u = 0L;
  2324. if( !m_fContinueWithSameClass )
  2325. {
  2326. if( !m_pwcsSpecificClass )
  2327. {
  2328. SAFE_RELEASE_PTR(m_pCurrentMethodClass);
  2329. hr = m_ppEnum->Next(0,1,&m_pCurrentMethodClass,&u);
  2330. if( SUCCEEDED(hr))
  2331. {
  2332. hr = m_pCurrentMethodClass->BeginMethodEnumeration(0);
  2333. }
  2334. }
  2335. }
  2336. if( SUCCEEDED(hr))
  2337. {
  2338. ResetMethodPtrs();
  2339. hr = m_pCurrentMethodClass->NextMethod(0,(BSTR*)&m_bstrCurrentMethodName,&m_pCurrentMethodInClass,&m_pCurrentMethodOutClass);
  2340. if( hr == S_OK )
  2341. {
  2342. m_fContinueWithSameClass = TRUE;
  2343. break;
  2344. }
  2345. else
  2346. {
  2347. if( hr == WBEM_S_NO_MORE_DATA )
  2348. {
  2349. if( !m_pwcsSpecificClass )
  2350. {
  2351. hr = S_OK; // continue on to the next one
  2352. }
  2353. // otherwise,we know there isn't another one.
  2354. }
  2355. m_pCurrentMethodClass->EndEnumeration();
  2356. m_fContinueWithSameClass = FALSE;
  2357. }
  2358. //==============================================================
  2359. // It doesn't, so, keep looping through the classes until we
  2360. // find another class that has methods, or we are done with all
  2361. // the classes
  2362. //==============================================================
  2363. }
  2364. else
  2365. {
  2366. break;
  2367. }
  2368. }
  2369. return hr;
  2370. }
  2371. ////////////////////////////////////////////////////////////////////////////////////////////////
  2372. HRESULT CWbemSchemaProceduresInstanceList::GetSpecificNextInstance()
  2373. {
  2374. HRESULT hr = GetTheSpecificClass();
  2375. if( S_OK == hr )
  2376. {
  2377. m_pCurrentMethodClass = m_pSpecificClass;
  2378. m_pSpecificClass = NULL; // will be released with the m_pCurrentMethodClass
  2379. ResetMethodPtrs();
  2380. m_fContinueWithSameClass = TRUE;
  2381. hr = m_pCurrentMethodClass->BeginMethodEnumeration(0);
  2382. }
  2383. //==================================================================
  2384. // We know there are no more classes, but there might be more
  2385. // methods, so go on to process the rest of the methods
  2386. //==================================================================
  2387. if( hr == WBEM_S_NO_MORE_DATA )
  2388. {
  2389. hr = S_OK;
  2390. }
  2391. return hr;
  2392. }
  2393. ////////////////////////////////////////////////////////////////////////////////////////////////
  2394. HRESULT CWbemSchemaProceduresInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  2395. {
  2396. HRESULT hr = S_OK;
  2397. if( m_pwcsSpecificClass )
  2398. {
  2399. hr = GetSpecificNextInstance();
  2400. }
  2401. if( S_OK == hr )
  2402. {
  2403. hr = GetTheNextClassThatHasMethods();
  2404. if( S_OK == hr)
  2405. {
  2406. *pInst = new CWbemSchemaProceduresInstanceWrapper(m_pParms);
  2407. // NTRaid:136455
  2408. // 07/05/00
  2409. if(*pInst)
  2410. {
  2411. (*pInst)->SetPos(++m_lCurrentPos);
  2412. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->SetMethodName((LPWSTR)m_bstrCurrentMethodName);
  2413. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->SetInputClass(m_pCurrentMethodInClass);
  2414. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->SetOutputClass(m_pCurrentMethodOutClass);
  2415. (*pInst)->SetClass(m_pCurrentMethodClass);
  2416. AddInstance(*pInst);
  2417. (*pInst)->GetKey(Key);
  2418. hr = S_OK;
  2419. }
  2420. else
  2421. {
  2422. hr = E_OUTOFMEMORY;
  2423. }
  2424. }
  2425. }
  2426. return hr;
  2427. }
  2428. //********************************************************************************************
  2429. //////////////////////////////////////////////////////////////////////////////////////////////
  2430. //
  2431. // Classes for the Procedure Parameters schema rowset
  2432. //
  2433. //********************************************************************************************
  2434. //////////////////////////////////////////////////////////////////////////////////////////////
  2435. CWbemSchemaProceduresParametersClassDefinitionWrapper::CWbemSchemaProceduresParametersClassDefinitionWrapper(CWbemClassParameters * p) : CWbemSchemaClassDefinitionWrapper(p)
  2436. {
  2437. m_nMaxColumns = sizeof(g_ProcedureParameters)/sizeof(SchemaRowsetDefinition);
  2438. }
  2439. //////////////////////////////////////////////////////////////////////////////////////////////
  2440. HRESULT CWbemSchemaProceduresParametersClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  2441. {
  2442. HRESULT hr = S_OK;
  2443. //===============================================================================
  2444. // See if we got all of the column info
  2445. //===============================================================================
  2446. if( m_nSchemaClassIndex == m_nMaxColumns )
  2447. {
  2448. return WBEM_S_NO_MORE_DATA;
  2449. }
  2450. *pType = g_ProcedureParameters[m_nSchemaClassIndex].Type;
  2451. *pProperty = Wmioledb_SysAllocString(g_ProcedureParameters[m_nSchemaClassIndex].wcsColumnName);
  2452. m_nSchemaClassIndex++;
  2453. return hr;
  2454. }
  2455. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2456. HRESULT CWbemSchemaProceduresParametersInstanceWrapper::GetKey(CBSTR & Key)
  2457. {
  2458. HRESULT hr = S_OK;
  2459. //===========================================================
  2460. // The key is going to the be the class name.method name
  2461. //===========================================================
  2462. CVARIANT v;
  2463. CIMTYPE Type;
  2464. LONG lFlavor;
  2465. hr = GetClassProperty(L"__CLASS",&v,&Type,&lFlavor);
  2466. if( SUCCEEDED(hr))
  2467. {
  2468. WCHAR * p = new WCHAR [wcslen(v.GetStr()) + wcslen(m_bstrCurrentMethodName) + wcslen(m_bstrPropertyName)+ 4 ];
  2469. if( p )
  2470. {
  2471. swprintf(p, L"%s:%s:%s", v.GetStr(),m_bstrCurrentMethodName,m_bstrPropertyName);
  2472. Key.SetStr(p);
  2473. delete p;
  2474. }
  2475. }
  2476. return hr;
  2477. }
  2478. //////////////////////////////////////////////////////////////////////////////////////////////
  2479. HRESULT CWbemSchemaProceduresParametersInstanceWrapper::GetPropertyQualifier(WCHAR * wcsQualifier,VARIANT * v)
  2480. {
  2481. LONG lType;
  2482. long lFlavor;
  2483. HRESULT hr = S_OK;
  2484. IWbemClassObject * pTmp = m_pClass;
  2485. if( m_pInClass )
  2486. {
  2487. m_pClass = m_pInClass;
  2488. }
  2489. else
  2490. {
  2491. m_pClass = m_pOutClass;
  2492. }
  2493. hr = CWbemClassWrapper::GetPropertyQualifier(m_bstrPropertyName,CBSTR(wcsQualifier),v,&lType,&lFlavor);
  2494. m_pClass = pTmp;
  2495. return hr;
  2496. }
  2497. //////////////////////////////////////////////////////////////////////////////////////////////
  2498. HRESULT CWbemSchemaProceduresParametersInstanceWrapper::GetSchemaProperty( WCHAR * pProperty, VARIANT * v,CIMTYPE * pType , LONG * plFlavor)
  2499. {
  2500. HRESULT hr = S_OK;
  2501. ((CVARIANT*)v)->Clear();
  2502. *plFlavor = 0;
  2503. //=============================================================
  2504. // PROCEDURE_CATALOG
  2505. //=============================================================
  2506. if( _wcsicmp(pProperty,g_ProcedureParameters[0].wcsColumnName) == 0 )
  2507. {
  2508. *pType = CIM_STRING;
  2509. ((CVARIANT*)v)->SetStr(m_pParms->m_pConnection->GetNamespace());
  2510. }
  2511. //=============================================================
  2512. // PROCEDURE_SCHEMA
  2513. //=============================================================
  2514. else if( _wcsicmp(pProperty,g_ProcedureParameters[1].wcsColumnName) == 0 )
  2515. {
  2516. *pType = CIM_STRING;
  2517. hr = GetClassProperty(L"__CLASS",v,pType,plFlavor);
  2518. }
  2519. //=============================================================
  2520. // PROCEDURE_NAME
  2521. //=============================================================
  2522. else if( _wcsicmp(pProperty,g_ProcedureParameters[2].wcsColumnName) == 0 )
  2523. {
  2524. *pType = CIM_STRING;
  2525. ((CVARIANT*)v)->SetStr(m_bstrCurrentMethodName);
  2526. }
  2527. //=============================================================
  2528. // PARAMETER_NAME
  2529. //=============================================================
  2530. else if( _wcsicmp(pProperty,g_ProcedureParameters[3].wcsColumnName) == 0 )
  2531. {
  2532. *pType = CIM_STRING;
  2533. ((CVARIANT*)v)->SetStr(m_bstrPropertyName);
  2534. }
  2535. //=============================================================
  2536. // ORDINAL_POSITION
  2537. //=============================================================
  2538. else if( _wcsicmp(pProperty,g_ProcedureParameters[4].wcsColumnName) == 0 )
  2539. {
  2540. *pType = CIM_UINT16;
  2541. ((CVARIANT*)v)->SetShort(m_nOrdinal);
  2542. }
  2543. //=============================================================
  2544. // PARAMETER_TYPE
  2545. //=============================================================
  2546. else if( _wcsicmp(pProperty,g_ProcedureParameters[5].wcsColumnName) == 0 )
  2547. {
  2548. *pType = CIM_UINT16;
  2549. CVARIANT vIn, vOut;
  2550. GetPropertyQualifier(L"IN",vIn);
  2551. GetPropertyQualifier(L"OUT",vOut);
  2552. if( vIn.GetType() != VT_EMPTY && vOut.GetType() != VT_EMPTY )
  2553. {
  2554. if( vIn.GetBool() == TRUE && vOut.GetBool() == TRUE )
  2555. {
  2556. ((CVARIANT*)v)->SetShort(DBPARAMTYPE_INPUTOUTPUT);
  2557. }
  2558. }
  2559. else if( vOut.GetType() != VT_EMPTY && vOut.GetBool() == TRUE )
  2560. {
  2561. ((CVARIANT*)v)->SetShort(DBPARAMTYPE_OUTPUT);
  2562. }
  2563. else if( vIn.GetType() != VT_EMPTY && vIn.GetBool() == TRUE )
  2564. {
  2565. ((CVARIANT*)v)->SetShort(DBPARAMTYPE_INPUT);
  2566. }
  2567. }
  2568. //=============================================================
  2569. // PARAMETER_HASDEFAULT
  2570. //=============================================================
  2571. else if( _wcsicmp(pProperty,g_ProcedureParameters[6].wcsColumnName) == 0 )
  2572. {
  2573. *pType = CIM_BOOLEAN;
  2574. CVARIANT vVar;
  2575. hr = GetPropertyQualifier(CBSTR(L"Optional"),(VARIANT *)&vVar);
  2576. if( SUCCEEDED(hr))
  2577. {
  2578. ((CVARIANT*)v)->SetBool(vVar.GetBool());
  2579. }
  2580. }
  2581. //=============================================================
  2582. // PARAMETER_DEFAULT
  2583. //=============================================================
  2584. else if( _wcsicmp(pProperty,g_ProcedureParameters[7].wcsColumnName) == 0 )
  2585. {
  2586. *pType = CIM_STRING;
  2587. }
  2588. //=============================================================
  2589. // IS_NULLABLE
  2590. //=============================================================
  2591. else if( _wcsicmp(pProperty,g_ProcedureParameters[8].wcsColumnName) == 0 )
  2592. {
  2593. *pType = CIM_BOOLEAN;
  2594. ((CVARIANT*)v)->SetBool(VARIANT_TRUE);
  2595. }
  2596. //=============================================================
  2597. // DATA_TYPE
  2598. //=============================================================
  2599. else if( _wcsicmp(pProperty,g_ProcedureParameters[9].wcsColumnName) == 0 )
  2600. {
  2601. *pType = CIM_UINT16;
  2602. CDataMap Map;
  2603. WORD wType;
  2604. DBLENGTH dwLength;
  2605. DWORD dwFlags;
  2606. hr = Map.MapCIMTypeToOLEDBType(m_vProperty.GetType(),wType,dwLength,dwFlags);
  2607. if( SUCCEEDED(hr))
  2608. {
  2609. ((CVARIANT*)v)->SetShort(wType);
  2610. }
  2611. }
  2612. //=============================================================
  2613. // CHARACTER_MAXIMUM_LENGTH
  2614. //=============================================================
  2615. else if( _wcsicmp(pProperty,g_ProcedureParameters[10].wcsColumnName) == 0 )
  2616. {
  2617. *pType = CIM_UINT32;
  2618. if( m_vProperty.GetType() == CIM_STRING )
  2619. {
  2620. ((CVARIANT*)v)->SetLONG(~0);
  2621. }
  2622. }
  2623. //=============================================================
  2624. // CHARACTER_OCTET_LENGTH
  2625. //=============================================================
  2626. else if( _wcsicmp(pProperty,g_ProcedureParameters[11].wcsColumnName) == 0 )
  2627. {
  2628. *pType = CIM_UINT32;
  2629. if( m_vProperty.GetType() == CIM_STRING )
  2630. {
  2631. ((CVARIANT*)v)->SetLONG(~0);
  2632. }
  2633. }
  2634. //=============================================================
  2635. // NUMERIC_PRECISION
  2636. //=============================================================
  2637. else if( _wcsicmp(pProperty,g_ProcedureParameters[12].wcsColumnName) == 0 )
  2638. {
  2639. *pType = CIM_UINT16;
  2640. }
  2641. //=============================================================
  2642. // NUMERIC_SCALE
  2643. //=============================================================
  2644. else if( _wcsicmp(pProperty,g_ProcedureParameters[13].wcsColumnName) == 0 )
  2645. {
  2646. *pType = CIM_SINT16;
  2647. }
  2648. //=============================================================
  2649. // DESCRIPTION
  2650. //=============================================================
  2651. else if( _wcsicmp(pProperty,g_ProcedureParameters[14].wcsColumnName) == 0 )
  2652. {
  2653. *pType = CIM_STRING;
  2654. }
  2655. //=============================================================
  2656. // TYPE_NAME
  2657. //=============================================================
  2658. else if( _wcsicmp(pProperty,g_ProcedureParameters[15].wcsColumnName) == 0 )
  2659. {
  2660. *pType = CIM_STRING;
  2661. CVARIANT vVar;
  2662. hr = GetPropertyQualifier(CBSTR(L"CIMTYPE"),(VARIANT *)&vVar);
  2663. if( SUCCEEDED(hr))
  2664. {
  2665. ((CVARIANT*)v)->SetStr(vVar.GetStr());
  2666. }
  2667. }
  2668. //=============================================================
  2669. // LOCAL_TYPE_NAME
  2670. //=============================================================
  2671. else if( _wcsicmp(pProperty,g_ProcedureParameters[16].wcsColumnName) == 0 )
  2672. {
  2673. *pType = CIM_STRING;
  2674. }
  2675. return MapWbemErrorToOLEDBError(hr);
  2676. }
  2677. ////////////////////////////////////////////////////////////////////////////////////////////////
  2678. HRESULT CWbemSchemaProceduresParametersInstanceList::GetTheNextParameter()
  2679. {
  2680. HRESULT hr = WBEM_S_NO_MORE_DATA;
  2681. //===================================================================
  2682. // Get the properties of the class
  2683. //===================================================================
  2684. CIMTYPE Type = 0;
  2685. LONG Flavor = 0;
  2686. m_bstrPropertyName.Clear();
  2687. m_vProperty.Clear();
  2688. if( m_pCurrentMethodInClass )
  2689. {
  2690. hr = m_pCurrentMethodInClass->Next(0,(BSTR*)&m_bstrPropertyName,&m_vProperty,&Type,&Flavor);
  2691. }
  2692. if( hr == WBEM_S_NO_MORE_DATA )
  2693. {
  2694. SAFE_RELEASE_PTR(m_pCurrentMethodInClass );
  2695. if( m_pCurrentMethodOutClass )
  2696. {
  2697. hr = m_pCurrentMethodOutClass->Next(0,(BSTR*)&m_bstrPropertyName,&m_vProperty,&Type,&Flavor);
  2698. }
  2699. }
  2700. return hr;
  2701. }
  2702. ////////////////////////////////////////////////////////////////////////////////////////////////
  2703. HRESULT CWbemSchemaProceduresParametersInstanceList::GetTheNextClassThatHasParameters()
  2704. {
  2705. HRESULT hr = S_OK;
  2706. //===================================================================================
  2707. // If we aren't working on the same class, then get the next class that has a method
  2708. //===================================================================================
  2709. m_nOrdinal = 0;
  2710. while(hr == S_OK)
  2711. {
  2712. hr = GetTheNextClassThatHasMethods();
  2713. if( SUCCEEDED(hr))
  2714. {
  2715. //===========================================================================
  2716. // Process the input parameters first
  2717. //===========================================================================
  2718. if( m_pCurrentMethodInClass )
  2719. {
  2720. hr = m_pCurrentMethodInClass->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY);
  2721. }
  2722. else if( m_pCurrentMethodOutClass )
  2723. {
  2724. hr = m_pCurrentMethodOutClass->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY);
  2725. }
  2726. if( SUCCEEDED(hr))
  2727. {
  2728. hr = GetTheNextParameter();
  2729. if( SUCCEEDED(hr))
  2730. {
  2731. m_fStillWorkingOnTheSameClass = TRUE;
  2732. break;
  2733. }
  2734. }
  2735. }
  2736. }
  2737. return hr;
  2738. }
  2739. ////////////////////////////////////////////////////////////////////////////////////////////////
  2740. HRESULT CWbemSchemaProceduresParametersInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst )
  2741. {
  2742. HRESULT hr = S_OK;
  2743. if( m_pwcsSpecificClass )
  2744. {
  2745. hr = GetSpecificNextInstance();
  2746. m_fStillWorkingOnTheSameClass = TRUE; // We want to pick up the parameters
  2747. }
  2748. if( S_OK == hr )
  2749. {
  2750. if( !m_fStillWorkingOnTheSameClass )
  2751. {
  2752. hr = GetTheNextClassThatHasParameters();
  2753. }
  2754. else
  2755. {
  2756. hr = GetTheNextParameter();
  2757. if( S_OK != hr )
  2758. {
  2759. hr = GetTheNextClassThatHasParameters();
  2760. }
  2761. }
  2762. }
  2763. if( S_OK == hr)
  2764. {
  2765. *pInst = new CWbemSchemaProceduresParametersInstanceWrapper(m_pParms);
  2766. // NTRaid:136459
  2767. // 07/05/00
  2768. if(*pInst)
  2769. {
  2770. (*pInst)->SetPos(++m_lCurrentPos);
  2771. ((CWbemSchemaProceduresParametersInstanceWrapper*)(*pInst))->SetMethodName((LPWSTR)m_bstrCurrentMethodName);
  2772. ((CWbemSchemaProceduresParametersInstanceWrapper*)(*pInst))->SetPropertyName((LPWSTR)m_bstrPropertyName);
  2773. ((CWbemSchemaProceduresParametersInstanceWrapper*)(*pInst))->SetProperty(m_vProperty);
  2774. ((CWbemSchemaProceduresParametersInstanceWrapper*)(*pInst))->SetOrdinal(++m_nOrdinal);
  2775. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->SetInputClass(m_pCurrentMethodInClass);
  2776. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->SetOutputClass(m_pCurrentMethodOutClass);
  2777. (*pInst)->SetClass(m_pCurrentMethodClass);
  2778. AddInstance(*pInst);
  2779. ((CWbemSchemaProceduresInstanceWrapper*)(*pInst))->GetKey(Key);
  2780. hr = S_OK;
  2781. }
  2782. else
  2783. {
  2784. hr = E_OUTOFMEMORY;
  2785. }
  2786. }
  2787. return hr;
  2788. }