Click to open or copy the CATALOG project files.
The CATALOG sample illustrates making calls directly to open database connectivity (ODBC) functions, particularly to SQLTables and SQLColumns. CATALOG shows all the tables in a selected database. For each table, it shows a list of the columns and information about each column.
CATALOG implements a reusable CRecordset-derived class, CColumns, which represents the results set of the call to SQLColumns. This reusable CColumns class is used by the DYNABIND sample, which dynamically examines the list of columns in a table and lets the user update columns not known at compile time.
CATALOG illustrates calling ODBC functions directly. CATALOG's CTables class represents the result set of a call to SQLTables. CColumns represents the result set of a call to SQLColumns. The specific calls to these ODBC functions are in CTables::Open and CColumns::Open. Both illustrations show how you can leverage the Microsoft Foundation Class Library (MFC) record field exchange (RFX) mechanism and CRecordset for result sets returned by ODBC functions that the default result set returns when CRecordset::Open is called.
The CColumns class, derived from CRecordset, is a reusable class that represents the result set of a call to the ODBC SQLColumns function. Each record describes one column of a specified table.
To retrieve the column information for a specific table, construct a CColumns object.
Use the CRecordset-derived function Move to move from one column record to another. To get information about a column, examine the CColumns members m_strTypeName, m_lPrecision, m_lLength, and so on. The names of these members are similar to the parameters for the SQLColumns function documented in the ODBC Programmer's Reference.
When you run CATALOG, select an ODBC data source from the SQL Data Sources dialog box. If you have not registered at least one ODBC data source, see instructions for installing the Student Registration database in the ENROLL sample.
This sample demonstrates the following keywords:
AfxThrowDBException; CDialog::DoModal; CDocument::OnNewDocument; CFrameWnd::Create; CObject::AssertValid; CObject::Dump; CRecordView::OnGetRecordset; CRecordView::OnMove; CRecordset::Close; CRecordset::DoFieldExchange; CRecordset::GetDefaultConnect; CRecordset::GetDefaultSQL; CRecordset::IsOpen; CRecordset::MoveFirst; CRecordset::OnSetOptions; CRecordset::Open; CString::Empty; CString::IsEmpty; CView::GetDocument; CView::OnInitialUpdate; CWinApp::AddDocTemplate; CWinApp::Enable3dControls; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::OnFileNew; CWnd::DoDataExchange; CWnd::OnCreate; LoadBitmap; afxTraceFlags