Changing the Run Button Handler

You must add code to set the DBPROP_IRowsetLocate property, as shown below. This property tells the provider that the consumer wants a bookmark column. In this code, the while loop contains a call to IRowsetLocate::Compare. This call should always succeed, since it compares a bookmark to itself. The call stores the bookmark in a temporary variable, so that the value will be available later to call MoveToBookmark.

//////////////////////////////////////////////////////////////////////
// TestProv Consumer Application in TestProvDlg.cpp

void CTestProvDlg::OnRun() 
{
   CCommand<CAccessor<CProvider>> table;
   CDataSource source;
   CSession   session;

   if (source.Open(“MyProvider.MyProvider.1”, NULL, NULL, NULL, 
          NULL) != S_OK)
      return;

   if (session.Open(source) != S_OK)
      return;

   CDBPropSet propset(DBPROPSET_ROWSET);
   propset.AddProperty(DBPROP_IRowsetLocate, true);
   if (table.Open(session, _T("c:\\public\\testprf2\\foo.txt"), 
          &propset) != S_OK)
      return;

   CBookmark<4> tempBookmark;
   ULONG ulCount=0;
   while (table.MoveNext() == S_OK)
   {

      DBCOMPARE compare;
      if (ulCount == 2)
         tempBookmark = table.bookmark;
         hr = table.Compare(table.bookmark, table.bookmark,
                 &compare);
      if (FAILED(hr))
         ATLTRACE(_T("Compare failed: 0x%X\n"), hr);
      else
         ATLASSERT (compare == DBCOMPARE_EQ);

      m_ctlString1.AddString(table.szCommand);
      m_ctlString2.AddString(table.szText);
      ulCount++;
   }

   table.MoveToBookmark(tempBookmark);
   m_ctlString1.AddString(table.szCommand);
   m_ctlString2.AddString(table.szText);
}

Back to Modifying the Consumer for Use with the Enhanced Provider