2

是否可以执行 Array DMLINSERTUPDATE在参数数组中传递 BLOB 字段数据的语句?我的问题中更重要的部分是,如果可能的话,包含 BLOB 数据的 Array DML 命令是否仍然比一个接一个地执行命令更有效?

我注意到它TADParam有一个AsBlobs索引属性,所以我认为它可能是可能的,但我还没有尝试过,因为没有提到性能,也没有显示这一点的示例,而且索引属性的类型RawByteString不太适合我的需要.

我正在使用 FireDAC 并使用 SQLite 数据库(Params.BindMode = pbByNumber,所以我使用INSERT带有多个的原生 SQLite VALUES)。我的目标是尽可能快地存储大约 100k 条记录,其中包含非常小的 BLOB 数据(每条记录大约 1kB)(以 FireDAC 的抽象为代价)。

4

1 回答 1

5

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.

于 2013-10-03T12:08:11.227 回答