Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AdvancedPV Sample: Demonstrates Advanced Provider Techniques

The AdvancedPV sample is very similar to UpdatePV, but it demonstrates some advanced techniques.

Normally providers written using OLE DB Templates use CAtlArray for data storage. The OLE DB Provider Templates call a user-provided Execute method to populate the array (for example, to load all of the rows from the data file into the array). Another user-provided method, FlushData, is used to save the contents of the array (for example, to write the array contents back into the data file).The problem with this approach is that in Execute you have to load all of the rows in the rowset, and in FlushData you have to save all of the rows at the same time. If there is a large number of rows in the rowset, all of the data needs to be stored in memory (in the CAtlArray object).

AdvancedPV demonstrates how to use a special array class in place of the default CAtlArray array to make the provider load and save rows as necessary. The rows will be loaded from the data file only when they are actually requested (through a specially implemented operator[]) and the changes will be written back to the file as soon as the array contents change.

Security noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

To build and run this sample

  1. Open the solution file AdvancedPV.sln.

  2. From the Build menu, click Build.

  3. Create a Win32 Console application with the Win32 Project wizard. Give it ATL support.

  4. Add an OLE DB consumer to the project (from Add Class, select ATL OLE DB Consumer).

  5. In the ATL OLE DB Consumer wizard, click the Data Source button and in Data Link Properties, select AdvancedProv Provider. (The AdvancedProv provider should be registered automatically when you build AdvancedPV, but if you don't see it listed here, run regsvr32.exe on AdvancedPV.dll.)

  6. Click Next to go to the Connection tab, then under Enter the initial catalog to use, specify the initial catalog to use (the path to DataFile.dat).

  7. Under Select Database Object, open Tables; there is only one item (the path to DataFile.dat). Select it and click OK. When you return to the ATL OLE DB Consumer wizard, select Table, rename the class to something shorter (if necessary) such as CMyCons, and click Finish. Build the consumer project.

  8. Add the following to your project's main code:

    #include "MyCons.h" 
     
    int main( int argc, char* argv[] )
    {
       // Add this code
       HRESULT hr = CoInitialize(NULL); 
       CMyCons rs; 
       hr = rs.OpenAll(); 
       ATLASSERT( SUCCEEDED(hr)); 
    
       hr = rs.MoveFirst(); 
       while( SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET ) 
       { 
          printf( "%d %s %s %s %s\n", rs.m_Fixed, rs.m_Command, rs.m_Text,  
          rs.m_Command2, rs.m_Text2 ); 
          hr = rs.MoveNext(); 
       } 
    
       rs.CloseAll(); 
       CoUninitialize(); 
       return 0;
    }
    
  9. Put a breakpoint on the CoUninitialize function; this will make the console stay open so you can view the results. Run the application by clicking the Start button (or click Start Without Debugging from the Debug menu). You should see five columns of text printed out (one index and four text columns).

This sample uses the following interfaces:

IRowsetLocateImpl, IRowsetScroll, IRowsetScrollImpl, IRowsetUpdateImpl, IConnectionPointContainerImpl, IRowsetNotifyCP, IDBCreateSessionImpl, IDBInitializeImpl, IDBPropertiesImpl, IPersistImpl, IInternalConnectionImpl, IGetDataSourceImpl, IOpenRowsetImpl, ISessionPropertiesImpl, IObjectWithSiteSessionImpl, IDBSchemaRowsetImpl, IDBCreateCommandImpl, IAccessorImpl, ICommandTextImpl, ICommandPropertiesImpl, IObjectWithSiteImpl, IConvertTypeImpl, IColumnsInfoImpl, IInternalCommandConnectionImpl

The sample demonstrates the following classes:

CSchemaRowsetImpl, CComObjectRootEx, CComObjectRootEx, CRowsetImpl, CFileArray, CSimpleRow

The sample demonstrates the following macros:

COM_INTERFACE_ENTRY, PROPERTY_INFO_ENTRY

Other Resources

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft