PRB: ATL OLE DB Provider Displays Table Names Twice (214771)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q214771 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.
Modification Type: | Major | Last Reviewed: | 11/17/2003 |
---|
Keywords: | kbprb kbProvider KB214771 |
---|
|