Creating a Schema Rowset

OLE DB Programmer's Reference

This example creates a schema rowset that represents the dimensions schema. IDBSchemaRowset 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 whether    // 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; }

1998-2001 Microsoft Corporation. All rights reserved.



Microsoft Ole Db 2.0 Programmer's Reference and Data Access SDK
Microsoft OLE DB 2.0 Programmers Reference and Data Access SDK (Microsoft Professional Editions)
ISBN: 0735605904
EAN: 2147483647
Year: 1998
Pages: 1083

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net