次の方法で共有


DAO Collections

OverviewHow Do IFAQSampleODBC Driver List

This article explains how to access the “collections” in which DAO keeps active DAO objects at all levels of the DAO object hierarchy. The article also explains how the collections are exposed in MFC. Topics covered include:

  • DAO collections: definitions

  • How MFC exposes DAO collections

  • The default object in a collection

  • How to access a collection

  • The information you obtain about objects in a collection

  • Contents of MFC DAO information structures

  • Primary, Secondary, and All information

  • Information about collections in DAO

DAO Collections: Definition

In DAO, each object in the object hierarchy maintains one or more "collections" of subordinate objects. For example, the Microsoft Jet database engine maintains a collection of open workspaces. Each workspace object maintains a collection of open databases (and other collections, related to security). And so on. For a list of the DAO objects and the collections they house, see the topic "Data Access Objects and Collections Reference" in DAO Help.

How MFC Exposes DAO Collections

In the MFC DAO classes, MFC doesn't maintain a collection (such as a CObArray) of C++ objects parallel to the underlying DAO collection. Rather, MFC supplies member functions and/or data members through which you can access the underlying collection itself in DAO, where the DAO collections are stored. For example, class supplies the member function to determine how many workspaces are in the database engine's Workspaces collection and the member function to examine information about any workspace in the collection.

In general, the MFC DAO classes supply similar functions for all relevant DAO collections. The one significant exception is the Recordsets collection of the database object. MFC does not supply GetRecordsetCount and GetRecordsetInfo member functions in class . When you work with recordsets, you always have an explicit MFC object in your application. It's up to you to keep track of which recordsets you have open.

The Default Object in a Collection

The first element in a DAO collection, at element 0, is the default element of the collection. In particular, DAO's default workspace is element 0 in the Workspaces collection. Collections are zero-based.

How to Access a Collection

The following procedure uses the TableDefs collection of a object to illustrate the general process for accessing objects in a DAO collection.

To access the TableDefs collection (for example)

  1. Construct a object, or get a pointer to one from a object.

  2. Call the object's member function unless you have obtained a database pointer from a recordset.

  3. Use the and member functions of the object to determine how many tabledefs the collection contains and to loop through the collection, obtaining information about each tabledef object.

For an example, see the LISTVIEW.CPP file in the MFC Database sample . For a procedure, see the article DAO Collections: Obtaining Information About DAO Objects.

The Information You Obtain About Objects in a Collection

To obtain information about the objects in a collection, you call a GetXInfo member function of the appropriate class. This function returns an object of one of the CDaoXInfo structures listed in the table Classes for Obtaining Information About DAO Objects in the article DAO Collections: Obtaining Information About DAO Objects. In general, there is a CDaoXInfo structure associated with each DAO object. These structures are commonly referred to as the MFC DAO “information structures.”

Contents of MFC DAO Information Structures

A typical information structure looks something like this:

struct CDaoDatabaseInfo
{
   CString m_strName;       // Primary
   BOOL m_bUpdatable;       // Primary
   BOOL m_bTransactions;    // Primary
   CString m_strVersion;    // Secondary
   long m_lCollatingOrder;  // Secondary
   short m_nQueryTimeout;   // Secondary
   CString m_strConnect;    // All
};

For detailed descriptions of the structure members, see the individual structure in the Class Library Reference. Structures are listed in the table Classes for Obtaining Information About DAO Objects in the article DAO Collections: Obtaining Information About DAO Objects.

Primary, Secondary, and All Information

The notations “Primary,” “Secondary,” and “All” indicate which MFC DAO structure members are filled when you call a function such as . You can specify that you want just primary information, both primary and secondary information, or all information. Some structures don’t include anything under the All designation.

****Caution   ****Using the Secondary and All options can be slow. In general, Primary is faster than Secondary, and Secondary is faster than All. Don’t use All unless you must.

For more information about using GetTableDefCount, GetTableDefInfo, and similar functions, see the article DAO Collections: Obtaining Information About DAO Objects.

Information About Collections in DAO

For general information about the DAO collections, see the topic "Data Access Objects and Collections Reference" in DAO Help.

See Also   DAO: Where Is...