Preferable way to write Delphi database apps with transactions & data-aware components

前端 未结 1 1781
轻奢々
轻奢々 2021-02-14 19:06

What is the preferable way to write Delphi database applications using transactions and also data-aware components?

I have to write a client app that access InnoDB table

相关标签:
1条回答
  • 2021-02-14 19:21

    Others mentioned using a combination of DatasetProvider and ClientDataset to have a batch update, but in case of using ADO or UniDAC components, you do not need the extra layer of DatasetProvider + ClientDataset, because both ADO and UniDAC support batch updates.

    For ADO, what you should do is to set LockType of your dataset to ltBatchOptimistic. For UniDAC, you should set CacheUpdate property to True.

    This change makes your dataset to cache all the changes you make on its in-memory recordset, and send them alltogether to database only when you call UpdateBatch method (ADO) or ApplyUpdates method (UniDAC).

    Now what you should do is to let your user insert/edit a record in the master dataset and whatever records he/she wants in the details dataset using whatever data-aware components you like. All the changes would be cached. When your user is done, you can start a new transaction, and first call UpdateBatch (or ApplyUpdate in case of UniDAC) for the master dataset, and then for the details dataset, and if everything goes fine, commit the transaction.

    This will make your transactions short without needing the extra layer of ClientDataset.

    Regards

    0 讨论(0)
提交回复
热议问题