Classes for Obtaining Information About Collections
Object | Class (structure) |
Database | CDaoDatabaseInfo |
Field | CDaoFieldInfo |
Index | CDaoIndexInfo |
Index Field (field that is part of an index object) | CDaoIndexFieldInfo |
Parameter | CDaoParameterInfo |
QueryDef | CDaoQueryDefInfo |
Relation | CDaoRelationInfo |
Relation Field (field that is part of a relation object) | CDaoRelationFieldInfo |
TableDef | CDaoTableDefInfo |
Workspace | CDaoWorkspaceInfo |
One additional DAO object, the error object, is handled somewhat differently in MFC, so you don’t use the technique described in this article to work with error objects. For information, see class CDaoException in the Class Library Reference.
This example shows how to loop through the QueryDefs collection of a CDaoDatabase object and obtain information about the QueryDefs in the collection. The example searches the QueryDefs collection for a particular named query, called “Senior Students”, so it can then extract other information about the query — such as its SQL string or query type.
// pDB is a pointer to a CDaoDatabase object
// Allocate a CDaoQueryDefInfo object to
// receive the information
CDaoQueryDefInfo queryinfo;
int nQueries = pDB->GetQueryDefCount( );
for ( int i = 0; i < nQueries; i++ )
{
pDB->GetQueryDefInfo( i, queryinfo );
if ( queryinfo.m_strName == "Senior Students" )
{
// Get other information about the query ...
// ...
break;
}
}
The code iterates through the collection, retrieving information about each object until the desired named query is found. Note that DAO collections are zero-based.
Tip Some MFC DAO class functions use CDaoXInfo structures for input parameters as well as for output parameters. In those cases, you assign values to a CDaoXInfo object, then pass the object to the function.
The syntax of the GetQueryDefInfo member function used in the example under Example: Obtaining Information About Querydefs is:
void GetQueryDefInfo( int nIndex, CDaoQueryDefInfo& queryinfo, DWORD dwInfoOptions = AFX_DAO_PRIMARY_INFO );
In the example, the queryinfo parameter returns a reference to a CDaoQueryDefInfo object. The example accepts the default value, AFX_DAO_PRIMARY_INFO, for the dwInfoOptions parameter, which specifies what information to return. The following table lists the options in this case.
Constants for Specifying the Levels of Information You Want
Constant | Meaning |
AFX_DAO_PRIMARY_INFO | Primary level of information; in the querydef case, this includes Name and Type. |
AFX_DAO_SECONDARY_INFO | Primary information plus a secondary level of information; in the querydef case, this would include Date Created, Date of Last Update, Returns Records, and Updatable. |
AFX_DAO_ALL_INFO | Primary and secondary information plus additional information: in the querydef case, this would include SQL, Connect, and ODBCTimeout. |
The items listed in column 2 of the table correspond to data members of the appropriate CDaoXInfo structure and, beneath that, to DAO properties.
Notice that the levels of information are cumulative: if you specify a higher level, such as secondary or all, you get the lower levels as well. For details about what information you can obtain for each collection type, see the appropriate GetXInfo functions. The functions are listed in the table Classes for Obtaining Information About Collections.
Caution In many cases, the information obtained with the AFX_DAO_ALL_INFO option can be time-consuming or otherwise costly to obtain. For example, getting a count of the records in a recordset can be time-consuming. Use this option with care.
See Also DAO: Where Is..., DAO Collections