PRB: ATL OLE DB Provider Displays Table Names TwiceID: Q214771
|
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.
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.
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;
}
};
This behavior is by design.
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