You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* oledb-tutorial-review pr3
* broken link
* minor edit
* minor edit
* minor formats
* changes per @corob-msft
* link updates
* Update creating-an-ole-db-provider.md
- Updated links to samples.
When you use the ATL OLE DB Consumer Wizard to generate a consumer, you have the choice of using OLE DB Templates or OLE DB attributes. In both cases, the wizard generates a command class and a user record class. The command class contains code to open the data source and rowset you specified in the wizard. The user record class contains a column map for the database table you selected. However, the generated code differs in each case:
16
+
When you use the **ATL OLE DB Consumer Wizard** to generate a consumer, you have the choice of using OLE DB Templates or OLE DB attributes. In both cases, the wizard generates a command class and a user record class. The command class contains code to open the data source and rowset you specified in the wizard. The user record class contains a column map for the database table you selected. However, the generated code differs in each case:
17
17
18
-
- If you select a templated consumer, the wizard generates a command class and a user record class. The command class will have the name that you enter in the Class box in the wizard (for example, `CProducts`), and the user record class will have a name of the form "*ClassName*Accessor" (for example, `CProductsAccessor`). Both classes are placed in the consumer's header file.
18
+
- If you select a templated consumer, the wizard generates a command class and a user record class. The command class will have the name that you enter in the **Class** box in the wizard (for example, `CProducts`), and the user record class will have a name of the form "*ClassName*Accessor" (for example, `CProductsAccessor`). Both classes are placed in the consumer's header file.
19
19
20
20
- If you select an attributed consumer, the user record class will have a name of the form "_*ClassName*Accessor" and will be injected. That is, you will be able to view only the command class in the text editor; you can only view the user record class as injected code. For information about viewing injected code, see [Debugging Injected Code](/visualstudio/debugger/how-to-debug-injected-code).
21
21
22
-
The following examples use a command class created on the Products table of the Northwind database to demonstrate the wizard-generated consumer code for the command class and user record class.
22
+
The following examples use a command class created on the `Products` table of the `Northwind` database to demonstrate the wizard-generated consumer code for the command class and user record class.
23
23
24
24
## Templated User Record Classes
25
25
@@ -30,10 +30,10 @@ If you create an OLE DB consumer using the OLE DB Templates (rather than the OLE
30
30
The first part of the user record class includes the data member declarations and the status and length data members for each data-bound column. For information about these data members, see [Field Status Data Members in Wizard-Generated Accessors](../../data/oledb/field-status-data-members-in-wizard-generated-accessors.md).
31
31
32
32
> [!NOTE]
33
-
> If you modify the user record class or write your own consumer, the data variables must come before the status and length variables.
33
+
> If you modify the user record class or write your own consumer, the data variables must come before the status and length variables.
34
34
35
35
> [!NOTE]
36
-
> The ATL OLE DB Consumer Wizard uses the `DB_NUMERIC` type to bind numeric data types. It formerly used `DBTYPE_VARNUMERIC` (the format of which is described by the `DB_VARNUMERIC` type; see Oledb.h). If you do not use the wizard to create consumers, it is recommended that you use `DB_NUMERIC`.
36
+
> The ATL OLE DB Consumer Wizard uses the `DB_NUMERIC` type to bind numeric data types. It formerly used `DBTYPE_VARNUMERIC` (the format of which is described by the `DB_VARNUMERIC` type; see Oledb.h). If you do not use the wizard to create consumers, it is recommended that you use `DB_NUMERIC`.
37
37
38
38
```cpp
39
39
// Products.H : Declaration of the CProducts class
@@ -142,7 +142,7 @@ class CProducts : public CCommand<CAccessor<CProductsAccessor>>
142
142
143
143
## Attribute-Injected User Record Classes
144
144
145
-
If you create an OLE DB consumer using the database attributes ([db_command](../../windows/db-command.md) or [db_table](../../windows/db-table.md)), the attributes inject a user record class with a name of the form "_*ClassName*Accessor." For example, if you named your command class `COrders`, the user record class will be `_COrdersAccessor`. Although the user record class appears in Class View, double-clicking it navigates to the command or table class in the header file instead. In these cases, you can only view the actual declaration of the user record class by viewing the attribute-injected code.
145
+
If you create an OLE DB consumer using the database attributes ([db_command](../../windows/db-command.md) or [db_table](../../windows/db-table.md)), the attributes inject a user record class with a name of the form "_*ClassName*Accessor." For example, if you named your command class `COrders`, the user record class will be `_COrdersAccessor`. Although the user record class appears in **Class View**, double-clicking it navigates to the command or table class in the header file instead. In these cases, you can only view the actual declaration of the user record class by viewing the attribute-injected code.
146
146
147
147
There can be potential complications if you add or override methods in attributed consumers. For example, you could add a `_COrdersAccessor` constructor to the `COrders` declaration, but note that in reality this adds a constructor to the injected `COrdersAccessor` class. Such a constructor can initialize the columns/parameters, but you cannot create a copy constructor this way, because it cannot directly instantiate the `COrdersAccessor` object. If you need a constructor (or other method) directly on the `COrders` class, it is recommended that you define a new class deriving from `COrders` and add the necessary methods there.
Copy file name to clipboardExpand all lines: docs/data/oledb/creating-a-consumer-without-using-a-wizard.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Creating a Consumer Without Using a Wizard | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "11/04/2016"
4
+
ms.date: "10/12/2018"
5
5
ms.technology: ["cpp-data"]
6
6
ms.topic: "reference"
7
7
dev_langs: ["C++"]
@@ -17,7 +17,7 @@ The following example assumes that you are adding OLE DB consumer support to an
17
17
18
18
To add OLE DB consumer support without using the ATL OLE DB Consumer Wizard:
19
19
20
-
- In your Stdafx.h file, append the following `#include` statements:
20
+
- In your pch.h file, append the following `#include` statements:
21
21
22
22
```cpp
23
23
#include<atlbase.h>
@@ -27,10 +27,10 @@ To add OLE DB consumer support without using the ATL OLE DB Consumer Wizard:
27
27
28
28
Programmatically, a consumer typically performs the following sequence of operations:
29
29
30
-
- Create a user record classthat binds columns to local variables. In this example, `CMyTableNameAccessor` is the user record class (see [User Records](../../data/oledb/user-records.md)). This class contains the column map and parameter map. Declare a data member in the user record class for each field you specify in your column map; for each of these data members, also declare a status data member and a length data member. For more information, see [Field Status Data Members in Wizard-Generated Accessors](../../data/oledb/field-status-data-members-in-wizard-generated-accessors.md).
30
+
1. Create a user record classthat binds columns to local variables. In this example, `CMyTableNameAccessor` is the user record class (see [User Records](../../data/oledb/user-records.md)). This class contains the column map and parameter map. Declare a data member in the user record class for each field you specify in your column map; for each of these data members, also declare a status data member and a length data member. For more information, see [Field Status Data Members in Wizard-Generated Accessors](../../data/oledb/field-status-data-members-in-wizard-generated-accessors.md).
31
31
32
32
> [!NOTE]
33
-
> If you write your own consumer, the data variables must come before the status and length variables.
33
+
> If you write your own consumer, the data variables must come before the status and length variables.
34
34
35
35
- Instantiate a data source and a session. Decide what type of accessor and rowset to use and then instantiate a rowset using [CCommand](../../data/oledb/ccommand-class.md) or [CTable](../../data/oledb/ctable-class.md):
36
36
@@ -56,7 +56,7 @@ Programmatically, a consumer typically performs the following sequence of operat
56
56
hr = rs.Open(); // (Open also executes the command)
57
57
```
58
58
59
-
- Optionally, set rowset properties using `CDBPropSet::AddProperty` and pass them as a parameter to `rs.Open`. For an example of how this is done, see GetRowsetProperties in [Consumer Wizard-Generated Methods](../../data/oledb/consumer-wizard-generated-methods.md).
59
+
- Optionally, set rowset properties using `CDBPropSet::AddProperty` and pass them as a parameter to `rs.Open`. For an example of how this is done, see **GetRowsetProperties** in [Consumer Wizard-Generated Methods](../../data/oledb/consumer-wizard-generated-methods.md).
60
60
61
61
- You can now use the rowset to retrieve/manipulate the data.
62
62
@@ -72,7 +72,7 @@ Programmatically, a consumer typically performs the following sequence of operat
72
72
73
73
- Call `CoUnInitialize` to uninitialize COM. This is usually called in the main code.
The recommended way to create an OLE DB provider is to use the wizards to create an ATL COM project and a provider and then modify the files using the OLE DB templates. As you customize your provider, you can comment out unwanted properties and add optional interfaces.
17
17
18
18
The basic steps are as follows:
19
+
20
+
1. Use the **ATL Project Wizard** to create the basic project files and the **ATL OLEDB Provider Wizard** to create the provider (select **ATL OLEDB Provider** from the **Installed** > **Visual C++** > **ATL** folder in **Add New Item**).
21
+
22
+
> [!NOTE]
23
+
> The project must include MFC support before adding a **ATL OLEDB Provider**.
19
24
20
-
1. Use the ATL Project Wizard to create the basic project files and the ATL OLE DB Provider Wizard to create the provider (select **ATL OLE DB Provider** from the Visual C++ folder in **Add Class**).
21
-
22
-
1. Modify the code in the `Execute` method in CMyProviderRS.h. For an example, see [Reading Strings Into an OLE DB Provider](../../data/oledb/reading-strings-into-the-ole-db-provider.md).
25
+
1. Modify the code in the `Execute` method in [CMyProviderRowset(MyProviderRS.h)](cmyproviderrowset-myproviderrs-h.md). For an example, see [Reading Strings Into an OLE DB Provider](../../data/oledb/reading-strings-into-the-ole-db-provider.md).
23
26
24
-
1. Edit the property maps in MyProviderDS.h, MyProviderSess.h, and MyProviderRS.h. The wizard creates property maps that contain all properties that a provider might implement. Go through the property maps and remove or comment out properties that your provider does not need to support.
27
+
1. Edit the property maps in [MyProviderDS.h](cmyprovidersource-myproviderds-h.md), [MyProviderSess.h](cmyprovidersession-myprovidersess-h.md), and [MyProviderRS.h](cmyproviderrowset-myproviderrs-h.md). The wizard creates property maps that contain all properties that a provider might implement. Go through the property maps and remove or comment out properties that your provider does not need to support.
25
28
26
-
1. Update the PROVIDER_COLUMN_MAP, which can be found in MyProviderRS.h. For an example, see [Storing Strings In the OLE DB Provider](../../data/oledb/storing-strings-in-the-ole-db-provider.md).
29
+
1. Update the PROVIDER_COLUMN_MAP, which can be found in [CMyProviderRowset(MyProviderRS.h)](cmyproviderrowset-myproviderrs-h.md). For an example, see [Storing Strings In the OLE DB Provider](../../data/oledb/storing-strings-in-the-ole-db-provider.md).
27
30
28
-
1. When you are ready to test your provider, you can test it by trying to find the provider in a provider enumeration. For examples of test code that finds a provider in an enumeration, see the [CATDB](https://github.com/Microsoft/VCSamples) and [DBVIEWER](https://github.com/Microsoft/VCSamples) samples or the example in [Implementing A Simple Consumer](../../data/oledb/implementing-a-simple-consumer.md).
31
+
1. When you are ready to test your provider, you can test it by trying to find the provider in a provider enumeration. For examples of test code that finds a provider in an enumeration, see the [CATDB](https://github.com/Microsoft/VCSamples/tree/master/VC2008Samples/ATL/OLEDB/Consumer/catdb) and [DBVIEWER](https://github.com/Microsoft/VCSamples/tree/master/VC2008Samples/ATL/OLEDB/Consumer/dbviewer) samples or the example in [Implementing A Simple Consumer](../../data/oledb/implementing-a-simple-consumer.md).
29
32
30
33
1. Add any additional interfaces you want. For an example, see [Enhancing the Simple Read-Only Provider](../../data/oledb/enhancing-the-simple-read-only-provider.md).
31
34
32
-
> [!NOTE]
33
-
> By default, the wizards generate code that is OLE DB level 0 compliant. To ensure that your application remains level 0 compliant, do not remove any of the wizard-generated interfaces from the code.
35
+
> [!NOTE]
36
+
>By default, the wizards generate code that is OLE DB level 0 compliant. To ensure that your application remains level 0 compliant, do not remove any of the wizard-generated interfaces from the code.
####To create an OLE DB provider with the ATL OLE DB Provider Wizard
16
+
## To create an OLE DB provider with the ATL OLE DB Provider Wizard
17
17
18
18
1. Right-click the project.
19
19
20
20
1. On the shortcut menu, click **Add**, and then click **Add Class**.
21
21
22
-
1. In the **Add Class** dialog box, select the **ATL OLE DB Provider** icon, and then click **Open**.
22
+
1. In the **Add Class** dialog box, under **Installed** > **Visual C++** > **ATL**, select the **ATL OLEDB Provider** icon, and then click **Open**.
23
23
24
-
1. In the ATL OLE DB Provider Wizard, enter a short name for your provider in the **Short Name** box. The following topics use the short name "MyProvider", but you can use another name. The other name boxes populate according to the name you enter.
24
+
1. In the **ATL OLE DB Provider Wizard**, enter a short name for your provider in the **Short Name** box. The following topics use the short name "MyProvider", but you can use another name. The other name boxes populate according to the name you enter.
25
25
26
26
1. Edit the other name boxes, if needed. In addition to the object and file names, you can edit the following:
27
27
28
28
-**Coclass**: The name that COM uses to create the provider.
29
29
30
30
-**ProgID**: The programmatic identifier, which is a text string that can be used instead of a GUID.
31
31
32
-
-**Version**: Used with the ProgID and coclass to generate a version-dependent programmatic ID.
32
+
-**Version**: Used with the ProgID and Coclass to generate a version-dependent programmatic ID.
0 commit comments