PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD17] HHistoryModification (Function)
[WD17] HHistoryModification (Function)
Iniciado por guest, 07,nov. 2014 10:39 - 8 respuestas
Publicado el 07,noviembre 2014 - 10:39
Hello to All

Searching an information on the WD online help, i found this function.

I would like to know if this function can be used only on Hyperfile or if i can use it
on a MySql (or other db) also.

What i'm trying to apply to my programs is to show who have modified a field in the record and when.
HHistoryModification seems to have this functionality, but before to change my source code, i would like to be sure that can be done with MySql db.

Thanks in advance.

Gianni
Publicado el 07,noviembre 2014 - 11:01
As far as i can tell you can't use it with MYSQL. It works using the HF log.
Publicado el 07,noviembre 2014 - 11:42
Thanks Paulo

Gianni
Publicado el 07,noviembre 2014 - 12:22
You can achive this by using triggers.
In our case we are using triggers and storing the information we need in xml with hrecordtoxml function
Publicado el 08,noviembre 2014 - 10:35
how to fetch data from hfsql for windev mobile 17
Publicado el 09,noviembre 2014 - 12:23
With WM17 the only way is interact with a webpage/webservice, which does the actual read/write to/from your HFSQL.
You can use Webdev for that, which of courze support hfsql natif.
Of use other web tools together wth the hyperfile ODBC driver
Publicado el 10,noviembre 2014 - 09:09
Hello Paulo

Please, can you post a little example on how you are using the triggers?
It could be a starting point to follow this approach.

Thanks

Gianni
Publicado el 10,noviembre 2014 - 13:03
Just one sample made by code, this only works inside the app and with H* functions but it can give you some hints.
This may not work, i copy the code of my project and try to remove all the specific stuff from the triggers, i hope it can help you but if not sorry.

In the init code of the project:
IF NOT HDescribeTrigger("myfile1","HADD,HMODIFY,HDELETE,HCROSS,HWRITE","TriggerBefore",hTriggerBefore) THEN
ExceptionThrow(1, "Error"+ErrorInfo())
END
IF NOT HDescribeTrigger("myfile1","HADD,HMODIFY,HDELETE,HCROSS,HWRITE","TriggerAfter",hTriggerAfter) THEN
ExceptionThrow(1, "Error"+ErrorInfo())
END

PROCEDURE GLOBAL TriggerBefore()

AUX_FICH is string
AUX_FICH=Upper(H.FileName)

aux_texto is string = ""

AUX_REG is string
AUX_TIPO is string
AUX_TIPO=H.TriggerFunction
R_ALIAS is Data Source
HCancelAlias("R_ALIAS")
IF AUX_TIPO="HModify" THEN
HAlias(H.FileName,"R_ALIAS")
IF ErrorOccurred THEN
ExceptionThrow(1, "ERROR " + H.FileName+CR+HErrorInfo())
END
HCopyRecord(R_ALIAS,H.FileName)
WHEN EXCEPTION IN
HRead(H.FileName, hCurrentRecNum)
DO
H.ToDo="A"
ExceptionThrow(1, "record already changed.")
END
R_LOG_1_FICH=H.FileName
R_LOG_1_TIPO_ACT="M1"
AUX_REG=HRecordToXML(H.FileName)
R_LOG_1_REGISTO=AUX_REG
HCopyRecord({H.FileName, indFile},R_ALIAS)
HCancelAlias("R_ALIAS")
END
R_LOG_2_FICH=H.FileName
IF AUX_TIPO="HModify" THEN
R_LOG_2_TIPO_ACT="M2"
END
IF AUX_TIPO="HDelete" THEN
R_LOG_2_TIPO_ACT="A"
END
IF AUX_TIPO="HAdd" THEN
R_LOG_2_TIPO_ACT="I"
END
AUX_REG=HRecordToXML(H.FileName)
R_LOG_2_REGISTO=AUX_REG

PROCEDURE GLOBAL TriggerAfter()

aux_datetime is DateTime=DateSys()+TimeSys()[[1 TO 6]]
strsql_l is string
aux_string is string
aux_string1 is string

IF R_LOG_1_TIPO_ACT<>"" THEN
R_LOG_1_REGISTO = Replace(R_LOG_1_REGISTO,"'","''")
file_LOG.xml_data = R_LOG_1_REGISTO
file_LOG.fich = R_LOG_1_FICH
file_LOG.TIPO_ACT = R_LOG_1_TIPO_ACT
file_LOG.DATA_HORA_ACT=aux_datetime
file_LOG.UTILIZADOR_ACT=G_USER
IF NOT HAdd(file_LOG) THEN
Error("Error"+HErrorInfo())
END
END

IF R_LOG_2_TIPO_ACT<>"" THEN
R_LOG_2_REGISTO = Replace(R_LOG_2_REGISTO,"'","''")
file_LOG.xml_data = R_LOG_2_REGISTO
file_LOG.fich = R_LOG_2_FICH
file_LOG.TIPO_ACT = R_LOG_2_TIPO_ACT
file_LOG.DATA_HORA_ACT=aux_datetime
file_LOG.UTILIZADOR_ACT=G_USER
IF NOT HAdd(file_LOG) THEN
Error("Error"+HErrorInfo())
END
END

R_LOG_1_TIPO_ACT=""
R_LOG_2_TIPO_ACT=""

R_LOG_1_REGISTO=""
R_LOG_2_REGISTO=""
Publicado el 10,noviembre 2014 - 13:55
Don't forget tihs are simple triggers (only works inside the app and with hadd,hmodify,hdelete), to change to server triggers you have to do it all in MYSQL in your case.

If your DB is HF you can change from simple triggers to server trigger defining the trigger in the analysis and using stored procedures.
<a class="ExternalLink" rel="nofollow" target="_blank" href="http://doc.windev.com/en-US/?3044369">http://doc.windev.com/en-US/&hellip;</a>