|
| Identifying the record the caused a trigger |
| Iniciado por sdbxox, 31,oct. 2019 16:44 - 5 respuestas |
| |
| | | |
|
| |
| Publicado el 31,octubre 2019 - 16:44 |
There is probably a very easy way around this, but I cannot find it.
I have set up a server trigger on a table which is activated after a new record is added or changed. That works fine and the trigger runs perfectly.
All I need to do now is find out which record activated the trigger. Is there a command avaialbve which can return the record number of the table?
Any suggestions are welcome.
Thanks Simon |
| |
| |
| | | |
|
| | |
| |
| Publicado el 31,octubre 2019 - 16:56 |
| Hi, within the trigger code the whole buffer to be written is availabe! |
| |
| |
| | | |
|
| | |
| |
| Publicado el 31,octubre 2019 - 17:19 |
Thanks for your quick reply Guenter.
I suspected that would be the case, however, in the trigger code, I wrote a small amount of code to save the Ref (autoID) of the record that was just added and activated the trigger, and it is returning 0 every time. However, in the main file it is the correctly incremented number. I have set the trigger to come after the add so it should be available by then.
Thanks Simon |
| |
| |
| | | |
|
| | |
| |
| Publicado el 31,octubre 2019 - 23:22 |
Ok, I have got round this by removing the Add Tigger and simply calling the Stored procedure from the client using HExecuteProcedure(FileName.Ref) straight after the HAdd(FileName). This way the autoID ref field has been updated . Not elegant but does the job.
As you correctly say, using a Trigger has the record buffer available, but does not have the AutoID updated so that is still 0. If I were to change the fields in that buffer and then use HSave, it actually adds a second record to the file.
Thanks Simon |
| |
| |
| | | |
|
| | |
| |
| Publicado el 31,octubre 2019 - 23:35 |
Ok, got it. It was because I was using the HSave in the Add trigger code. All I have now done is changed the fields as I need to and let the trigger do the rest without manually writing to the file.
I was envisaging that at the stage that the Trigger was called, the record would already have been written to disk, so I would need to retrieve the correct record, update it and write it back. Now I realise that the trigger is activated before the new record is actually writen to the file so any changes needed can be done before it is added.
I just put this in in case it helps anyone else who has gone down a simular path!
Thanks Simon |
| |
| |
| | | |
|
| | |
| |
| Publicado el 01,noviembre 2019 - 07:57 |
| Hi, of course, the automatic identifier is calculated & inserted while writing the record to disk. So, before writing it is not there.and equals 0. If you really need the auto-ID then just re-read the record after writing in order to retrieve the auto-ID. If this takes too much time think about using a different key-mechanism like GUID ... |
| |
| |
| | | |
|
| | | | |
| | |
|