0

I would like to log all the changes posted in a dataset Post event by looping through the changes in tdataset.afterpost event.

I use dataaware controls and i would like to store the changes done by a user.

My goal is to do it for all datasets in my application, but as a starting point i'd like to master it in a single dataset.

Which is the advisable technique to perform this?

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • 2
    Erm, why not from `BeforePost`? – Victoria Mar 08 '18 at 12:36
  • @Victoria: I suppose because the Post may fail, for example if a server constraint would be violated or conflict with a change to the same record by another user. – MartynA Mar 08 '18 at 13:01
  • Why not using use a database profiler ? – RBA Mar 08 '18 at 13:10
  • @MartynA, good point, but in such case you can cleanup your log started before the changes were applied. I think that in general, so long a dataset object does not have some _"undo"_ feature, it will overwrite its buffer and you won't be able to reach _"previous"_ data from the `AfterPost` event. – Victoria Mar 08 '18 at 13:11
  • There is no particuly good general way to do this on the client side (it is far better to log changes on the server). Whether it is even possible on the client side depends on the type of dataset you are using. Which dataset type are you using? – MartynA Mar 08 '18 at 13:11
  • @MartynA I use SDAC, mostly TMSQuery. I could use a combination of BeforePost and AfterPost. – UnDiUdin Mar 08 '18 at 13:20
  • 1
    @Victoria: I'm not arguing, but the problem is, some dataset types support logging better than others. E.g. the `TField.OldValue` is available for ADO datasets, but uses the underlying `RecordSet` to access it. Not all TDataset descendants properly support `ApplyUpdates`. – MartynA Mar 08 '18 at 13:20
  • In that case, I suggest you study SDAC's source carefully and see whether `TField.OldValue` and/or `TFieldValue.NewValue` are supported. They require specific support in the TDataSet descendant, because `TDataSet` per se does not support either of them iirc. – MartynA Mar 08 '18 at 13:24
  • Switch to a TClientDataset (put it 'after' your TMSQuery) and use its Delta property? – Jan Doggen Mar 08 '18 at 13:27
  • Doing that on the DB side is no option? E.g. using stored procedures for merging data and additionally writing a change log? – nil Mar 08 '18 at 13:27
  • What about changes in the data that are not done by your client ? These kind of logging is always best done on the server side, it can do it faster and will not miss a single change where-ever it originated from – GuidoG Mar 08 '18 at 13:38
  • 1
    @nil, before update trigger should be enough. – Victoria Mar 08 '18 at 13:38
  • 1
    @Victoria that might be even easier to implement, too. – nil Mar 08 '18 at 13:40
  • @Jan, how I wish people stopped using that MIDAS thing :) Besides, I believe that Devart has a memory dataset that is capable of the same. – Victoria Mar 08 '18 at 13:47
  • @Victoria What is wrong with that MIDAS thing ? I use it all the time and so far I am a happy user – GuidoG Mar 08 '18 at 14:38
  • @MartynA SDAC has the OldValue and NewValue thing, this i s perfect for my need. That is what i was looking for. Of course this kind of log is an overhead, but i will make it optional for customers requiring a custom Audit Trail – UnDiUdin Mar 08 '18 at 17:36

0 Answers0