PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Compare record old and new values
Compare record old and new values
Iniciado por guest, 28,feb. 2018 11:46 - 6 respuestas
Publicado el 28,febrero 2018 - 11:46
I have a Trigger Procedure and want to compare the values of a Modified record before the Trigger Procedure was called and after.

The after value is no problem but the old value will have been overwritten by the new.

I know there is a very easy way to do it but cannot recall how.

Obviously as the Trigger Procedure is a Global procedure I cannot check any of the edit fields as they are local and not available to the global procedure.

Thx in advance.
Publicado el 28,febrero 2018 - 13:09
All sorted. Got my memory back!
Publicado el 28,febrero 2018 - 13:20
Hi John,

How did you manage to do this (comparing the values) ?

Regards,

Joris
Publicado el 28,febrero 2018 - 13:29
Just save the record to memory and then compare the values:

Declare global - ContactRec is Record of Contact
In Win initialization after FileToScreen() just say - ContactRec = Contact
Then you can compare old with new after ScreenToFile:

IF ContactRec.Name <> Contact.Name then ....

Because I am using Indirection in a Global Procedure I would advise checking out HListItem to compare all the fields in a loop.

HTH
Publicado el 01,marzo 2018 - 12:15
Hi

I managed to do it by executing a SQL SELECT query in the trigger as it returns the record before the modifications

sQuery = StringBuild("SELECT * FROM %1 WHERE %2 = %3",MyTable,MyTable+"."+MyTable+"ID",{MyTable+"."+MyTable+"ID"})

HExecuteSQLQuery(dsSQL,hQueryDefault,sQuery)
sOldValue = ""
sNewValue = ""

FOR EACH STRING sField OF HListItem({MyTable}) SEPARATED BY CR
sOldValue += sField+Charact(1)+{"dsSQL."+sField}+Charact(2)
sNewValue += sField+Charact(1)+{MyTable+"."+sField}+Charact(2)
END
HFreeQuery(dsSQL)
Publicado el 01,marzo 2018 - 14:50
Hi Dave,

I managed to do it by executing a SQL SELECT query in the trigger as it
returns the record before the modifications



Actually, that is NOT what your query does.

Your query returns the values of the record as it is NOW in the DB, NOT
as it WAS when you open your form for edit.

Now, that is a completely valid solution IF that is what you want... But
if what you wanted is the content of the record when YOU read it before,
then it's incorrect, as soon as you are not in a standalone situation.

As for me, when I need to exactly know what I'm doing, I'm mixing both
solutions: saving the original record in memory when I read it, reading
the current values in the DB (I generally use a halias for that, but the
result is the same) and then do a 3 ways comparison.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com



>
Publicado el 03,marzo 2018 - 11:59
You are absolutely correct Fabrice

I use it in a standalone method/tool for testing, i gather every single update and have a tool that shows all table and field changes (Create, Modify and Delete - Old and New values) in a test and where the update was performed, and i can then roll-back the data to a selected check point. The trigger for gathering the data can be turned on and off.

All generic, using indirection with zero data setup

Its great for testing complex processes, not having to re-create test data or backup/restore.

cheers
Dave