OLE DB is a strategic, low-level application interface for Microsoft that leads to different data sources. OLE DB includes not only the Structured Query Language (SQL) capability of the Microsoft-funded standard data Interface Open Database Connectivity (ODBC), but also access to other non-SQL data types. As a design of Microsoft's Component Object Model (COM), OLE DB is a set of methods for reading and writing data (which in the past may be called a channel). Objects in OLE DB primarily include data source objects, stage objects, command objects, and row group objects.
Foreign namesOLE DBObjectData sources, stages, commands, row group objectsProposed companyMicrosoft CorporationmeaningLow-level program interface directory to different data sources
-
1 definitions
-
2 Introduction
-
3 composition
-
4 Features
-
5 Structural problems
-
6 Practical applications
1 definition edits OLE DB (Object linking and Embedding,database, also referred to as OLE or OLE-DB), a COM-based data store object that provides operations on all types of data, and even access to data offline (for example, You're using your laptop, and you can see the data image at the last data sync effortlessly.2 Introduction to editing OLE DB is located between the ODBC layer and the application. In your ASP page, ADO is an application that is located above OLE DB. Your ADO call is sent to OLE DB before being processed by ODBC. You can connect directly to the OLE DB layer, and if you do, you'll see a performance boost for server-side cursors (the default cursor for the recordset and the most common cursor). OLE DB (OLE DB) is Microsoft's strategic low-level application interface to different data sources. OLE DB includes not only the Structured Query Language (SQL) capability of the Microsoft-funded standard data Interface Open Database Connectivity (ODBC), but also the path for other non-SQL data types. As a design of Microsoft's Component Object Model (COM), OLE DB is a set of methods for reading and writing data (which in the past may be called a channel). Objects in OLE DB primarily include data source objects, stage objects, command objects, and row group objects. Applications that use OLE DB use the following sequence of requests: Initialize OLE, connect to a data source, issue commands, process results, release data source objects, and stop initializing OLE.3 composition edits New concepts defined in the OLE DB standard----OLE DB divides a traditional database system into logical components that are relatively independent and communicate with each other. Each part of this component model is labeled with a different name. For example, data Provider is a software component that provides data storage, small to normal text files, a complex database that is large to a host, or an e-mail store, which is an example of a data provider. Some documents refer to developers of these software components as data providers. To open data in an Access database, we must use ADOT to open it through OLE DB. At using OLE DB to obtain data because OLE DB knows how to communicate with many kinds of data sources, it is important to have a good understanding of OLE DB. OLE DB is an open standard and is designed as a COM (Componentobject Model, an object format. All components produced according to COM specifications can be used by other programs or components to provide functionality. Components OLE DB is mostly composed of three parts:
1.Data Providers data providers who provide data through OLE DB are the data providers. For example, a data table in a SQL Server database, or an Access database file named MDB, is a Provider. ⒉data Consumers data users are those who use OLE DB to provide data to programs or components that are data users of OLE DB. In other words, all applications or Web pages that use ADO are data users of OLE DB. ⒊service Component service Component data Service components can perform the work of data delivery between data providers and data users, and data users are required to perform queries against the query processor of the OLE DB service component when they want data from the data provider. The query results are managed by the pointer engine.4 functional editing Applications that use OLE DB use the following sequence of requests: initializing OLE connections to the data source issuing command processing results releasing the data source object and stopping initialization Oleole DB is the data access model for Microsoft. Unlike ODBC, which uses the Component Object Model (COM) interface, OLE DB assumes that the data source is not using a SQL query processor. Adaptive Server Anywhere includes an OLE DB provider named Asaprov. This provider is available for the current Windows and Windows CE platforms. You can also use the Microsoft OLE DB Provider for ODBC (MSDASQL) and the Adaptive server anywhere ODBC driver to access Adaptive server anywhere. Using the Adaptive Server anywhere OLE DB provider has several advantages: • Some features, such as updating via cursors, cannot be used through OLE Db/odbc Bridge. • If you use Adaptive Server anywhere OLE DB provider, ODBC is not required during the deployment process. MSDASQL allows OLE DB clients to be used with any ODBC driver, but does not guarantee that you can use the full functionality of each ODBC driver. While using the Adaptive server anywhere provider, you can fully access the full functionality of Adaptive server anywhere from the OLE DB programming environment.5 structural problem editing Before you start writing an OLE DB application, consider the following question: What programming implementation do you use to write an OLE DB application? Microsoft provides a variety of libraries to address this issue: The OLE DB Template Library, OLE DB properties, and the original OLE DB interface in the OLE DB SDK. In addition, Microsoft provides wizards to help you write programs. For more detailed information about these implementations, see OLE DB templates, properties, and other implementations. Do you need to write your own provider? This is not required for most developers. Microsoft offers a variety of providers. Whenever a user creates a data connection, for example, when you add a consumer to a project by using the ATL OLE DB Consumer Wizard, the Data Link Properties dialog box lists all the available providers that are registered on the system. If one of the providers is appropriate for the user's own data store and data Access application, the simplest approach is to use the provider. However, if the user's data store does not fit the provided category, you must create your own provider. For information about creating a provider, see OLE DB Provider Templates and their subtopics. What level of support do you need to provide for your users? Some users may be very simple, others may be very complex. The functionality of an OLE DB object is specified by a property. When you create a consumer by using the ATL OLE DB Consumer Wizard or when you create a provider by using the Database Provider Wizard, the wizard sets the appropriate object properties for the user to provide a set of standard features. However, if the wizard-generated consumer class or provider class does not have all the support features you need, you need to consult the interfaces of these classes in the OLE DB template Gallery. These interfaces wrap the original OLE DB interface, providing additional implementations to make it easier to use. For example, if you want to update the data in a rowset, but you forget to specify the feature when you use the wizard to create the consumer, you can specify the feature after you create the consumer by setting the DBPROP_IRowsetChange and Dbprop_updatability properties on the Command object. This way, when the rowset is created, it will have the IRowsetChange interface. Do you have legacy code that uses other data access technologies (ADO, ODBC, or DAO)? Visual C + + documentation does not cover all scenarios because there may be various combinations of technologies, such as ADO components and OLE DB components, migrating ODBC code to OLE DB, and so on.6 practical application edit 1 Overview The presence of OLE DB provides a unified way for users to access all different kinds of data sources. OLE DB can be converted in different data sources. With Ole DB, the client's developers only have to focus on a few details when making data access, rather than having to understand a large number of access protocols for different databases. OLE DB is a set of ActiveX interfaces that access data through a COM interface. This OLE DB interface is quite generic enough to provide a uniform means of accessing data, regardless of the method used to store the data. At the same time, OLE DB allows developers to continue leveraging the benefits of the underlying database technology without having to move the data out to take advantage of these benefits. 2 use ATL to use OLE DB data usage programs because you design database applications directly using OLE DB objects and interfaces, you need to write a large amount of code. To simplify programming, Visual C + + provides an ATL template for designing OLE DB data applications and data providers. The ATL template makes it easy to combine OLE DB with MFC, simplifying complex programming such as database parameter queries. The database classes provided by MFC make OLE DB programming more object-oriented. Viual C + + provides an ATL template for OLE DB that can be divided into templates for data providers and data usage programs. Using an ATL template to create a data application typically has the following steps: Creating an application framework to join ATL generated template classes to use resulting data access objects in your app without ATL using OLE DB data usage programs using an ATL template to produce data using a program is simpler, but not widely applicable, Changes to the database cannot be dynamically adapted. The following is an introduction to using the MFC OLE DB class directly to generate a data usage program. The use of the OLE DB data consumer template for templates is made up of templates that include some of the following templates, some of which are described in some common classes. The session class CDataSource class CDataSource class corresponds to the OLE DB data source object. This class represents the connection between the OLE DB data provider and the data source. A session object can be generated only if the connection to the data source has been established, and the connection to the data source may be opened by calling Open. The object created by the CSession class CSession represents a separate session for database access. A data source object created with the CDataSource class can create one or more sessions, and to generate a session object on the data source object, the function open () needs to be called. The session object can also be used to create transaction operations. The CEnumeratorAccessor class CEnumeratorAccessor class is an accessor that is used to access information from the available data providers in the rowset resulting from an enumerator query.Can provide the currently available data provider and? The CAccessor class represents the type of the accessor. This class can be used when the user knows the type and structure of the database. It supports multiple accessors for a rowset, and the buffer that holds the data is assigned by the user. The CDynamicAccessor class CDynamicAccessor class is used to create accessors dynamically while the program is running. When the system is running, you can dynamically obtain column information from the rowset, and you can dynamically create accessors based on this information. The CManualAccessor class CManualAccessor class to bind a column to a variable while the program is running, or to bundle a parameter with a variable. The rowset class CRowset class CRowset class encapsulates the rowset object and the corresponding interface, and provides methods for querying, setting up data, and so on. You can use functions such as Move () to record movement, read data with the GetData () function, and update data with insert (), Delete (), SetData (). The CBulkRowset class CBulkRowset class is used to retrieve multiple row handles in a single call or to manipulate multiple rows. The CArrayRowset class CArrayRowset class provides data access with array subscripts. The command class CTable class CTable class is used for simple access to the database, with the name of the data source to get the rowset, resulting in data. The CCommand class CCommand class is used to support a data source for a command. You can use the open () function to execute SQL commands, or the prepare () function to prepare the command, which can improve the flexibility and robustness of the data source that supports the command. In the StdAfx.h header file, add the following code. #includeextern CComModule _module; #include #include#include//If you are using the schema templates in the Stdafx.cpp file, add the following code. #includeCComModule _module; Decide what type of accessor and rowset to use. Get data when you open a data source, session, rowset object, you can get the data. The data type you get depends on the accessor you are using, and you may need to bind the column. Follow the steps below. Open the rowset object with the correct command. If you use CManualAccessor, bind to the corresponding column before use. To bind a column, you can use the function GetColumnInfo as follows://Get the column Informationulong ulcolumns = 0;dbcolumninfo* Pcolumninfo = NULL Lpolestr pstrings = null;if (rs. GetColumnInfo (&ulcolumns,&pcolumninfo,&pstrings)! = S_OK) afxthrowoledbexception (rs.m_prowset,ⅱd_ IColumnsInfo); struct mybind* pbind = new Mybind "Ulcolumns"; Rs. CreateAccessor (ulcolumns,&pbind "0", sizeof (Mybind) *ulcolumns); for (ULONG l=0; l<>rs. AddBindEntry (l+1,dbtype_str,sizeof (TCHAR) *40,&pbind "L". Szvalue,null,&pbind "L". dwstatus); Rs. Bind (); Use the while loop to fetch the data. In the loop, call MoveNext to test whether the return value of the cursor is S_OK, as follows: while (Rs. MoveNext () = = S_OK) {//ADD code to fetch data here//If is not using a auto Accessor,call Rs. GetData ()} In a while loop, you can get the data through different accessors. If you are using the CAccessor class, you can access it directly by using their data members. As shown below: If you are using the CDynamicAccessor or CDynamicParameterAccessor class, you can get the data through the GetValue or GetColumn function. You can use GetType to get the data type you are using. As shown below: while (Rs. MoveNext () = = S_OK) {//Use the dynamic accessor functions to retrieve your//dataulong ulcolumns = Rs. getColumnCount (); for (ULONG i=0; i<>{rs. GetValue (i);}} If you are using CManualAccessor, you can specify your own data members and bind them. can be accessed directly. As shown below: while (Rs. MoveNext () = = S_OK){//Use the data section specified in the Calls to//addbindentry.wsprintf ("%s", Szfoo);} Determines whether the data type of a rowset determines the data type at run time, using a dynamic or manual access program. If you are using a manual access program, you can use the GetColumnInfo function to get the column information for the rowset. The data type can be obtained from here. 3 Summary Because there are a variety of data sources, the only way to manage access to these data is through some kind of mechanism, such as OLE DB. The Advanced OLE DB structure is divided into two parts: the customer and the provider. The customer uses the data generated by the provider. Like most other COM-based architectures, OLE DB developers need to implement many interfaces, most of which are template files. When you build a customer object, you can create a simple customer by pointing to a data source through the ATL Object Wizard. The ATL Object Wizard examines the data source and creates a client agent for the database. From there, you can use the standard browse functions through the OLE DB client templates. When a provider is generated, the wizard provides a good starting point by simply generating a simple provider to enumerate the files in a directory. The provider template then contains the fully supplemental content supported by OLE DB. With this support, users can create OLE DB providers to implement rowset positioning policies, data read and write, and bookmark creation.
Introduction to OLE DB