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: articles/cosmos-db/table-storage-how-to-use-c-plus.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.service: cosmos-db
5
5
ms.subservice: cosmosdb-table
6
6
ms.devlang: cpp
7
7
ms.topic: sample
8
-
ms.date: 04/05/2018
8
+
ms.date: 10/07/2019
9
9
author: wmengmsft
10
10
ms.author: wmeng
11
11
---
@@ -16,7 +16,7 @@ ms.author: wmeng
16
16
17
17
## Overview
18
18
19
-
This guide will show you common scenarios by using the Azure Table storage service or Azure Cosmos DB Table API. The samples are written in C++ and use the [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md). This article covers the following scenarios:
19
+
This guide shows you common scenarios by using the Azure Table storage service or Azure Cosmos DB Table API. The samples are written in C++ and use the [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md). This article covers the following scenarios:
20
20
21
21
* Creating and deleting a table
22
22
* Working with table entities
@@ -41,11 +41,11 @@ This guide will show you common scenarios by using the Azure Table storage servi
41
41
42
42
## Create a C++ application
43
43
44
-
In this guide, you use storage features from C++ application. To do so, install the Azure Storage Client Library for C++.
44
+
In this guide, you use storage features from a C++ application. To do so, install the Azure Storage Client Library for C++.
45
45
46
46
To install the Azure Storage Client Library for C++, you can use the following methods:
47
47
48
-
* Linux. Follow the instructions given in [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md) page.
48
+
* Linux. Follow the instructions given in [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md).
49
49
* Windows. In Visual Studio, select **Tools > NuGet Package Manager > Package Manager Console**. Run the following command in the **Package Management Console**:
50
50
51
51
```powershell
@@ -56,7 +56,7 @@ For more information about **Package Management Console**, see [Install and mana
56
56
57
57
### Configure access to the Table client library
58
58
59
-
Add the following include statements to the top of the C++ file where you want to use the Azure storage APIs to access tables:
59
+
Add the following `include` statements to the top of the C++ file where you want to use the Azure storage APIs to access tables:
Use the name of your Azure Cosmos DB account, your primary key, and endpoint listed in the [Azure portal](https://portal.azure.com).
89
89
90
-
To test your application in your local Windows-based computer, you can use the Azure [storage emulator](../storage/common/storage-use-emulator.md) that is installed with the [Azure SDK](https://azure.microsoft.com/downloads/). The storage emulator is a utility that simulates the Azure Blob, Queue, and Table services available on your local development machine. The following example shows how you can declare a static field to hold the connection string to your local storage emulator:
90
+
To test your application in your local Windows-based computer, you can use the Azure storage emulator that is installed with the [Azure SDK](https://azure.microsoft.com/downloads/). The storage emulator is a utility that simulates the Azure Blob, Queue, and Table services available on your local development machine. The following example shows how you can declare a static field to hold the connection string to your local storage emulator:
91
91
92
92
```cpp
93
93
// Define the connection string with Azure storage emulator.
To start the Azure storage emulator, select the **Start** button or press the Windows key. Enter and run *Azure Storage Emulator*.
97
+
To start the Azure storage emulator, select the **Start** button or the Windows key. Enter and run *Azure Storage Emulator*. For more information, see [Use the Azure storage emulator for development and testing](../storage/common/storage-use-emulator.md).
98
98
99
99
### Retrieve your connection string
100
100
@@ -136,7 +136,7 @@ table.create_if_not_exists();
136
136
137
137
To add an entity to a table, create a new `table_entity` object and pass it to `table_operation::insert_entity`. The following code uses the customer's first name as the row key and last name as the partition key. Together, an entity's partition and row key uniquely identify the entity in the table. Entities with the same partition key can be queried faster than entities with different partition keys. Using diverse partition keys allows for greater parallel operation scalability. For more information, see [Microsoft Azure storage performance and scalability checklist](../storage/common/storage-performance-checklist.md).
138
138
139
-
The following code creates a new instance of `table_entity` with some customer data to store. The code next calls `table_operation::insert_entity` to create a `table_operation` object to insert an entity into a table, and associates the new table entity with it. Finally, the code calls the execute method on the `cloud_table` object. And the new `table_operation` sends a request to the Table service to insert the new customer entity into the "people" table.
139
+
The following code creates a new instance of `table_entity` with some customer data to store. The code next calls `table_operation::insert_entity` to create a `table_operation` object to insert an entity into a table, and associates the new table entity with it. Finally, the code calls the execute method on the `cloud_table` object. And the new `table_operation` sends a request to the Table service to insert the new customer entity into the `people` table.
140
140
141
141
```cpp
142
142
// Retrieve the storage account from the connection string.
@@ -226,7 +226,7 @@ Some things to note on batch operations:
226
226
227
227
### Retrieve all entities in a partition
228
228
229
-
To query a table for all entities in a partition, use a `table_query` object. The following code example specifies a filter for entities where 'Smith' is the partition key. This example prints the fields of each entity in the query results to the console.
229
+
To query a table for all entities in a partition, use a `table_query` object. The following code example specifies a filter for entities where `Smith` is the partition key. This example prints the fields of each entity in the query results to the console.
230
230
231
231
> [!NOTE]
232
232
> These methods are not currently supported for C++ in Azure Cosmos DB.
@@ -265,7 +265,7 @@ The query in this example brings all the entities that match the filter criteria
265
265
266
266
### Retrieve a range of entities in a partition
267
267
268
-
If you don't want to query all the entities in a partition, you can specify a range. Combine the partition key filter with a row key filter. The following code example uses two filters to get all entities in partition 'Smith' where the row key (first name) starts with a letter earlier than 'E' in the alphabet and then prints the query results.
268
+
If you don't want to query all the entities in a partition, you can specify a range. Combine the partition key filter with a row key filter. The following code example uses two filters to get all entities in partition `Smith` where the row key (first name) starts with a letter earlier than `E` in the alphabet and then prints the query results.
269
269
270
270
> [!NOTE]
271
271
> These methods are not currently supported for C++ in Azure Cosmos DB.
@@ -306,7 +306,7 @@ for (; it != end_of_results; ++it)
306
306
307
307
### Retrieve a single entity
308
308
309
-
You can write a query to retrieve a single, specific entity. The following code uses `table_operation::retrieve_entity` to specify the customer 'Jeff Smith'. This method returns just one entity, rather than a collection, and the returned value is in `table_result`. Specifying both partition and row keys in a query is the fastest way to retrieve a single entity from the Table service.
309
+
You can write a query to retrieve a single, specific entity. The following code uses `table_operation::retrieve_entity` to specify the customer `Jeff Smith`. This method returns just one entity, rather than a collection, and the returned value is in `table_result`. Specifying both partition and row keys in a query is the fastest way to retrieve a single entity from the Table service.
To replace an entity, retrieve it from the Table service, modify the entity object, and then save the changes back to the Table service. The following code changes an existing customer's phone number and email address. Instead of calling `table_operation::insert_entity`, this code uses `table_operation::replace_entity`. This approach causes the entity to be fully replaced on the server, unless the entity on the server has changed since it was retrieved. If it has been changed, the operation fails. This failure prevents your application from overwriting a change made between the retrieval and update by another component. The proper handling of this failure is to retrieve the entity again, make your changes, if still valid, and then do another `table_operation::replace_entity` operation. The next section will show you how to override this behavior.
335
+
To replace an entity, retrieve it from the Table service, modify the entity object, and then save the changes back to the Table service. The following code changes an existing customer's phone number and email address. Instead of calling `table_operation::insert_entity`, this code uses `table_operation::replace_entity`. This approach causes the entity to be fully replaced on the server, unless the entity on the server has changed since it was retrieved. If it has been changed, the operation fails. This failure prevents your application from overwriting a change made between the retrieval and update by another component. The proper handling of this failure is to retrieve the entity again, make your changes, if still valid, and then do another `table_operation::replace_entity` operation. The next section shows you how to override this behavior.
336
336
337
337
```cpp
338
338
// Retrieve the storage account from the connection string.
@@ -441,7 +441,7 @@ for (; it != end_of_results; ++it)
441
441
442
442
### Delete an entity
443
443
444
-
You can delete an entity after you retrieve it. After you retrieve an entity, call `table_operation::delete_entity` with the entity to delete. Then call the `cloud_table.execute` method. The following code retrieves and deletes an entity with a partition key of "Smith" and a row key of "Jeff".
444
+
You can delete an entity after you retrieve it. After you retrieve an entity, call `table_operation::delete_entity` with the entity to delete. Then call the `cloud_table.execute` method. The following code retrieves and deletes an entity with a partition key of `Smith` and a row key of `Jeff`.
445
445
446
446
```cpp
447
447
// Retrieve the storage account from the connection string.
Finally, the following code example deletes a table from a storage account. A table that has been deleted will be unavailable to be re-created for some time following the deletion.
469
+
Finally, the following code example deletes a table from a storage account. A table that has been deleted is unavailable to be re-created for some time following the deletion.
470
470
471
471
```cpp
472
472
// Retrieve the storage account from the connection string.
0 commit comments