PRB: ATL OLE DB Provider Displays Table Names Twice

ID: Q214771


The information in this article applies to:


SYMPTOMS

An ATL wizard generated OLE DB Provider displays table names twice when you select the ADO Data Control RecordSource tab and the Command Type adCmdTable.

The drop-down Table listbox shows the table twice.


CAUSE

The default ATL wizard generated ATL OLE DB Provider does not check the criteria for the table schema rowset (see TABLES schema rowset in Appendix B of the OLE DB Programmer's Reference). The ADO Data control requests the table schema rowset twice: once to get tables and again to get database views. In the case of the default ATL Wizard generated provider, the table schema rowset should not return any rows when the TABLE_TYPE criteria is VIEW.


RESOLUTION

In the Execute() method of the CTABLESRow schema class, check the criteria for TABLE and only return records if the criteria is TABLE or if there is no criteria specified.

For example:


class CMyProviderSessionTRSchemaRowset : 
     public CRowsetImpl<CMyProviderSessionTRSchemaRowset, CTABLESRow,
                        CMyProviderSession>
{
   public:

   HRESULT Execute(LONG* pcRowsAffected, ULONG cRestrictions,
                   const VARIANT* rgRestrictions)
   {
      if ((cRestrictions < 3) || (cRestrictions >= 3 && 
           wcscmp(V_BSTR(&rgRestrictions[3]), L"TABLE") == 0))
      {
         USES_CONVERSION;
         Cdbl2WindowsFile wf;
         CTABLESRow trData;
         lstrcpyW(trData.m_szType, OLESTR("TABLE"));
         lstrcpyW(trData.m_szDesc, OLESTR("The Directory Table"));
         HANDLE hFile = INVALID_HANDLE_VALUE;
         TCHAR szDir[MAX_PATH + 1];
         DWORD cbCurDir = GetCurrentDirectory(MAX_PATH, szDir);
         lstrcat(szDir, _T("\\*.*"));
         hFile = FindFirstFile(szDir, &wf);
         if (hFile == INVALID_HANDLE_VALUE)
            return E_FAIL; // User does not have a c:\ drive.
         FindClose(hFile);
         lstrcpynW(trData.m_szTable, T2OLE(szDir), 
              SIZEOF_MEMBER(CTABLESRow, m_szTable));
         if (!m_rgRowData.Add(trData))
              return E_OUTOFMEMORY;
         *pcRowsAffected = 1;
      }
      else 
         *pcRowsAffected = 0;
	
      return S_OK;
   }
}; 


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create and build a wizard generated ATL Provider.


  2. Create a Visual C++ MFC dialog based application and add the Microsoft ADO Data Control to the dialog box.


  3. Bring up the properties for the ADO Data Control and click the Control tab. Type in the connection string for the ATL generated provider you created.


  4. Click the RecordSource tab for the ADO Data Control and select the Command Type adCmdTable.


  5. On the RecordSource tab, click on the Table or Stored Procedure Name list box. Notice the duplicate entries.


Additional query words:


Keywords          : kbATL kbOLEDB kbProvider kbVC600 kbVS600 
Version           : WINDOWS:6.0; winnt:6.0
Platform          : WINDOWS winnt 
Issue type        : kbprb 

Last Reviewed: March 3, 1999