分享
 
 
 

DAO and MFC

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

DAO and MFC

This article describes MFC's implementation 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 encapsulates 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

Class

DAO object

Remarks

CDaoWorkspace

Workspace

Manages a transaction space and provides access to the database engine.

CDaoDatabase

Database

Represents a connection to a database.

CDaoTableDef

Tabledef

Used to examine and manipulate the structure of a table.

CDaoQueryDef

Querydef

Used to store queries in a database. You can create recordsets from a querydef or use it to execute action or SQL pass-through queries.

CDaoRecordset

Recordset

Used to manage a result set, a set of records based on a table or selected by a query.

CDaoException

Error

MFC responds to all DAO errors by throwing exceptions of this type.

CDaoFieldExchange

None

Manages exchange of data between a record in the database and the field data members of a recordset.

How MFC Manages DAO Objects Not Mapped to Classes

DAO object

How MFC manages it

Field

Objects of classes CDaoTableDef and CDaoRecordset encapsulate fields and supply member functions for adding them, deleting them, and examining them.

Index

Objects 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.

Parameter

Objects of class CDaoQueryDef encapsulate parameters and supply member functions for adding them, deleting them, examining them, and getting and setting their values.

Relation

Objects of class CDaoDatabase encapsulate relations and supply member functions for adding them, deleting 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 doesn't supply classes or interfaces to the DAO group and user objects — to work with DAO security, you must write your own code.

MFC also doesn't encapsulate DAO property objects, except that the MFC DAO classes do give you access to the properties of all exposed objects.

MFC does give you access to DAO's DBEngine object, through class CDaoWorkspace.

Accessing the Unexposed 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, the effect is that the DAO object hierarchy is somewhat "flattened" in MFC. The main examples 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

MFC does not encapsulate the DAO user and group objects in any way, which means that MFC doesn't provide DAO's security functionality.

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 cannot 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 Sources (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 is always available via the See Also button in the topic window.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有