This example creates a schema rowset that represents the dimensions schema. This function returns an IRowset interface pointer for the schema rowset.
//
HRESULT MDPSchemaSample(IDBSchemaRowset* pIDBSchemaRowset,
IUnknown** ppIUnknown)
{
HRESULT hr;
assert(*ppIUnknown == NULL);
IDBSchemaRowset *pIDBSchemaRowset = NULL;
hr = pIUnknown->QueryInterface(IID_IDBSchemaRowset,
(void **) &pIDBSchemaRowset);
// Get a list of the schemas supported by the provider
GUID *rgSchemas = NULL;
ULONG *rgRestrictionSupport = NULL;
ULONG cSchemas;
hr = pIDBSchemaRowset->GetSchemas( &cSchemas, &rgSchemas,
&rgRestrictionSupport );
// Create a rowset that represents the dimensions.Check if
// MDSCHEMA_DIMENSIONS is in the list returned by GetSchemas()
ULONG cRestrictions = 0;
BOOL bSchemaSupported = FALSE;
for (ULONG i=0; i < cSchemas; i++)
{
if (rgSchemas[i] == MDSCHEMA_DIMENSIONS)
{
bSchemaSupported = TRUE;
cRestrictions = rgRestrictionSupport[i];
}
}
if (bSchemaSupported)
{
IDBCreateCommand *pIDBCreateCommand = NULL;
VARIANT rgRestrictions[MAX_RESTRICTIONS];
// Initialize the restrictions
for (ULONG j=0; j < cRestrictions; j++)
VariantInit( &rgRestrictions[j] );
rgRestrictions[CUBE_NAME].bstrVal = SysAllocString(
L"Video Store Sales");
rgRestrictions[CUBE_NAME].vt = VT_BSTR;
assert(rgRestrictions[CUBE_NAME].bstrVal);
rgRestrictions[DIMENSION_NAME].bstrVal =
SysAllocString( L"Customer Location");
rgRestrictions[DIMENSION_NAME].vt = VT_BSTR;
assert(rgRestrictions[DIMENSION_NAME].bstrVal);
// Create a schema rowset for the "Customer Location" dimension
hr = pIDBSchemaRowset->GetRowset(NULL, MDSCHEMA_DIMENSIONS,
cRestrictions, rgRestrictions, IID_IRowset, 0, NULL,
(IUnknown **)ppIUnknown ));
// free the restrictions
for (j=0; j < cRestrictions; j++)
VariantClear(&rgRestrictions[j]);
}
if (rgSchemas) CoTaskMemFree(rgSchemas);
if (rgRestrictionSupport) CoTaskMemFree(rgRestrictionSupport);
if (pIDBSchemaRowset) pIDBSchemaRowset->Release();
return hr;
}