How often does it happen that we need to add or update large numbers of records in the same table. Consider imports where this happens a lot.
Firedac has a nice solution for this called Array DML. Basically, in a query you define your INSERT, UPDATE or DELETE statement with parameters once, then fill the parameters as an array and then run the query.
The array of parameters is sent to the database along with the query in one command. The performance differences from a more classical approach are significant. In Chapter 15 of the book “Delphi in Depth: Firedac”, Cary Jensen discusses Array DML and its technical details. In this blog, the description of how to apply it.
First define your query and parameters. Set the array size for parameters to the number of items you want to use.
Then loop through your data, fill the parameters and execute the query.
It took some effort to figure out how this worked with BLOB fields. No example of this could be found online and therefore the code snippet below. First define the parameter for a BLOB field.
In this example a Delphi record is written to the database as a binary field. The following code should be added in the loop where the parameters are filled.