Skip to content

Commit 4c8ba15

Browse files
Incorporate peer review.
1 parent b2d73eb commit 4c8ba15

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed

articles/cosmos-db/table-storage-how-to-use-c-plus.md

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ ms.author: wmeng
1414
[!INCLUDE [storage-selector-table-include](../../includes/storage-selector-table-include.md)]
1515
[!INCLUDE [storage-table-applies-to-storagetable-and-cosmos](../../includes/storage-table-applies-to-storagetable-and-cosmos.md)]
1616

17-
## Overview
18-
1917
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:
2018

21-
* Creating and deleting a table
22-
* Working with table entities
19+
* Create and delete a table
20+
* Work with table entities
2321

2422
> [!NOTE]
2523
> This guide targets the Azure Storage Client Library for C++ version 1.0.0 and above. The recommended version is Storage Client Library 2.2.0, which is available by using [NuGet](https://www.nuget.org/packages/wastorage) or [GitHub](https://github.com/Azure/azure-storage-cpp/).
@@ -43,7 +41,7 @@ This guide shows you common scenarios by using the Azure Table storage service o
4341

4442
In this guide, you use storage features from a C++ application. To do so, install the Azure Storage Client Library for C++.
4543

46-
To install the Azure Storage Client Library for C++, you can use the following methods:
44+
To install the Azure Storage Client Library for C++, use the following methods:
4745

4846
* Linux. Follow the instructions given in [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md).
4947
* Windows. In Visual Studio, select **Tools > NuGet Package Manager > Package Manager Console**. Run the following command in the **Package Management Console**:
@@ -56,63 +54,63 @@ For more information about **Package Management Console**, see [Install and mana
5654

5755
### Configure access to the Table client library
5856

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:
57+
To use the Azure storage APIs to access tables, add the following `include` statements to the top of the C++ file:
6058

6159
```cpp
6260
#include <was/storage_account.h>
6361
#include <was/table.h>
6462
```
6563

66-
An Azure Storage client or Cosmos DB client uses a connection string to store endpoints and credentials to access data management services. When running a client application, you must provide the storage connection string or Azure Cosmos DB connection string in the appropriate format.
64+
An Azure Storage client or Cosmos DB client uses a connection string to store endpoints and credentials to access data management services. When you run a client application, you must provide the storage connection string or Azure Cosmos DB connection string in the appropriate format.
6765

6866
### Set up an Azure Storage connection string
6967

70-
This example shows how you can declare a static field to hold the Azure Storage connection string:
68+
This example shows how to declare a static field to hold the Azure Storage connection string:
7169

7270
```cpp
7371
// Define the Storage connection string with your values.
74-
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=your_storage_account;AccountKey=your_storage_account_key"));
72+
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=<your_storage_account>;AccountKey=<your_storage_account_key>"));
7573
```
7674
77-
Use the name of your Storage account for `your_storage_account`. Use the access key for the Storage account listed in the [Azure portal](https://portal.azure.com). For information on Storage accounts and access keys, see [Create a storage account](../storage/common/storage-create-storage-account.md).
75+
Use the name of your Storage account for `<your_storage_account>`. For <your_storage_account_key>, use the access key for the Storage account listed in the [Azure portal](https://portal.azure.com). For information on Storage accounts and access keys, see [Create a storage account](../storage/common/storage-create-storage-account.md).
7876
7977
### Set up an Azure Cosmos DB connection string
8078
81-
This example shows how you can declare a static field to hold the Azure Cosmos DB connection string:
79+
This example shows how to declare a static field to hold the Azure Cosmos DB connection string:
8280
8381
```cpp
8482
// Define the Azure Cosmos DB connection string with your values.
85-
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=your_cosmos_db_account;AccountKey=your_cosmos_db_account_key;TableEndpoint=your_cosmos_db_endpoint"));
83+
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=<your_cosmos_db_account>;AccountKey=<your_cosmos_db_account_key>;TableEndpoint=<your_cosmos_db_endpoint>"));
8684
```
8785

88-
Use the name of your Azure Cosmos DB account, your primary key, and endpoint listed in the [Azure portal](https://portal.azure.com).
86+
Use the name of your Azure Cosmos DB account for `<your_cosmos_db_account>`. Enter your primary key for `<your_cosmos_db_account_key>`. Enter the endpoint listed in the [Azure portal](https://portal.azure.com) for `<your_cosmos_db_endpoint>`.
8987

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:
88+
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 to declare a static field to hold the connection string to your local storage emulator:
9189

9290
```cpp
9391
// Define the connection string with Azure storage emulator.
9492
const utility::string_t storage_connection_string(U("UseDevelopmentStorage=true;"));
9593
```
9694
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).
95+
To start the Azure storage emulator, from your Windows desktop, select the **Start** button or the Windows key. Enter and run *Microsoft Azure Storage Emulator*. For more information, see [Use the Azure storage emulator for development and testing](../storage/common/storage-use-emulator.md).
9896
9997
### Retrieve your connection string
10098
101-
You can use the `cloud_storage_account` class to represent your storage account information. To retrieve your storage account information from the storage connection string, you can use the `parse` method.
99+
You can use the `cloud_storage_account` class to represent your storage account information. To retrieve your storage account information from the storage connection string, use the `parse` method.
102100
103101
```cpp
104102
// Retrieve the storage account from the connection string.
105103
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);
106104
```
107105

108-
Next, get a reference to a `cloud_table_client` class. This class lets you get reference objects for tables and entities stored within the Table storage service. The following code creates a `cloud_table_client` object by using the storage account object we retrieved above:
106+
Next, get a reference to a `cloud_table_client` class. This class lets you get reference objects for tables and entities stored within the Table storage service. The following code creates a `cloud_table_client` object by using the storage account object you retrieved previously:
109107

110108
```cpp
111109
// Create the table client.
112110
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();
113111
```
114112

115-
## Use the Table storage
113+
## Create and add entities to a table
116114

117115
### Create a table
118116

@@ -136,7 +134,7 @@ table.create_if_not_exists();
136134

137135
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).
138136

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.
137+
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. The new `table_operation` sends a request to the Table service to insert the new customer entity into the `people` table.
140138

141139
```cpp
142140
// Retrieve the storage account from the connection string.
@@ -219,11 +217,13 @@ std::vector<azure::storage::table_result> results = table.execute_batch(batch_op
219217

220218
Some things to note on batch operations:
221219

222-
* You can do up to 100 insert, delete, merge, replace, insert-or-merge, and insert-or-replace operations in any combination in a single batch.
220+
* You can do up to 100 `insert`, `delete`, `merge`, `replace`, `insert-or-merge`, and `insert-or-replace` operations in any combination in a single batch.
223221
* A batch operation can have a retrieve operation, if it's the only operation in the batch.
224222
* All entities in a single batch operation must have the same partition key.
225223
* A batch operation is limited to a 4-MB data payload.
226224

225+
## Query and modify entities
226+
227227
### Retrieve all entities in a partition
228228

229229
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.
@@ -261,11 +261,11 @@ for (; it != end_of_results; ++it)
261261
}
262262
```
263263

264-
The query in this example brings all the entities that match the filter criteria. If you have large tables and need to download the table entities often, we recommend that you store your data in Azure storage blobs instead.
264+
The query in this example returns all the entities that match the filter criteria. If you have large tables and need to download the table entities often, we recommend that you store your data in Azure storage blobs instead.
265265

266266
### Retrieve a range of entities in a partition
267267

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.
269269

270270
> [!NOTE]
271271
> These methods are not currently supported for C++ in Azure Cosmos DB.
@@ -332,7 +332,7 @@ std::wcout << U("PartitionKey: ") << entity.partition_key() << U(", RowKey: ") <
332332

333333
### Replace an entity
334334

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.
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.
336336

337337
```cpp
338338
// Retrieve the storage account from the connection string.
@@ -362,7 +362,7 @@ azure::storage::table_operation replace_operation = azure::storage::table_operat
362362
azure::storage::table_result replace_result = table.execute(replace_operation);
363363
```
364364
365-
### Insert-or-replace an entity
365+
### Insert or replace an entity
366366
367367
`table_operation::replace_entity` operations fail if the entity has been changed since it was retrieved from the server. Furthermore, you must retrieve the entity from the server first in order for `table_operation::replace_entity` to be successful. Sometimes, you don't know if the entity exists on the server. The current values stored in it are irrelevant, because your update should overwrite them all. To accomplish this result, use a `table_operation::insert_or_replace_entity` operation. This operation inserts the entity if it doesn't exist. The operation replaces the entity if it exists. In the following code example, the customer entity for `Jeff Smith` is still retrieved, but it's then saved back to the server by using `table_operation::insert_or_replace_entity`. Any updates made to the entity between the retrieval and update operation will be overwritten.
368368
@@ -376,7 +376,7 @@ azure::storage::cloud_table_client table_client = storage_account.create_cloud_t
376376
// Create a cloud table object for the table.
377377
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));
378378
379-
// Insert-or-replace an entity.
379+
// Insert or replace an entity.
380380
azure::storage::table_entity entity_to_insert_or_replace(U("Smith"), U("Jeff"));
381381
azure::storage::table_entity::properties_type& properties_to_insert_or_replace = entity_to_insert_or_replace.properties();
382382
@@ -388,7 +388,7 @@ properties_to_insert_or_replace[U("Phone")] = azure::storage::entity_property(U(
388388
// Specify an email address.
389389
properties_to_insert_or_replace[U("Email")] = azure::storage::entity_property(U("[email protected]"));
390390
391-
// Create an operation to insert-or-replace the entity.
391+
// Create an operation to insert or replace the entity.
392392
azure::storage::table_operation insert_or_replace_operation = azure::storage::table_operation::insert_or_replace_entity(entity_to_insert_or_replace);
393393
394394
// Submit the operation to the Table service.
@@ -439,6 +439,8 @@ for (; it != end_of_results; ++it)
439439
> Querying a few properties from an entity is a more efficient operation than retrieving all properties.
440440
>
441441
442+
## Delete content
443+
442444
### Delete an entity
443445

444446
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`.
@@ -491,18 +493,19 @@ else
491493

492494
## Troubleshooting
493495

494-
For Visual Studio 2017 Community Edition, if your project gets build errors because of the include files *storage_account.h* and *table.h*, remove the **/permissive-** compiler switch:
496+
For Visual Studio Community Edition, if your project gets build errors because of the include files *storage_account.h* and *table.h*, remove the **/permissive-** compiler switch:
495497

496498
1. In **Solution Explorer**, right-click your project and select **Properties**.
497499
1. In the **Property Pages** dialog box, expand **Configuration Properties**, expand **C/C++**, and select **Language**.
498500
1. Set **Conformance mode** to **No**.
499501

500502
## Next steps
501503

504+
[Microsoft Azure Storage Explorer](../vs-azure-tools-storage-manage-with-storage-explorer.md) is a free, standalone app from Microsoft that enables you to work visually with Azure Storage data on Windows, macOS, and Linux.
505+
502506
Follow these links to learn more about Azure Storage and the Table API in Azure Cosmos DB:
503507

504508
* [Introduction to the Table API](table-introduction.md)
505-
* [Microsoft Azure Storage Explorer](../vs-azure-tools-storage-manage-with-storage-explorer.md) is a free, standalone app from Microsoft that enables you to work visually with Azure Storage data on Windows, macOS, and Linux.
506509
* [List Azure Storage resources in C++](../storage/common/storage-c-plus-plus-enumeration.md)
507510
* [Storage Client Library for C++ reference](https://azure.github.io/azure-storage-cpp)
508511
* [Azure Storage documentation](https://azure.microsoft.com/documentation/services/storage/)

includes/cosmos-db-create-azure-service-account.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ services: cosmos-db
55
author: MarkMcGeeAtAquent
66
ms.service: cosmos-db
77
ms.topic: "include"
8-
ms.date: 04/06/2018
8+
ms.date: 10/07/2019
99
ms.author: mimig
1010
ms.custom: "include file"
1111
---
12-
You can work with tables using Azure Table storage or Azure Cosmos DB. You can learn more about the differences between the services by reading [Table offerings](../articles/cosmos-db/table-introduction.md#table-offerings). You'll need to create an account for the service you're going to use.
13-
14-
15-
16-
12+
You can work with tables using Azure Table storage or Azure Cosmos DB. To learn more about the differences between the services, see [Table offerings](../articles/cosmos-db/table-introduction.md#table-offerings). You'll need to create an account for the service you're going to use.

includes/cosmos-db-create-storage-account.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.date: 04/06/2018
99
ms.author: mimig
1010
ms.custom: "include file"
1111
---
12-
The easiest way to create your first Azure storage account is by using the [Azure portal](https://portal.azure.com). To learn more, see [Create a storage account](../articles/storage/common/storage-quickstart-create-account.md).
12+
The easiest way to create an Azure storage account is by using the [Azure portal](https://portal.azure.com). To learn more, see [Create a storage account](../articles/storage/common/storage-quickstart-create-account.md).
1313

1414
You can also create an Azure storage account by using [Azure PowerShell](../articles/storage/common/storage-powershell-guide-full.md) or [Azure CLI](../articles/storage/common/storage-azure-cli.md).
1515

0 commit comments

Comments
 (0)