Question

Is it possible to execute an Array DML INSERT or UPDATE statement passing a BLOB field data in the parameter array ? And the more important part of my question, if it is possible, will Array DML command containing BLOB data still be more efficient than executing commands one by one ?

I have noticed that TADParam has a AsBlobs indexed property so I assume it might be possible, but I haven't tried this yet because there's no mention of performance nor example showing this and because the indexed property is of type RawByteString which is not much suitable for my needs.

I'm using FireDAC and working with SQLite database (Params.BindMode = pbByNumber, so I'm using native SQLite INSERT with multiple VALUES). My aim is to store about 100k records containing pretty small BLOB data (about 1kB per record) as fast as possible (in cost of the FireDAC's abstraction).

Was it helpful?

Solution

The main point in your case is that you are using a SQLIte3 database.

With SQLite3, Array DML is "emulated" by FireDAC. Since it is a local instance, not a client-server instance, there is no need to prepare a bunch of rows, then send them at once to avoid network latency (as with Oracle or MS SQL).

Using Array DML may speed up your insertion process a little bit with SQLite3, but I doubt it will very high. Good plain INSERT with binding per number will work just fine.

The main tips about performance in your case will be:

  • Nest your process within a single transaction (or even better, use one transaction per 1000 rows of data);
  • Prepare an INSERT statement, then re-execute it with a bound parameter each time;
  • By default, FireDAC initialize SQLite3 with the fastest options (e.g. disabling LOCK), so let it be.

SQlite3 is very good about BLOB process.

From my tests, FireDAC insertion timing is pretty good, very close to direct SQlite3 access. Only reading is slower than a direct SQLite3 link, due to the overhead of the Delphi TDataSet class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top