Azure Table: Save and Resume an Entity Query
See more Azure Table Service Examples
Fetches one page per invocation and saves private JSON plus a checkpoint bound to the account, collection path, filter, projection, page size and API version. Refuses to overwrite an unprocessed page. Process/archive qa_output/table-page.json before the next run; keep table-checkpoint.json until completion.
This demonstrates at-least-once processing, not an atomic transaction between output and checkpoint. A crash or failed checkpoint write can replay a page; deduplicate by entity identity/version. A malformed checkpoint stops instead of restarting. Use a single caller, protect files, and use transactional durable state for stronger guarantees. Table contents can change during enumeration.
Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.
HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.
Chilkat Objective-C Downloads
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoRest.h>
#import <CkoAuthAzureStorage.h>
#import <CkoSocket.h>
#import <CkoFileAccess.h>
BOOL success = NO;
// StringBuilder compares text by value in every generated language.
CkoStringBuilder *textCompare = [[CkoStringBuilder alloc] init];
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = NO;
CkoJsonObject *config = [[CkoJsonObject alloc] init];
config.Strict = YES;
success = [config LoadFile: @"qa_data/azure/storage.json"];
if (success != YES) {
NSLog(@"%@",@"Could not load private Azure configuration.");
return;
}
[textCompare Clear];
[textCompare SetString: [config StringOf: @"account"]];
BOOL sameText1 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"account"] intValue] != 1) || (sameText1 == YES)) {
NSLog(@"%@",@"Supply the storage account name.");
return;
}
// access_key is the base64 account key, not a connection string or SAS.
[textCompare Clear];
[textCompare SetString: [config StringOf: @"access_key"]];
BOOL sameText2 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"access_key"] intValue] != 1) || (sameText2 == YES)) {
NSLog(@"%@",@"Supply the base64 account access key.");
return;
}
CkoStringBuilder *accountText = [[CkoStringBuilder alloc] init];
success = [accountText Append: [config StringOf: @"account"]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
if (([accountText.Length intValue] < 3) || ([accountText.Length intValue] > 24)) {
NSLog(@"%@",@"Storage account names need 3-24 lowercase letters or digits.");
return;
}
CkoStringBuilder *allowedAccountChars = [[CkoStringBuilder alloc] init];
success = [allowedAccountChars Append: @"abcdefghijklmnopqrstuvwxyz0123456789"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
int charIndex = 0;
while ((charIndex < [accountText.Length intValue])) {
if ([allowedAccountChars Contains: [accountText GetRange: [NSNumber numberWithInt: charIndex] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Storage account names need lowercase letters or digits.");
return;
}
charIndex = charIndex + 1;
}
CkoStringBuilder *endpoint = [[CkoStringBuilder alloc] init];
success = [endpoint Append: [config StringOf: @"account"]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [endpoint Append: @".table.core.windows.net"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
// Table names contain only letters and digits and are case-insensitive.
// Entity PartitionKey and RowKey values are case-sensitive.
NSString *resourcePath = @"/ExampleCustomers()";
CkoRest *rest = [[CkoRest alloc] init];
rest.ConnectTimeoutMs = [NSNumber numberWithInt:20000];
rest.IdleTimeoutMs = [NSNumber numberWithInt:60000];
CkoAuthAzureStorage *azAuth = [[CkoAuthAzureStorage alloc] init];
azAuth.Account = [config StringOf: @"account"];
azAuth.AccessKey = [config StringOf: @"access_key"];
azAuth.Service = @"Table";
azAuth.Scheme = @"SharedKey";
azAuth.XMsVersion = @"2026-04-06";
success = [rest SetAuthAzureStorage: azAuth];
if (success != YES) {
NSLog(@"%@",@"Could not configure Shared Key signing.");
return;
}
CkoSocket *connection = [[CkoSocket alloc] init];
connection.RequireSslCertVerify = YES;
connection.MaxReadIdleMs = [NSNumber numberWithInt:60000];
connection.MaxSendIdleMs = [NSNumber numberWithInt:60000];
success = [connection Connect: [endpoint GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 20000]];
if (success != YES) {
NSLog(@"%@",@"TLS connection failed; inspect diagnostics privately.");
return;
}
// Do not replay a write automatically after losing its response.
success = [rest UseConnection: connection autoReconnect: NO];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
NSString *responseText = 0;
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
success = [rest AddHeader: @"DataServiceVersion" value: @"3.0;NetFx"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"MaxDataServiceVersion" value: @"3.0;NetFx"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"Content-Type" value: @"application/json"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"Accept" value: @"application/json;odata=minimalmetadata"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
// Single-caller, one-page-per-run example. Archive table-page.json before the next run.
CkoFileAccess *files = [[CkoFileAccess alloc] init];
if ([files FileExists: @"qa_output/table-page.json"] == YES) {
NSLog(@"%@",@"Previous page output exists; process and archive it before continuing.");
return;
}
CkoJsonObject *checkpoint = [[CkoJsonObject alloc] init];
checkpoint.Strict = YES;
NSString *nextPartition = @"";
NSString *nextRow = @"";
if ([files FileExists: @"qa_data/azure/table-checkpoint.json"] == YES) {
success = [checkpoint LoadFile: @"qa_data/azure/table-checkpoint.json"];
if (success != YES) {
NSLog(@"%@",@"Invalid checkpoint; do not silently restart.");
return;
}
[textCompare Clear];
[textCompare SetString: [checkpoint StringOf: @"path"]];
BOOL sameText3 = [textCompare ContentsEqual: resourcePath caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: [checkpoint StringOf: @"filter"]];
BOOL sameText4 = [textCompare ContentsEqual: @"PartitionKey eq 'customers-west'" caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: [checkpoint StringOf: @"select"]];
BOOL sameText5 = [textCompare ContentsEqual: @"PartitionKey,RowKey,Address,NumberOfOrders" caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: [checkpoint StringOf: @"top"]];
BOOL sameText6 = [textCompare ContentsEqual: @"100" caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: [checkpoint StringOf: @"version"]];
BOOL sameText7 = [textCompare ContentsEqual: @"2026-04-06" caseSensitive: YES];
if (([checkpoint StringOf: @"account"] != [config StringOf: @"account"]) || (sameText3 != YES) || (sameText4 != YES) || (sameText5 != YES) || (sameText6 != YES) || (sameText7 != YES)) {
NSLog(@"%@",@"Checkpoint belongs to a different account or query.");
return;
}
if (([[checkpoint JsonTypeOf: @"complete"] intValue] != 5) || ([[checkpoint JsonTypeOf: @"partition"] intValue] != 1) || ([[checkpoint JsonTypeOf: @"row"] intValue] != 1)) {
NSLog(@"%@",@"Checkpoint fields are invalid.");
return;
}
if ([checkpoint BoolOf: @"complete"] == YES) {
NSLog(@"%@",@"Query already complete.");
return;
}
nextPartition = [checkpoint StringOf: @"partition"];
nextRow = [checkpoint StringOf: @"row"];
[textCompare Clear];
[textCompare SetString: nextPartition];
BOOL sameText8 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText8 == YES) {
NSLog(@"%@",@"Incomplete checkpoint has no continuation token.");
return;
}
}
success = [rest AddQueryParam: @"$filter" value: @"PartitionKey eq 'customers-west'"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddQueryParam: @"$select" value: @"PartitionKey,RowKey,Address,NumberOfOrders"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddQueryParam: @"$top" value: @"100"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
[textCompare Clear];
[textCompare SetString: nextPartition];
BOOL sameText9 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText9 != YES) {
success = [rest AddQueryParam: @"NextPartitionKey" value: nextPartition];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
[textCompare Clear];
[textCompare SetString: nextRow];
BOOL sameText10 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText10 != YES) {
success = [rest AddQueryParam: @"NextRowKey" value: nextRow];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
responseText = [rest FullRequestNoBody: @"GET" uriPath: resourcePath];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",@"Request did not complete; inspect the target before retrying a write.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"HTTP status: ",[rest.ResponseStatusCode intValue]);
NSLog(@"%@%@",@"Request ID: ",[rest ResponseHdrByName: @"x-ms-request-id"]);
// 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
// Keep response bodies private. Reconcile uncertain writes before retrying.
return;
}
success = [result Load: responseText];
if (success != YES) {
NSLog(@"%@",@"Expected well-formed JSON.");
return;
}
if ([[result JsonTypeOf: @"value"] intValue] != 4) {
NSLog(@"%@",@"Missing entity/table array.");
return;
}
NSString *followingPartition = [rest ResponseHdrByName: @"x-ms-continuation-NextPartitionKey"];
NSString *followingRow = [rest ResponseHdrByName: @"x-ms-continuation-NextRowKey"];
[textCompare Clear];
[textCompare SetString: followingPartition];
BOOL sameText11 = [textCompare ContentsEqual: @"null" caseSensitive: YES];
if (sameText11 == YES) {
followingPartition = @"";
}
[textCompare Clear];
[textCompare SetString: followingRow];
BOOL sameText12 = [textCompare ContentsEqual: @"null" caseSensitive: YES];
if (sameText12 == YES) {
followingRow = @"";
}
[textCompare Clear];
[textCompare SetString: followingPartition];
BOOL sameText13 = [textCompare ContentsEqual: @"" caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: followingRow];
BOOL sameText14 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if ((sameText13 == YES) && (sameText14 != YES)) {
NSLog(@"%@",@"Malformed continuation.");
return;
}
[textCompare Clear];
[textCompare SetString: followingPartition];
BOOL sameText15 = [textCompare ContentsEqual: @"" caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: followingPartition];
BOOL sameText16 = [textCompare ContentsEqual: nextPartition caseSensitive: YES];
[textCompare Clear];
[textCompare SetString: followingRow];
BOOL sameText17 = [textCompare ContentsEqual: nextRow caseSensitive: YES];
if ((sameText15 != YES) && (sameText16 == YES) && (sameText17 == YES)) {
NSLog(@"%@",@"Service repeated the current checkpoint.");
return;
}
// Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
success = [result WriteFile: @"qa_output/table-page.json"];
if (success != YES) {
NSLog(@"%@",@"Could not save private page output.");
return;
}
success = [checkpoint UpdateString: @"account" value: [config StringOf: @"account"]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"path" value: resourcePath];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"filter" value: @"PartitionKey eq 'customers-west'"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"select" value: @"PartitionKey,RowKey,Address,NumberOfOrders"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"top" value: @"100"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"version" value: @"2026-04-06"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"partition" value: followingPartition];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint UpdateString: @"row" value: followingRow];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
BOOL completed = NO;
[textCompare Clear];
[textCompare SetString: followingPartition];
BOOL sameText18 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText18 == YES) {
completed = YES;
}
success = [checkpoint UpdateBool: @"complete" value: completed];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [checkpoint WriteFile: @"qa_data/azure/table-checkpoint.json"];
if (success != YES) {
NSLog(@"%@",@"Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.");
return;
}
NSLog(@"%@",@"Page and continuation checkpoint saved privately.");