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
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
18
21
-
*Creating and deleting a table
22
-
*Working with table entities
19
+
*Create and delete a table
20
+
*Work with table entities
23
21
24
22
> [!NOTE]
25
23
> 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
43
41
44
42
In this guide, you use storage features from a C++ application. To do so, install the Azure Storage Client Library for C++.
45
43
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:
47
45
48
46
* Linux. Follow the instructions given in [Azure Storage Client Library for C++](https://github.com/Azure/azure-storage-cpp/blob/master/README.md).
49
47
* 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
56
54
57
55
### Configure access to the Table client library
58
56
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:
60
58
61
59
```cpp
62
60
#include<was/storage_account.h>
63
61
#include<was/table.h>
64
62
```
65
63
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.
67
65
68
66
### Set up an Azure Storage connection string
69
67
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:
71
69
72
70
```cpp
73
71
// Define the Storage connection string with your values.
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).
78
76
79
77
### Set up an Azure Cosmos DB connection string
80
78
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:
82
80
83
81
```cpp
84
82
// Define the Azure Cosmos DB connection string with your values.
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>`.
89
87
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:
91
89
92
90
```cpp
93
91
// Define the connection string with Azure storage emulator.
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).
98
96
99
97
### Retrieve your connection string
100
98
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.
102
100
103
101
```cpp
104
102
// Retrieve the storage account from the connection string.
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:
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
136
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.
140
138
141
139
```cpp
142
140
// Retrieve the storage account from the connection string.
* 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.
223
221
* A batch operation can have a retrieve operation, if it's the only operation in the batch.
224
222
* All entities in a single batch operation must have the same partition key.
225
223
* A batch operation is limited to a 4-MB data payload.
226
224
225
+
## Query and modify entities
226
+
227
227
### Retrieve all entities in a partition
228
228
229
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.
@@ -261,11 +261,11 @@ for (; it != end_of_results; ++it)
261
261
}
262
262
```
263
263
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.
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.
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.
336
336
337
337
```cpp
338
338
// Retrieve the storage account from the connection string.
`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.
@@ -439,6 +439,8 @@ for (; it != end_of_results; ++it)
439
439
> Querying a few properties from an entity is a more efficient operation than retrieving all properties.
440
440
>
441
441
442
+
## Delete content
443
+
442
444
### Delete an entity
443
445
444
446
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
491
493
492
494
## Troubleshooting
493
495
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:
495
497
496
498
1. In **Solution Explorer**, right-click your project and select **Properties**.
497
499
1. In the **Property Pages** dialog box, expand **Configuration Properties**, expand **C/C++**, and select **Language**.
498
500
1. Set **Conformance mode** to **No**.
499
501
500
502
## Next steps
501
503
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
+
502
506
Follow these links to learn more about Azure Storage and the Table API in Azure Cosmos DB:
503
507
504
508
*[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.
506
509
*[List Azure Storage resources in C++](../storage/common/storage-c-plus-plus-enumeration.md)
507
510
*[Storage Client Library for C++ reference](https://azure.github.io/azure-storage-cpp)
Copy file name to clipboardExpand all lines: includes/cosmos-db-create-azure-service-account.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,8 @@ services: cosmos-db
5
5
author: MarkMcGeeAtAquent
6
6
ms.service: cosmos-db
7
7
ms.topic: "include"
8
-
ms.date: 04/06/2018
8
+
ms.date: 10/07/2019
9
9
ms.author: mimig
10
10
ms.custom: "include file"
11
11
---
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.
Copy file name to clipboardExpand all lines: includes/cosmos-db-create-storage-account.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ ms.date: 04/06/2018
9
9
ms.author: mimig
10
10
ms.custom: "include file"
11
11
---
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).
13
13
14
14
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).
0 commit comments