API Limits with #FDEC
[SHOWTOGROUPS=4,20]
Jim mcKeeth
31 August 2018
I am a person who wears Google Glass
The FireDAC Enterprise Connectors (#FDEC) by CData and Embarcadero make it really easy to work with various APIs just like you would any SQL database.
For example if you want to publish the results of a query to a Google Sheet (which I find incredibly useful) then it is just a few FireDAC components and you are off to the races.
You might run into an API limit though.
What is an API limit? Most rest services have a limit to how often a client can call a specific API within a certain amount of time.
Google calls this their Для просмотра ссылки Войдиили Зарегистрируйся:
Using the Для просмотра ссылки Войдиили Зарегистрируйся features of FireDAC you can batch multiple DML (Data Manipulation Language) operations into a single API call.
The Для просмотра ссылки Войдиили Зарегистрируйся from CData doesn’t cover Array DML, but the component supports this (they are updating the documentation).
The Elasticsearch documentation does cover Для просмотра ссылки Войдиили Зарегистрируйся with an example, and I’ve used this with Sheets and it works great!
Bulk Insert
The following example prepares a single batch that inserts records in bulk.
Delphi:
FDConnection1.ResourceOptions.ServerOutput := True;
FDQuery1.SQL.Text := 'insert into Account values Name, :Id )';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'MyName1';
FDQuery1.Params[1].AsStrings[0]:= 'MyId1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'MyName2';
FDQuery1.Params[1].AsStrings[1]:= 'MyId2'; ...
FDQuery1.Execute(FDQuery1.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
To retrieve the Ids of the new records, query the LastResultInfo#TEMP table:
Delphi:
sName := FDQuery1.Open('SELECT * FROM [LastResultInfo#TEMP]');
Bulk Update
The following example prepares a single batch that inserts records in bulk.
Delphi:
FDQuery1.SQL.Text := 'update Account set Name = :Name WHERE Id = :Id';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'Floppy Disks';
FDQuery1.Params[1].AsStrings[0]:= 'Id1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'Jon Doe';
FDQuery1.Params[1].AsStrings[1]:= 'Id2'; ...
FDQuery1.Execute(FDQuery.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
Bulk Delete
The following example prepares a single batch that inserts records in bulk:
Delphi:
FDQuery1.SQL.Text := 'delete Account where Id = :Id';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'MyId1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'MyId2'; ...
FDQuery1.Execute(FDQuery.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
If you want to learn more about Для просмотра ссылки Войдиили Зарегистрируйся check out these videos:
или Зарегистрируйся.
Original link: Для просмотра ссылки Войдиили Зарегистрируйся
[/SHOWTOGROUPS]
Jim mcKeeth
31 August 2018
I am a person who wears Google Glass
The FireDAC Enterprise Connectors (#FDEC) by CData and Embarcadero make it really easy to work with various APIs just like you would any SQL database.
For example if you want to publish the results of a query to a Google Sheet (which I find incredibly useful) then it is just a few FireDAC components and you are off to the races.
You might run into an API limit though.
What is an API limit? Most rest services have a limit to how often a client can call a specific API within a certain amount of time.
Google calls this their Для просмотра ссылки Войди
That may seem like a lot, but I found I was running into that limit pretty quick once I moved my project into production. Luckily FireDAC and the FireDAC Enterprise Connectors have a simple workaround: Batch Processing.This version of the Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user. Limits for reads and writes are tracked separately. There is no daily usage limit.
Using the Для просмотра ссылки Войди
The Для просмотра ссылки Войди
The Elasticsearch documentation does cover Для просмотра ссылки Войди
Bulk Insert
The following example prepares a single batch that inserts records in bulk.
Delphi:
FDConnection1.ResourceOptions.ServerOutput := True;
FDQuery1.SQL.Text := 'insert into Account values Name, :Id )';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'MyName1';
FDQuery1.Params[1].AsStrings[0]:= 'MyId1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'MyName2';
FDQuery1.Params[1].AsStrings[1]:= 'MyId2'; ...
FDQuery1.Execute(FDQuery1.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
To retrieve the Ids of the new records, query the LastResultInfo#TEMP table:
Delphi:
sName := FDQuery1.Open('SELECT * FROM [LastResultInfo#TEMP]');
Bulk Update
The following example prepares a single batch that inserts records in bulk.
Delphi:
FDQuery1.SQL.Text := 'update Account set Name = :Name WHERE Id = :Id';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'Floppy Disks';
FDQuery1.Params[1].AsStrings[0]:= 'Id1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'Jon Doe';
FDQuery1.Params[1].AsStrings[1]:= 'Id2'; ...
FDQuery1.Execute(FDQuery.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
Bulk Delete
The following example prepares a single batch that inserts records in bulk:
Delphi:
FDQuery1.SQL.Text := 'delete Account where Id = :Id';
FDQuery1.Params.ArraySize := 100;
FDQuery1.Params[0].AsStrings[0]:= 'MyId1'; //next statement
FDQuery1.Params[0].AsStrings[1]:= 'MyId2'; ...
FDQuery1.Execute(FDQuery.Params.ArraySize);
ShowMessage(IntToStr(FDQuery1.RowsAffected));
If you want to learn more about Для просмотра ссылки Войди
- Для просмотра ссылки Войди
или Зарегистрируйся - Для просмотра ссылки Войди
или Зарегистрируйся
Original link: Для просмотра ссылки Войди
[/SHOWTOGROUPS]
Последнее редактирование: