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
Copy file name to clipboardExpand all lines: docs/data/oledb/creating-an-updatable-provider.md
+12-15Lines changed: 12 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ This topic assumes that you are starting with a workable provider. There are two
20
20
Next, you must make sure your provider contains all the functionality to support anything the consumer might request of it. If the consumer wants to update the data store, the provider has to contain code that persists data to the data store. For example, you might use the C Run-Time Library or MFC to perform such operations on your data source. The section "[Writing to the Data Source](#vchowwritingtothedatasource)" describes how to write to the data source, deal with NULL and default values, and set column flags.
21
21
22
22
> [!NOTE]
23
-
> [UpdatePV](https://github.com/Microsoft/VCSamples/tree/master/VC2010Samples/ATL/OLEDB/Provider/UPDATEPV) is an example of an updatable provider. UpdatePV is the same as MyProv but with updatable support.
23
+
> [UpdatePV](https://github.com/Microsoft/VCSamples/tree/master/VC2010Samples/ATL/OLEDB/Provider/UPDATEPV) is an example of an updatable provider. UpdatePV is the same as MyProv but with updatable support.
24
24
25
25
## <aname="vchowmakingprovidersupdatable"></a> Making Providers Updatable
26
26
@@ -34,7 +34,7 @@ You must first decide whether to inherit from `IRowsetChangeImpl` or `IRowsetUpd
34
34
35
35
Note that `IRowsetUpdateImpl` derives from `IRowsetChangeImpl`. Thus, `IRowsetUpdateImpl` gives you change capability plus batch capability.
36
36
37
-
####To support updatability in your provider
37
+
### To support updatability in your provider
38
38
39
39
1. In your rowset class, inherit from `IRowsetChangeImpl` or `IRowsetUpdateImpl`. These classes provide appropriate interfaces for changing the data store:
40
40
@@ -57,7 +57,7 @@ Note that `IRowsetUpdateImpl` derives from `IRowsetChangeImpl`. Thus, `IRowsetUp
57
57
```
58
58
59
59
> [!NOTE]
60
-
> You should remove the `IRowsetChangeImpl` line from your inheritance chain. This one exception to the directive previously mentioned must include the code for `IRowsetChangeImpl`.
60
+
> You should remove the `IRowsetChangeImpl` line from your inheritance chain. This one exception to the directive previously mentioned must include the code for `IRowsetChangeImpl`.
61
61
62
62
1. Add the following to your COM map (`BEGIN_COM_MAP ... END_COM_MAP`):
63
63
@@ -96,7 +96,7 @@ Note that `IRowsetUpdateImpl` derives from `IRowsetChangeImpl`. Thus, `IRowsetUp
96
96
You can find the values used in these macro calls by looking in Atldb.h for the property IDs and values (if Atldb.h differs from the online documentation, Atldb.h supersedes the documentation).
97
97
98
98
> [!NOTE]
99
-
> Many of the `VARIANT_FALSE` and `VARIANT_TRUE` settings are required by the OLE DB templates; the OLE DB specification says they can be read/write, but the OLE DB templates can only support one value.
99
+
> Many of the `VARIANT_FALSE` and `VARIANT_TRUE` settings are required by the OLE DB templates; the OLE DB specification says they can be read/write, but the OLE DB templates can only support one value.
100
100
101
101
**If you implement IRowsetChangeImpl**
102
102
@@ -129,16 +129,14 @@ Note that `IRowsetUpdateImpl` derives from `IRowsetChangeImpl`. Thus, `IRowsetUp
129
129
- `DBPROP_MAXPENDINGROWS`.
130
130
131
131
> [!NOTE]
132
-
> If you support notifications, you might also have some other properties as well; see the section on `IRowsetNotifyCP` for this list.
132
+
> If you support notifications, you might also have some other properties as well; see the section on `IRowsetNotifyCP` for this list.
133
133
134
134
## <aname="vchowwritingtothedatasource"></a> Writing to the Data Source
135
135
136
136
To read from the data source, call the `Execute` function. To write to the data source, call the `FlushData` function. (In a general sense, flush means to save modifications you make to a table or index to disk.)
137
137
138
138
```cpp
139
-
140
139
FlushData(HROW, HACCESSOR);
141
-
142
140
```
143
141
144
142
The row handle (HROW) and accessor handle (HACCESSOR) arguments allow you to specify the region to write. Typically, you write a single data field at a time.
@@ -179,7 +177,7 @@ Handling NULL values.
179
177
180
178
### Handling default values.
181
179
182
-
To implement your own FlushData method, you need to:
180
+
To implement your own `FlushData` method, you need to:
183
181
184
182
- Go to your rowset class.
185
183
@@ -194,7 +192,7 @@ To implement your own FlushData method, you need to:
194
192
195
193
- Provide an implementation of `FlushData`.
196
194
197
-
A good implementation of FlushData stores only the rows and columns that are actually updated. You can use the HROW and HACCESSOR parameters to determine the current row and column being stored for optimization.
195
+
A good implementation of `FlushData` stores only the rows and columns that are actually updated. You can use the HROW and HACCESSOR parameters to determine the current row and column being stored for optimization.
198
196
199
197
Typically, the biggest challenge is working with your own native data store. If possible, try to:
200
198
@@ -206,7 +204,7 @@ Typically, the biggest challenge is working with your own native data store. If
206
204
207
205
The best thing to do is to have actual specified values in your data store for NULL and default values. It is best if you can extrapolate this data. If not, you are advised not to allow NULL and default values.
208
206
209
-
The following example shows how `FlushData` is implemented in the RUpdateRowset class in the UpdatePV sample (see Rowset.h in the sample code):
207
+
The following example shows how `FlushData` is implemented in the `RUpdateRowset` class in the `UpdatePV` sample (see Rowset.h in the sample code):
As with NULL data, you have the responsibility to deal with changing default values.
370
367
371
-
The default of FlushData and Execute is to return S_OK. Therefore, if you do not override this function, the changes appear to succeed (S_OK will be returned), but they will not be transmitted to the data store.
368
+
The default of `FlushData` and `Execute` is to return S_OK. Therefore, if you do not override this function, the changes appear to succeed (S_OK will be returned), but they will not be transmitted to the data store.
372
369
373
-
In the UpdatePV sample (in Rowset.h), the `SetDBStatus` method handles default values as follows:
370
+
In the `UpdatePV` sample (in Rowset.h), the `SetDBStatus` method handles default values as follows:
If you support default values on your columns, you need to set it using metadata in the \<provider class\>SchemaRowset class. Set `m_bColumnHasDefault` = VARIANT_TRUE.
409
+
If you support default values on your columns, you need to set it using metadata in the \<provider class\>SchemaRowset class. Set `m_bColumnHasDefault = VARIANT_TRUE`.
413
410
414
411
You also have the responsibility to set the column flags, which are specified using the DBCOLUMNFLAGS enumerated type. The column flags describe column characteristics.
415
412
416
-
For example, in the `CUpdateSessionColSchemaRowset` class in UpdatePV (in Session.h), the first column is set up this way:
413
+
For example, in the `CUpdateSessionColSchemaRowset` class in `UpdatePV` (in Session.h), the first column is set up this way:
The PROVIDER_COLUMN_ENTRY macros normally handle the `IColumnsInfo::GetColumnsInfo` call. However, because a consumer might choose to use bookmarks, the provider must be able to change the columns returned depending on whether the consumer asks for a bookmark.
17
17
18
-
To handle the `IColumnsInfo::GetColumnsInfo` call, delete the PROVIDER_COLUMN_MAP, which defines a function `GetColumnInfo`, from the `CAgentMan` user record in MyProviderRS.h and replace it with the definition for your own `GetColumnInfo` function:
18
+
To handle the `IColumnsInfo::GetColumnsInfo` call, delete the PROVIDER_COLUMN_MAP, which defines a function `GetColumnInfo`, from the `CAgentMan` user record in *Custom*RS.h and replace it with the definition for your own `GetColumnInfo` function:
Next, implement the `GetColumnInfo` function in MyProviderRS.cpp, as shown in the following code.
42
42
43
-
`GetColumnInfo` checks first to see if the OLE DB property `DBPROP_BOOKMARKS` is set. To get the property, `GetColumnInfo` uses a pointer (`pRowset`) to the rowset object. The `pThis` pointer represents the class that created the rowset, which is the class where the property map is stored. `GetColumnInfo` typecasts the `pThis` pointer to an `RMyProviderRowset` pointer.
43
+
`GetColumnInfo` checks first to see if the OLE DB property `DBPROP_BOOKMARKS` is set. To get the property, `GetColumnInfo` uses a pointer (`pRowset`) to the rowset object. The `pThis` pointer represents the class that created the rowset, which is the class where the property map is stored. `GetColumnInfo` typecasts the `pThis` pointer to an `RCustomRowset` pointer.
44
44
45
45
To check for the `DBPROP_BOOKMARKS` property, `GetColumnInfo` uses the `IRowsetInfo` interface, which you can obtain by calling `QueryInterface` on the `pRowset` interface. As an alternative, you can use an ATL [CComQIPtr](../../atl/reference/ccomqiptr-class.md) method instead.
To add the `IRowsetLocate` interface to the simple read-only provider example, modify the inheritance of `RMyProviderRowset`. Initially, `RMyProviderRowset` inherits from `CRowsetImpl`. You need to modify it to inherit from `CRowsetBaseImpl`.
16
+
To add the `IRowsetLocate` interface to the simple read-only provider example, modify the inheritance of `RCustomRowset`. Initially, `RCustomRowset` inherits from `CRowsetImpl`. You need to modify it to inherit from `CRowsetBaseImpl`.
17
17
18
-
To do this, create a new class, `CMyRowsetImpl`, in MyProviderRS.h:
18
+
To do this, create a new class, `CMyRowsetImpl`, in *Custom*RS.h:
The `RMyProviderRowset::Execute` function opens a file and reads strings. The consumer passes the file name to the provider by calling [ICommandText::SetCommandText](/previous-versions/windows/desktop/ms709757). The provider receives the file name and stores it in the member variable `m_szCommandText`. `Execute` reads the file name from `m_szCommandText`. If the file name is invalid or the file is unavailable, `Execute` returns an error. Otherwise, it opens the file and calls `fgets` to retrieve the strings. For each set of strings it reads, `Execute` creates an instance of the user record (`CAgentMan`) and places it into an array.
16
+
The `RCustomRowset::Execute` function opens a file and reads strings. The consumer passes the file name to the provider by calling [ICommandText::SetCommandText](/previous-versions/windows/desktop/ms709757). The provider receives the file name and stores it in the member variable `m_szCommandText`. `Execute` reads the file name from `m_szCommandText`. If the file name is invalid or the file is unavailable, `Execute` returns an error. Otherwise, it opens the file and calls `fgets` to retrieve the strings. For each set of strings it reads, `Execute` creates an instance of the user record (`CAgentMan`) and places it into an array.
17
17
18
18
If the file cannot be opened, `Execute` must return DB_E_NOTABLE. If it returns E_FAIL instead, the provider will not work with many consumers and will not pass the OLE DB [conformance tests](../../data/oledb/testing-your-provider.md).
Copy file name to clipboardExpand all lines: docs/data/oledb/supporting-notifications.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ Note that you must also implement and register `IRowsetNotify` on the consumer (
23
23
24
24
In addition, the class must also contain a map that defines the connection point entry, like this:
25
25
26
-
```
26
+
```cpp
27
27
BEGIN_CONNECTION_POINT_MAP
28
28
CONNECTIONPOINT_ENTRY (IID_IRowsetNotify)
29
29
END_CONNECTION_POINT_MAP
@@ -36,7 +36,7 @@ To add `IRowsetNotify`, you need to add `IConnectionPointContainerImpl<rowset-na
36
36
For example, here is the inheritance chain for `RUpdateRowset` in [UpdatePV](https://github.com/Microsoft/VCSamples/tree/master/VC2010Samples/ATL/OLEDB/Provider/UPDATEPV):
37
37
38
38
> [!NOTE]
39
-
> The sample code might differ from what is listed here; you should regard the sample code as the more up-to-date version.
39
+
> The sample code might differ from what is listed here; you should regard the sample code as the more up-to-date version.
0 commit comments