Comparison of Several VC ++ database development technologies
Source: Internet
Author: User
Comparison of Several VC ++ database development technologies-general Linux technology-Linux programming and kernel information. The following is a detailed description. From simple databases (such as Jet Engine) to complex large database systems (such as oracle), VC ++ 6.0 provides some programming interfaces. This article mainly introduces the following five types:
1. odbc api;
2. mfc odbc class;
3. mfc dao class; (Data Access Object)
4. OLE/DB of MFC;
5. ActiveX Data Object (ADO ).
1. Open Database Connection (odbc api ):
Provides a common programming interface that allows programs to connect to a variety of different databases. It provides drivers for Oracle, SQL Server, MS Excel and so on, so that users can use SQL statements to directly operate the underlying functions of the database. When using ODBC APIs, you must introduce the header files "SQL. h", "sqlext. h", "sqltypes. h ". Follow these steps to create a database application using ODBC APIs:
The first step is to allocate an ODBC environment to initialize some internal structures. To complete this step, you must allocate a SQLHENV type variable for use in the ODBC environment as a handle.
The second step is to assign a connection handle to each data source to be used, which is completed by the SQLALLocHandle () function.
The third step is to use SQLConnect () to connect the connection handle to the database. You can first set the connection attribute through SQLSetConnectAttr.
Then you can perform SQL statement operations. Due to space limitations, the relevant functions are not described in detail. Readers can refer to relevant books.
After the operation is complete, the user can retrieve the corresponding results and cancel the connection to the database.
Finally, you need to release the ODBC environment.
ODBC APIs are characterized by powerful functions and advanced functions such as asynchronous operations and transaction processing. However, the corresponding programming is complex and requires a large workload.
2. mfc odbc class:
Classes that encapsulate ODBC functions are introduced in Versions later than MFC1.5. These classes provide interfaces with ODBC, allowing you to perform database operations without having to handle the complicated processing in ODBC APIs. The main mfc odbc classes are as follows.
CDatabase class: A CDatabase object represents a connection to the data source, through which the data source can be operated. Applications can use multiple CDatabase objects: Construct an object and call the OpenEx () member function to open a connection. Then construct the CRecordSet object to operate the connected data source, and pass the record set constructor pointer to the CDatabase object. Use the Close () member function to destroy the CDatabase object. Generally, you do not need to directly use the CDatabase object because the CRecordSet object can implement most of the functions. However, CDatabase plays a key role in transaction processing. A Transaction refers to a series of updates to the data source, which are submitted at the same time or not submitted at the same time to ensure that multiple users operate on the data source at the same time.
CRecordSet class: A CRecordSet object represents a set of records selected from the data source-record set. The record set has two forms: snapshot and dynaset. The former indicates the static view of data, and the latter indicates that the record set is synchronized with other users to update the database. With the CRecordSet object, you can perform various operations on records in the database.
CRecordView class: The CRecordView object is a view that displays database records in a space. This view is a format view directly connected to a CRecordSet object. It creates a template resource from a dialog box and displays the fields of the CRecordSet object in the control of the dialog box template. Objects use the DDX and RFX mechanisms to automate the movement of data between controls in the format and fields in the record set. That is to say, users can simply view database records without writing a line of code.
CDBException class: Derived from the Cexception class, which reflects database operation exceptions with three inherited member variables:
M_nRetCode: indicates the cause of the exception in the form of ODBC return code (SQL _RETURN.
M_strError: string to describe the cause of an error thrown.
M_strStateNativeOrigin: string used to describe the Exception error represented by ODBC error code.
All MFC Database member functions can throw exceptions of the CDBException type. Therefore, it is correct to monitor exceptions after the code operates on the database.
The mfc odbc class is the most widely used in actual development because of its rich functions and ease of operation.
3. mfc dao (Data Access Object) programming:
DAO is used with the Access Database Interface of Microsoft. If the database application only needs to interface with the Access database, DAO programming is more convenient. Its main classes are as follows.
CDaoWorkspace: The CDaoWorkspace object allows a user to manage the entire process of a password-protected database Session from login to departure. In most cases, do not create multiple workspaces or clear workspace objects. Because when opening database and record set objects, they can use the DAO default workspace.
CDaoDatabase: represents a connection, similar to the preceding CDatabase class.
CDaoRecordSet: used to select and operate a record set, similar to the preceding CRecordSet class.
CDaoRecordView: similar to the preceding CRecordView class.
CDaoException: similar to the above CDBException class.
CDaoTableDef: defines a basic table or an additional table. Each DAO database object includes a collection called TableDef, which contains all the DAO table definition objects stored. The CDaoTableDef object can be used to control table definitions.
CDaoQueryDef: The CDaoQueryDef object represents a query definition (querydef ).
CDaoFieldExchange: supports DAO field exchange (DFX) routines used by the database class. It can also process transactions, similar to the mfc odbc class.
Mfc dao is only used to support Access databases, and its application scope is relatively fixed.
4. ole db:
Ole db provides flexible Component Object Model (COM) interfaces between data providers and users, which sometimes complicate operations. The ole db Framework defines three basic classes of applications.
Data Provider: an application that has its own Data and displays Data in tables. The row set COM interface of ole db is provided. The period display range can be used to know more complex distributed database systems from simple providers of a single data table.
User Consumers: the application that uses the ole db interface to control the data stored in the data provider. User applications are classified as usage classes.
Service Provider: A combination of data providers and users. The service provider does not have its own data, but uses the ole db user interface to access data stored in the data provider. Then, the service provider opens the data provider interface to make the data valid for the user. Service providers are often used to provide high-level services to applications, such as advanced distributed queries.
During ole db programming, you can use component objects to develop applications. These components include:
Enumerator: Used to list available data sources;
Data source: represents individual data and service providers for creating dialogs;
Dialog: used to create transactions and commands;
Transaction: Used to merge multiple operations into a single transaction;
Command: used to send a text command (SQL) to the data source and return the row set;
Error: used to obtain error information.
5. ActiveX Data Object (ADO): It is an object-oriented interface provided by Microsoft. It is similar to ole db, but the interface is simpler, with a wider array of features and higher flexibility. Based on COM, ADO provides the objects available for programming languages. In addition to VC ++, it also provides applications for various development tools, such as VB and VJ. ADO is very useful in Server applications, especially for Dynamic Server Pages (ASP ).
The ADO object structure is similar to ole db, but does not rely on Object layers. In most cases, you only need to create and use the objects to be processed. The following object classes constitute the ADO interface.
Connection: used to indicate the Connection to the database and process some commands and transactions.
Command: The Command used to process the data sent to the data source.
Recordset: The table set used to process data, including obtaining and modifying data.
Field: indicates the column information in the record set, including the column value and other information.
Parameter: used to send data back and forth between commands sent to the data source.
Property: Detailed properties of other objects used in ADO.
Error: used to obtain detailed information about possible errors.
COM operations are required to use ADO in VC ++. The detailed method will not be described here.
In today's popular distributed development environment, VC ++ 6.0 has a strong advantage in database development and learns to use different technologies on different occasions, it is a necessary technology for developers.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.