Dao and MFC

xiaoxiao2021-03-06  61

Dao and MFC

This Article Describes MFC's Implement Of Microsoft Data Access Objects (DAO). Topics Covered Include:

How mfc encapsulates Dao mapping of dao Objects to mfc classes Key Differences Between MFC and Dao Further Reading About The MFC Dao Classes

Note Whether you use the MFC DAO classes or the MFC ODBC classes depends on your situation and your needs. For a discussion of the differences between the two and guidance on choosing one, see the article Database Topics (DAO).

How mfc encapsulates Dao

The MFC DAO classes treat DAO much as the MFC classes for programming Windows treat the Windows API: MFC encapsulates, or "wraps," DAO functionality in a number of classes that correspond closely to DAO objects Class CDaoWorkspace encapsulates the DAO workspace object, class. CDAORECORDSET Encapsules The Dao RecordSet Object, Class Cdaodatabase Encapsulates The DAO DATABASE Object, And So ON.

MFC's encapsulation of DAO is thorough, but it is not completely one-for-one. Most major DAO objects do correspond to an MFC class, and the classes supply generally thorough access to the underlying DAO object's properties and methods. But some DAO objects, Including Fields, Indexes, Parameters, And Relations, Do Not. Instead, The Appropriate MFC Class Provides An Interface, Via Member Functions, Through Which You CAN Access, for EXAMPLE:

THE FIELDS OF A Recordset Object The Indexes OR Fields of a Table The Parameters of a QueryDef The Relations Defined Between Tables in A Database

Mapping of dao Objects to MFC Classes

The following tables show how DAO objects correspond to MFC objects. MFC Classes and Corresponding DAO Objects shows the MFC classes and the DAO objects they encapsulate. How MFC Manages DAO Objects Not Mapped to Classes shows how MFC deals with DAO objects that do not map directly To an MFC Class.note MFC Now Supports Dao 3.5. MFC Dao Classes Work Either With Dao 3.0 or Dao 3.5, But Have Not Been Designed to Take Advantage of Any New Dao 3.5 Features, Including Odbcdirect.

MFC Classes and Corresponding Dao Objects

ClassDAO objectRemarksCDaoWorkspaceWorkspaceManages a transaction space and provides access to the database engine.CDaoDatabaseDatabaseRepresents a connection to a database.CDaoTableDefTabledefUsed to examine and manipulate the structure of a table.CDaoQueryDefQuerydefUsed to store queries in a database. You can create recordsets from a querydef or use it to execute action or SQL pass-through queries.CDaoRecordsetRecordsetUsed to manage a result set, a set of records based on a table or selected by a query.CDaoExceptionErrorMFC responds to all DAO errors by throwing exceptions of this type.CDaoFieldExchangeNoneManages exchange of data between a record In The Database and The Field Data Membase of a Recordset.

How MFC Manages Dao Objects Not Mapped To Classes

DAO objectHow MFC manages itFieldObjects of classes CDaoTableDef and CDaoRecordset encapsulate fields and supply member functions for adding them, deleting them, and examining them.IndexObjects of classes CDaoTableDef and CDaoRecordset encapsulate indexes and supply member functions for managing them. Tabledefs can add, delete, and examine indexes. Tabledefs and recordsets can set or get the currently active index.ParameterObjects of class CDaoQueryDef encapsulate parameters and supply member functions for adding them, deleting them, examining them, and getting and setting their values.RelationObjects of class CDaoDatabase encapsulate relations and supply Member functions for adding them, deleding them, and examining them.dao objects not exposed in mfc

MFC and DAO do not supply abstractions for some objects used within Microsoft Access: Application, Container, Control, Debug, Document, Form, Module, Report, Screen, and Section If you create a Microsoft Access database and manipulate it from an MFC application. You can't Access Those Objects through code.

.

.

Mfc Does Give You Access To Dao's DbEngine Object, Through Class Cdaoworkspace.

Accessing the unnexposed Dao Objects

The Unexposed Objects listed Above Can Be Accessed In Two Ways:

Outside the MFC classes by using the non-MFC C classes provided in the DAO SDK. Inside the MFC classes by calling DAO directly through a DAO interface pointer supplied by one of the MFC classes. For information, see Technical Note 54.Key Differences Between MFC and Dao

MFC's Version of Data Access Objects Differs from The Underlying Structure of Dao in Some Ways.

How MFC Accesses The Database Engine

DAO HAS A DBENGINE OBJECT THAT REPRESENTS The Microsoft Jet Database Engine. The DBENGINE Object Provides Properties and Methods You can Use to configure the database engine.

In MFC, there is no DBEngine object Access to important properties of the database engine is supplied via class CDaoWorkspace To set or get these properties, call any of the static member functions of CDaoWorkspace For more information, see the articles DAO Workspace...: The Database Engine and Dao Workspace: Accessing Properties of The Database Engine.

MFC Flattening of the Dao Object Hierarchy

Because Mfc Doesn't Supply a class for Every Dao Object Hierarchy Is Somewhat "flattened" in mfc. The main example of this flattening Are:

Putting access to the database engine in class CDaoWorkspace rather than in a database engine class. Encapsulating DAO field, index, parameter, and relation objects inside the classes that represent their owning objects. For example, access to fields is encapsulated in classes CDaoTableDef and CDaoRecordset For Information, See The Table How MFC Manages Dao Objects Not Mapped to Classes.

MFC and Dao Security

.

You can still use DAO security from your MFC applications, but you will have to call DAO directly, using the m_pDAOWorkspace data member of class CDaoWorkspace. That member is a pointer to an interface that gives access to a DAO workspace object's methods and properties. For information about calling DAO directly, see Technical Note 54.MFC does allow password protection via various MFC classes. For example, when you create a CDaoWorkspace object, you can specify a password to protect the database (s) that the workspace contains. to use this functionality, a SYSTEM.MDW file must be available to the database engine on the machine running your application. If no SYSTEM.MDW file is available to the database engine, your application can not use any of the security features. For information about the SYSTEM .Mdw file, see the topic "Permissions Property" in Dao Help.

Further Reading About The MFC Dao Classes

To Learn More About Using The MFC Dao Classes, See The Following Articles (In The ORDER Listed Here):

DAO: Writing a Database Application DAO: Database Tasks DAO: Creating, Opening, and Closing DAO Objects DAO Workspace DAO Database DAO Database: Using Workspaces and Databases DAO Recordset DAO Record Field Exchange (DFX) DAO Querydef DAO Tabledef DAO Workspace: Managing Transactions DAO Collections Dao External: Working with External Data Source (Primarily ODBC) DAO WORKSPACE: The Database Engine Dao: Using Dao in Dlls Exceptions: Database Exceptions Record Views

Tip From any of the MFC help topics in this documentation set, you can get to a topic called DAO: Where Is ..., which helps you navigate online to the topics that you need The topic via is always available the See Also button. In the topic window.

转载请注明原文地址:https://www.9cbs.com/read-84767.html

New Post(0)