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 Delphi ActiveX Downloads
var
success: Integer;
textCompare: TChilkatStringBuilder;
config: TChilkatJsonObject;
sameText1: Integer;
sameText2: Integer;
accountText: TChilkatStringBuilder;
allowedAccountChars: TChilkatStringBuilder;
charIndex: Integer;
endpoint: TChilkatStringBuilder;
resourcePath: WideString;
rest: TChilkatRest;
azAuth: TChilkatAuthAzureStorage;
connection: TChilkatSocket;
responseText: WideString;
result: TChilkatJsonObject;
files: TCkFileAccess;
checkpoint: TChilkatJsonObject;
nextPartition: WideString;
nextRow: WideString;
sameText3: Integer;
sameText4: Integer;
sameText5: Integer;
sameText6: Integer;
sameText7: Integer;
sameText8: Integer;
sameText9: Integer;
sameText10: Integer;
followingPartition: WideString;
followingRow: WideString;
sameText11: Integer;
sameText12: Integer;
sameText13: Integer;
sameText14: Integer;
sameText15: Integer;
sameText16: Integer;
sameText17: Integer;
completed: Integer;
sameText18: Integer;
begin
success := 0;
// StringBuilder compares text by value in every generated language.
textCompare := TChilkatStringBuilder.Create(Self);
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success := 0;
config := TChilkatJsonObject.Create(Self);
config.Strict := 1;
success := config.LoadFile('qa_data/azure/storage.json');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not load private Azure configuration.');
Exit;
end;
textCompare.Clear();
textCompare.SetString(config.StringOf('account'));
sameText1 := textCompare.ContentsEqual('',1);
if ((config.JsonTypeOf('account') <> 1) or (sameText1 = 1)) then
begin
Memo1.Lines.Add('Supply the storage account name.');
Exit;
end;
// access_key is the base64 account key, not a connection string or SAS.
textCompare.Clear();
textCompare.SetString(config.StringOf('access_key'));
sameText2 := textCompare.ContentsEqual('',1);
if ((config.JsonTypeOf('access_key') <> 1) or (sameText2 = 1)) then
begin
Memo1.Lines.Add('Supply the base64 account access key.');
Exit;
end;
accountText := TChilkatStringBuilder.Create(Self);
success := accountText.Append(config.StringOf('account'));
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
if ((accountText.Length < 3) or (accountText.Length > 24)) then
begin
Memo1.Lines.Add('Storage account names need 3-24 lowercase letters or digits.');
Exit;
end;
allowedAccountChars := TChilkatStringBuilder.Create(Self);
success := allowedAccountChars.Append('abcdefghijklmnopqrstuvwxyz0123456789');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
charIndex := 0;
while (charIndex < accountText.Length) do
begin
if (allowedAccountChars.Contains(accountText.GetRange(charIndex,1,0),1) <> 1) then
begin
Memo1.Lines.Add('Storage account names need lowercase letters or digits.');
Exit;
end;
charIndex := charIndex + 1;
end;
endpoint := TChilkatStringBuilder.Create(Self);
success := endpoint.Append(config.StringOf('account'));
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := endpoint.Append('.table.core.windows.net');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
// Table names contain only letters and digits and are case-insensitive.
// Entity PartitionKey and RowKey values are case-sensitive.
resourcePath := '/ExampleCustomers()';
rest := TChilkatRest.Create(Self);
rest.ConnectTimeoutMs := 20000;
rest.IdleTimeoutMs := 60000;
azAuth := TChilkatAuthAzureStorage.Create(Self);
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.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not configure Shared Key signing.');
Exit;
end;
connection := TChilkatSocket.Create(Self);
connection.RequireSslCertVerify := 1;
connection.MaxReadIdleMs := 60000;
connection.MaxSendIdleMs := 60000;
success := connection.Connect(endpoint.GetAsString(),443,1,20000);
if (success <> 1) then
begin
Memo1.Lines.Add('TLS connection failed; inspect diagnostics privately.');
Exit;
end;
// Do not replay a write automatically after losing its response.
success := rest.UseConnection(connection.ControlInterface,0);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
result := TChilkatJsonObject.Create(Self);
result.Strict := 1;
success := rest.AddHeader('DataServiceVersion','3.0;NetFx');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := rest.AddHeader('MaxDataServiceVersion','3.0;NetFx');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := rest.AddHeader('Content-Type','application/json');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := rest.AddHeader('Accept','application/json;odata=minimalmetadata');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
// Single-caller, one-page-per-run example. Archive table-page.json before the next run.
files := TCkFileAccess.Create(Self);
if (files.FileExists('qa_output/table-page.json') = 1) then
begin
Memo1.Lines.Add('Previous page output exists; process and archive it before continuing.');
Exit;
end;
checkpoint := TChilkatJsonObject.Create(Self);
checkpoint.Strict := 1;
nextPartition := '';
nextRow := '';
if (files.FileExists('qa_data/azure/table-checkpoint.json') = 1) then
begin
success := checkpoint.LoadFile('qa_data/azure/table-checkpoint.json');
if (success <> 1) then
begin
Memo1.Lines.Add('Invalid checkpoint; do not silently restart.');
Exit;
end;
textCompare.Clear();
textCompare.SetString(checkpoint.StringOf('path'));
sameText3 := textCompare.ContentsEqual(resourcePath,1);
textCompare.Clear();
textCompare.SetString(checkpoint.StringOf('filter'));
sameText4 := textCompare.ContentsEqual('PartitionKey eq ''customers-west''',1);
textCompare.Clear();
textCompare.SetString(checkpoint.StringOf('select'));
sameText5 := textCompare.ContentsEqual('PartitionKey,RowKey,Address,NumberOfOrders',1);
textCompare.Clear();
textCompare.SetString(checkpoint.StringOf('top'));
sameText6 := textCompare.ContentsEqual('100',1);
textCompare.Clear();
textCompare.SetString(checkpoint.StringOf('version'));
sameText7 := textCompare.ContentsEqual('2026-04-06',1);
if ((checkpoint.StringOf('account') <> config.StringOf('account')) or (sameText3 <> 1) or (sameText4 <> 1) or (sameText5 <> 1) or (sameText6 <> 1) or (sameText7 <> 1)) then
begin
Memo1.Lines.Add('Checkpoint belongs to a different account or query.');
Exit;
end;
if ((checkpoint.JsonTypeOf('complete') <> 5) or (checkpoint.JsonTypeOf('partition') <> 1) or (checkpoint.JsonTypeOf('row') <> 1)) then
begin
Memo1.Lines.Add('Checkpoint fields are invalid.');
Exit;
end;
if (checkpoint.BoolOf('complete') = 1) then
begin
Memo1.Lines.Add('Query already complete.');
Exit;
end;
nextPartition := checkpoint.StringOf('partition');
nextRow := checkpoint.StringOf('row');
textCompare.Clear();
textCompare.SetString(nextPartition);
sameText8 := textCompare.ContentsEqual('',1);
if (sameText8 = 1) then
begin
Memo1.Lines.Add('Incomplete checkpoint has no continuation token.');
Exit;
end;
end;
success := rest.AddQueryParam('$filter','PartitionKey eq ''customers-west''');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := rest.AddQueryParam('$select','PartitionKey,RowKey,Address,NumberOfOrders');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := rest.AddQueryParam('$top','100');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
textCompare.Clear();
textCompare.SetString(nextPartition);
sameText9 := textCompare.ContentsEqual('',1);
if (sameText9 <> 1) then
begin
success := rest.AddQueryParam('NextPartitionKey',nextPartition);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
end;
textCompare.Clear();
textCompare.SetString(nextRow);
sameText10 := textCompare.ContentsEqual('',1);
if (sameText10 <> 1) then
begin
success := rest.AddQueryParam('NextRowKey',nextRow);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
end;
responseText := rest.FullRequestNoBody('GET',resourcePath);
if (rest.LastMethodSuccess <> 1) then
begin
Memo1.Lines.Add('Request did not complete; inspect the target before retrying a write.');
Exit;
end;
if (rest.ResponseStatusCode <> 200) then
begin
Memo1.Lines.Add('HTTP status: ' + IntToStr(rest.ResponseStatusCode));
Memo1.Lines.Add('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.
Exit;
end;
success := result.Load(responseText);
if (success <> 1) then
begin
Memo1.Lines.Add('Expected well-formed JSON.');
Exit;
end;
if (result.JsonTypeOf('value') <> 4) then
begin
Memo1.Lines.Add('Missing entity/table array.');
Exit;
end;
followingPartition := rest.ResponseHdrByName('x-ms-continuation-NextPartitionKey');
followingRow := rest.ResponseHdrByName('x-ms-continuation-NextRowKey');
textCompare.Clear();
textCompare.SetString(followingPartition);
sameText11 := textCompare.ContentsEqual('null',1);
if (sameText11 = 1) then
begin
followingPartition := '';
end;
textCompare.Clear();
textCompare.SetString(followingRow);
sameText12 := textCompare.ContentsEqual('null',1);
if (sameText12 = 1) then
begin
followingRow := '';
end;
textCompare.Clear();
textCompare.SetString(followingPartition);
sameText13 := textCompare.ContentsEqual('',1);
textCompare.Clear();
textCompare.SetString(followingRow);
sameText14 := textCompare.ContentsEqual('',1);
if ((sameText13 = 1) and (sameText14 <> 1)) then
begin
Memo1.Lines.Add('Malformed continuation.');
Exit;
end;
textCompare.Clear();
textCompare.SetString(followingPartition);
sameText15 := textCompare.ContentsEqual('',1);
textCompare.Clear();
textCompare.SetString(followingPartition);
sameText16 := textCompare.ContentsEqual(nextPartition,1);
textCompare.Clear();
textCompare.SetString(followingRow);
sameText17 := textCompare.ContentsEqual(nextRow,1);
if ((sameText15 <> 1) and (sameText16 = 1) and (sameText17 = 1)) then
begin
Memo1.Lines.Add('Service repeated the current checkpoint.');
Exit;
end;
// Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
success := result.WriteFile('qa_output/table-page.json');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not save private page output.');
Exit;
end;
success := checkpoint.UpdateString('account',config.StringOf('account'));
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('path',resourcePath);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('filter','PartitionKey eq ''customers-west''');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('select','PartitionKey,RowKey,Address,NumberOfOrders');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('top','100');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('version','2026-04-06');
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('partition',followingPartition);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.UpdateString('row',followingRow);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
completed := 0;
textCompare.Clear();
textCompare.SetString(followingPartition);
sameText18 := textCompare.ContentsEqual('',1);
if (sameText18 = 1) then
begin
completed := 1;
end;
success := checkpoint.UpdateBool('complete',completed);
if (success <> 1) then
begin
Memo1.Lines.Add('Could not prepare the request.');
Exit;
end;
success := checkpoint.WriteFile('qa_data/azure/table-checkpoint.json');
if (success <> 1) then
begin
Memo1.Lines.Add('Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.');
Exit;
end;
Memo1.Lines.Add('Page and continuation checkpoint saved privately.');