Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 4 Jahren, 10 Monaten
Letzter Beitrag:
vor 4 Jahren, 10 Monaten
Beteiligte Autoren:
Gianni Spano, RichardRose, Paulo Oliveira, Peter Holemans, Fabrice Harari, Cesar Flores

[WD17] How to generate log of user operations

Startbeitrag von Gianni Spano am 15.03.2013 12:41

Hello to All

I need to generate records about the operations a user do during the use of a program.
In details, i need to store in a database all the fields he will modify.

Is there a function to obtain a list of the fields that are modified by a user in a window?

Thanks in advance



Hi Gianni

AFAIK, there is no automatic system to do so... This is how I do it, based on the principle that all changes in the DB are made using hadd/hmodify/hdelete (no query for writing)...

I overwrite the 3 functions above by global procedures of the same name.
In those procedure, for the hadd and hedelete, I can easily log.
For the hmodify I need to find which fields were modified... For that, I use an halias of the file used to read the record begin modified, the enum functions to loop trhough all the fields, and a test to check if the value has changed... And log accordingly...

To be perfectly exact, this system is not enough, as the comparison here could find that the field has changed even though the user didn't to any change (if somebody else changed a field during the time the record was open locally)... So to be sure that the log records only what the user has requested to change, we need to:
- read the original record and KEEP it in memory
- Before doing the hmodify, read the disk record
- Compare all THREE versions original/disk/modified by user
Only the fields that changed between original and user should be applied to the disk version and logged as changed

Best regards

von Fabrice Harari - am 15.03.2013 13:17
Hi Gianno,

On the DB side:
In HFSQL there is a system for that that is called 'Journaling'.
Most other DB engines provide before/after image storage functionality as well out of the box.

On the app side:
Check teh dbg and Audit functions to capture execution traces. But this is of course more for debugging an performance tracing of course.

Just my 2 cents,

Peter H.

von Peter Holemans - am 15.03.2013 14:26
Hi. i dont know a function like that! (but i have not a lot of experiences with this tool). but you can create your own log file.

what you can do is add 2 fields in your file this fields will contain the username and the datetime.
Or you can create a new file called "log". and you can write all of the modifications in this new file helped by a procedure and the trigers. Hadd, Hmodify and Hdelete can be handled by the trigers
In the new file write the username and the file he affect, you can use HListItem item or Indirection to write the especific field or you just can save the file name!.

i know this is a little conventional but could work! :)

hope this help.

best regards!

von Cesar Flores - am 15.03.2013 14:49
Our solution is almost the same as Fabrice but instead of using the overload method we use triggers to get the job done (we use more than one db engine).
In almost all the DB engines HF classic & HF/CS included you can use them.

In HF classic mode the triggers (application triggers) only work with HADD/DMODIFY,... function they don't fire if you use INSERT/UPDATE/...
In HF/CS you can use application triggers with the same restrictions as for HF classic but you can use server triggers with less restriction (they are controlled by the db server).

If you only use HF you can use the LOG function for that check it in the help.


von Paulo Oliveira - am 15.03.2013 18:06
Thanks to all

Basically, i did know about a function "Journal" (or similar) for HF files.
But, unfortunately, i'm using a MySql database....

I agree with the Fabrice method, despite it requires that each field must be checked before
to update.
Fortunately, there are about 5 tables that must be updated by user, and i was thinking
to create a table (hidden) that contains all the field name and its original value when i read it from the db, then compare the final value and store in the log only the field name changed with original and update value. In this way a user can never say he hasn't changed the field value..
I can use only a read and compare method, because i use a table that contains all the records locked and other users can't access it before update by the user who get the record locking.
I know it could require a lot of extra work, but i think this solution is near as Fabrice is suggesting.

I will inform you about the solution i will adopt .

Thanks again to all for your suggestions.


von Gianni Spano - am 15.03.2013 20:14
Now that you have stated the db, I'd suggest as its an sql server you build a trigger/storedprocedure which logs the changes to a seperate table.


The only thing to note with this, is you will probably be using an application password to access your data, so you wont be able to easily identify the user who made the changes, but there are a few ways round this problem depending on how your db & app are setup.

von RichardRose - am 21.03.2013 22:34
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.